blob: db982dba0dc1d7eb2bfae767005345edca30685e [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>
Naseer Ahmed29a26812012-06-14 00:56:20 -070033#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050034#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080035#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070036#include "hwc_ad.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070037#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "hwc_copybit.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070039#include "hwc_dump_layers.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070040#include "hdmi.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080041#include "hwc_qclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070042#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080043#include "comptype.h"
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -080044#include "hwc_virtual.h"
Tatenda Chipeperekwaa7dd23c2014-03-05 13:02:24 -080045#include "qd_utils.h"
Zohaib Alam83ea46d2015-03-23 15:44:19 -040046#include "hwc_qdcm.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;
Zohaib Alam83ea46d2015-03-23 15:44:19 -040056using namespace qQdcm;
Saurabh Shahacf10202013-02-26 10:15:15 -080057namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080058
Saurabh Shah74eff4d2014-03-28 16:33:13 -070059#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070060#ifdef __cplusplus
61extern "C" {
62#endif
63
64EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
65 EGLint *attrib_list);
66#define EGL_GPU_HINT_1 0x32D0
67#define EGL_GPU_HINT_2 0x32D1
68
69#define EGL_GPU_LEVEL_0 0x0
70#define EGL_GPU_LEVEL_1 0x1
71#define EGL_GPU_LEVEL_2 0x2
72#define EGL_GPU_LEVEL_3 0x3
73#define EGL_GPU_LEVEL_4 0x4
74#define EGL_GPU_LEVEL_5 0x5
75
76#ifdef __cplusplus
77}
78#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070079#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070080
Ramakant Singhbe390c72014-12-03 23:04:21 +053081#define PROP_DEFAULT_APPBUFFER "hw.sf.app_buff_count"
Ramakant Singh98c533c2014-09-30 19:01:54 +053082#define MAX_RAM_SIZE 512*1024*1024
83#define qHD_WIDTH 540
84
85
Naseer Ahmed29a26812012-06-14 00:56:20 -070086namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070087
Arun Kumar K.R053dc502014-11-13 11:13:43 -080088// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
89uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070090
radhakrishnac3198ff2015-03-10 17:10:02 +053091static uint32_t getFBformat(fb_var_screeninfo vinfo) {
92 uint32_t fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
93
94#ifdef GET_FRAMEBUFFER_FORMAT_FROM_HWC
95 // Here, we are adding the formats that are supported by both GPU and MDP.
96 // The formats that fall in this category are RGBA_8888, RGB_565, RGB_888
97 switch(vinfo.bits_per_pixel) {
98 case 16:
99 fbformat = HAL_PIXEL_FORMAT_RGB_565;
100 break;
101 case 24:
102 if ((vinfo.transp.offset == 0) && (vinfo.transp.length == 0))
103 fbformat = HAL_PIXEL_FORMAT_RGB_888;
104 break;
105 case 32:
106 if ((vinfo.red.offset == 0) && (vinfo.green.offset == 8) &&
107 (vinfo.blue.offset == 16) && (vinfo.transp.offset == 24))
108 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
109 break;
110 default:
111 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
112 }
113#endif
114 return fbformat;
115}
116
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530117bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
118{
Jeykumar Sankaran39305802014-12-12 17:55:57 -0800119 return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530120 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
121 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
122}
123
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800124static void handleFbScaling(hwc_context_t *ctx, int xresPanel, int yresPanel,
125 int width, int height) {
126 const int dpy = HWC_DISPLAY_PRIMARY;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530127 //Store original display resolution.
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800128 ctx->dpyAttr[dpy].xresFB = xresPanel;
129 ctx->dpyAttr[dpy].yresFB = yresPanel;
130 ctx->dpyAttr[dpy].fbScaling = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530131 char property[PROPERTY_VALUE_MAX] = {'\0'};
132 char *yptr = NULL;
133 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
134 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530135 if(yptr) {
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800136 int xresFB = atoi(property);
137 int yresFB = atoi(yptr + 1);
138 if (isValidResolution(ctx, xresFB, yresFB) &&
139 xresFB != xresPanel && yresFB != yresPanel) {
140 ctx->dpyAttr[dpy].xresFB = xresFB;
141 ctx->dpyAttr[dpy].yresFB = yresFB;
142 ctx->dpyAttr[dpy].fbScaling = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530143
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800144 //Calculate DPI according to changed resolution.
145 float xdpi = ((float)xresFB * 25.4f) / (float)width;
146 float ydpi = ((float)yresFB * 25.4f) / (float)height;
147 ctx->dpyAttr[dpy].xdpi = xdpi;
148 ctx->dpyAttr[dpy].ydpi = ydpi;
Raj Kamal4a443082014-10-12 21:07:59 +0530149 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530150 }
151 }
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800152 ctx->dpyAttr[dpy].fbWidthScaleRatio = (float) ctx->dpyAttr[dpy].xres /
153 (float) ctx->dpyAttr[dpy].xresFB;
154 ctx->dpyAttr[dpy].fbHeightScaleRatio = (float) ctx->dpyAttr[dpy].yres /
155 (float) ctx->dpyAttr[dpy].yresFB;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530156}
157
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700158// Initialize hdmi display attributes based on
159// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700160void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
radhakrishnac3198ff2015-03-10 17:10:02 +0530161 struct fb_var_screeninfo info;
162
163 if (ioctl(ctx->mHDMIDisplay->getFd(), FBIOGET_VSCREENINFO, &info) == -1) {
164 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s",
165 __FUNCTION__, strerror(errno));
166 }
167
168 ctx->dpyAttr[dpy].fbformat = getFBformat(info);
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700169 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
170 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
171 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
172 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
173 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700174 //FIXME: for now assume HDMI as secure
175 //Will need to read the HDCP status from the driver
176 //and update this accordingly
177 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700178 ctx->mViewFrame[dpy].left = 0;
179 ctx->mViewFrame[dpy].top = 0;
180 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
181 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
182}
183
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700184// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700185void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
186 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
187 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
188 // We reset the fd to -1 here but External display class is responsible
189 // for it when the display is disconnected. This is handled as part of
190 // EXTERNAL_OFFLINE event.
191 ctx->dpyAttr[dpy].fd = -1;
192}
193
194// Initialize composition resources
195void initCompositionResources(hwc_context_t* ctx, int dpy) {
196 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
197 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
198}
199
200void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
201 if(ctx->mFBUpdate[dpy]) {
202 delete ctx->mFBUpdate[dpy];
203 ctx->mFBUpdate[dpy] = NULL;
204 }
205 if(ctx->mMDPComp[dpy]) {
206 delete ctx->mMDPComp[dpy];
207 ctx->mMDPComp[dpy] = NULL;
208 }
209}
210
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800211static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700212{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800213 struct fb_fix_screeninfo finfo;
214 struct fb_var_screeninfo info;
215
216 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530217 if(fb_fd < 0) {
218 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800219 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530220 }
221
222 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
223 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
224 strerror(errno));
225 close(fb_fd);
226 return -errno;
227 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800228
229 if (int(info.width) <= 0 || int(info.height) <= 0) {
230 // the driver doesn't return that information
231 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530232 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
233 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700234 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800235
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530236 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
237 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800238
239#ifdef MSMFB_METADATA_GET
240 struct msmfb_metadata metadata;
241 memset(&metadata, 0 , sizeof(metadata));
242 metadata.op = metadata_op_frame_rate;
243
244 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530245 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
246 strerror(errno));
247 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800248 return -errno;
249 }
250
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530251 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800252#else
253 //XXX: Remove reserved field usage on all baselines
254 //The reserved[3] field is used to store FPS by the driver.
255 float fps = info.reserved[3] & 0xFF;
256#endif
257
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530258 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
259 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
260 strerror(errno));
261 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800262 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530263 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800264
265 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
266 //xres, yres may not be 32 aligned
267 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
268 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
269 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
270 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
271 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700272 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
273 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700274 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530275 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
276 (uint32_t)(1000000000l / fps);
radhakrishnac3198ff2015-03-10 17:10:02 +0530277 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fbformat = getFBformat(info);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800278
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800279 handleFbScaling(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530280
Naseer Ahmed22616d92013-05-15 17:20:26 -0400281 //Unblank primary on first boot
282 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
283 ALOGE("%s: Failed to unblank display", __FUNCTION__);
284 return -errno;
285 }
286 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
287
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800288 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700289}
290
Ramakant Singh98c533c2014-09-30 19:01:54 +0530291static void changeDefaultAppBufferCount() {
292 struct sysinfo info;
293 unsigned long int ramSize = 0;
294 if (!sysinfo(&info)) {
295 ramSize = info.totalram ;
296 }
297 int fb_fd = -1;
298 struct fb_var_screeninfo sInfo ={0};
299 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
300 if (fb_fd >=0) {
301 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
302 close(fb_fd);
303 }
304 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
305 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
Sanjeev Jakkilinkif8bc0362015-02-23 20:20:17 +0530306 property_set(PROP_DEFAULT_APPBUFFER, "3");
Ramakant Singh98c533c2014-09-30 19:01:54 +0530307 }
308}
309
Arun Kumar K.R205df772015-02-20 18:45:58 -0800310int initContext(hwc_context_t *ctx)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700311{
Arun Kumar K.R205df772015-02-20 18:45:58 -0800312 int error = -1;
313 int compositionType = 0;
314
315 //Right now hwc starts the service but anybody could do it, or it could be
316 //independent process as well.
317 QService::init();
318 sp<IQClient> client = new QClient(ctx);
319 sp<IQService> iqs = interface_cast<IQService>(
320 defaultServiceManager()->getService(
321 String16("display.qservice")));
322 if (iqs.get()) {
323 iqs->connect(client);
324 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
325 } else {
326 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
327 return error;
328 }
329
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700330 overlay::Overlay::initOverlay();
331 ctx->mHDMIDisplay = new HDMIDisplay();
332 uint32_t priW = 0, priH = 0;
333 // 1. HDMI as Primary
334 // -If HDMI cable is connected, read display configs from edid data
335 // -If HDMI cable is not connected then use default data in vscreeninfo
336 // 2. HDMI as External
337 // -Initialize HDMI class for use with external display
338 // -Use vscreeninfo to populate display configs
339 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
340 int connected = ctx->mHDMIDisplay->getConnectedState();
341 if(connected == 1) {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800342 error = ctx->mHDMIDisplay->configure();
343 if (error < 0) {
344 goto OpenFBError;
345 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700346 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
347 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
348 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800349 error = openFramebufferDevice(ctx);
350 if(error < 0) {
351 goto OpenFBError;
352 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700353 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
354 }
355 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800356 error = openFramebufferDevice(ctx);
357 if(error < 0) {
358 goto OpenFBError;
359 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700360 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
361 // Send the primary resolution to the hdmi display class
362 // to be used for MDP scaling functionality
363 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
364 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
365 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
366 }
367
Raj kamal59fea562014-04-01 16:52:19 +0530368 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700369 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
370 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
371 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800372 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800373 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800374 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800375
Ramakant Singh98c533c2014-09-30 19:01:54 +0530376 //default_app_buffer for ferrum
377 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
378 changeDefaultAppBufferCount();
379 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700380 // Initialize composition objects for the primary display
381 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800382
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800383 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800384 // decide if we need to open the copybit module.
Arun Kumar K.R205df772015-02-20 18:45:58 -0800385 compositionType =
386 qdutils::QCCompositionType::getInstance().getCompositionType();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800387
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800388 // Only MDP copybit is used
389 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
390 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530391 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
392 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800393 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530394 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800395 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
396 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800397 }
398
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700399 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700400 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
401 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
402 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
403 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700404 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
405 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
406 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800407
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700408 //Initialize the primary display viewFrame info
409 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
410 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
411 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
412 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
413 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
414 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530415
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700416 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700417 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700418 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700419 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800420 ctx->dpyAttr[i].mActionSafePresent = false;
421 ctx->dpyAttr[i].mAsWidthRatio = 0;
422 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500423 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
424 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700425 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700426
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500427 //Make sure that the 3D mode is unset at bootup
428 //This makes sure that the state is accurate on framework reboots
429 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
430
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530431 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
432 ctx->mPrevHwLayerCount[i] = 0;
433 }
434
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500435 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700436 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700437
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400438 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500439 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700440 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530441 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800442
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700443 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700444 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700445 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400446
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700447 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
448 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
449
Ramakant Singh0def28c2014-03-28 20:43:13 +0530450 ctx->enableABC = false;
451 property_get("debug.sf.hwc.canUseABC", value, "0");
452 ctx->enableABC = atoi(value) ? true : false;
453
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530454 // Initializing boot anim completed check to false
455 ctx->mBootAnimCompleted = false;
456
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700457 // Initialize gpu perfomance hint related parameters
458 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700459#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700460 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
461
462 ctx->mGPUHintInfo.mEGLDisplay = NULL;
463 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700464 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700465 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700466#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700467 // Read the system property to determine if windowboxing feature is enabled.
468 ctx->mWindowboxFeature = false;
469 if(property_get("sys.hwc.windowbox_feature", value, "false")
470 && !strcmp(value, "true")) {
471 ctx->mWindowboxFeature = true;
472 }
473
Raj Kamal0d53fc62014-11-25 17:36:36 +0530474 ctx->mUseMetaDataRefreshRate = true;
475 if(property_get("persist.metadata_dynfps.disable", value, "false")
476 && !strcmp(value, "true")) {
477 ctx->mUseMetaDataRefreshRate = false;
478 }
479
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700480 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800481 ctx->mHPDEnabled = false;
Zohaib Alam83ea46d2015-03-23 15:44:19 -0400482
483 //init qdcm service related context.
484 qdcmInitContext(ctx);
485
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700486 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700487 ALOGI("MDP version: %d", ctx->mMDP.version);
Arun Kumar K.R205df772015-02-20 18:45:58 -0800488
489 return 0;
490
491OpenFBError:
492 ALOGE("%s: Fatal Error: FB Open failed!!!", __FUNCTION__);
493 delete ctx->mHDMIDisplay;
494 return error;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700495}
496
497void closeContext(hwc_context_t *ctx)
498{
Zohaib Alam83ea46d2015-03-23 15:44:19 -0400499 //close qdcm service related context.
500 qdcmCloseContext(ctx);
501
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500502 if(ctx->mOverlay) {
503 delete ctx->mOverlay;
504 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700505 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700506
Saurabh Shahacf10202013-02-26 10:15:15 -0800507 if(ctx->mRotMgr) {
508 delete ctx->mRotMgr;
509 ctx->mRotMgr = NULL;
510 }
511
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700512 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800513 if(ctx->mCopyBit[i]) {
514 delete ctx->mCopyBit[i];
515 ctx->mCopyBit[i] = NULL;
516 }
517 }
518
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800519 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700520 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
521 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700522 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700523
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700524 if(ctx->mHDMIDisplay) {
525 delete ctx->mHDMIDisplay;
526 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700527 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400528
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700529 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700530 destroyCompositionResources(ctx, i);
531
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700532 if(ctx->mHwcDebug[i]) {
533 delete ctx->mHwcDebug[i];
534 ctx->mHwcDebug[i] = NULL;
535 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700536 if(ctx->mLayerRotMap[i]) {
537 delete ctx->mLayerRotMap[i];
538 ctx->mLayerRotMap[i] = NULL;
539 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800540 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800541 if(ctx->mHWCVirtual) {
542 delete ctx->mHWCVirtual;
543 ctx->mHWCVirtual = NULL;
544 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700545 if(ctx->mAD) {
546 delete ctx->mAD;
547 ctx->mAD = NULL;
548 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800549
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400550 if(ctx->mQService) {
551 delete ctx->mQService;
552 ctx->mQService = NULL;
553 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700554}
555
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700556//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530557uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700558 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
559 uint32_t rate = refreshRate;
560 for(int i=0; i< count; i++) {
561 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
562 // Most likely used for video, the fps can fluctuate
563 // Ex: b/w 29 and 30 for 30 fps clip
564 rate = stdRefreshRates[i];
565 break;
566 }
567 }
568 return rate;
569}
570
571//Helper func to set the dyn fps
572void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
573 //Update only if different
574 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
575 return;
576 const int fbNum = Overlay::getFbForDpy(dpy);
577 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
578 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800579 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700580
581 int fd = open(sysfsPath, O_WRONLY);
582 if(fd >= 0) {
583 char str[64];
584 snprintf(str, sizeof(str), "%d", refreshRate);
585 ssize_t ret = write(fd, str, strlen(str));
586 if(ret < 0) {
587 ALOGE("%s: Failed to write %d with error %s",
588 __FUNCTION__, refreshRate, strerror(errno));
589 } else {
590 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
591 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
592 __FUNCTION__, refreshRate);
593 }
594 close(fd);
595 } else {
596 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
597 strerror(errno));
598 }
599}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500600
601void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700602{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500603 va_list varargs;
604 va_start(varargs, fmt);
605 buf.appendFormatV(fmt, varargs);
606 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700607}
608
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700609int getExtOrientation(hwc_context_t* ctx) {
610 int extOrient = ctx->mExtOrientation;
611 if(ctx->mBufferMirrorMode)
612 extOrient = getMirrorModeOrientation(ctx);
613 return extOrient;
614}
615
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800616/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700617void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
618 // Position
619 int x = rect.left, y = rect.top;
620 int w = rect.right - rect.left;
621 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800622
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800623 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800624 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800625 // Read action safe properties
626 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
627 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700628
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800629 float wRatio = 1.0;
630 float hRatio = 1.0;
631 float xRatio = 1.0;
632 float yRatio = 1.0;
633
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700634 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
635 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700636 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
637 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700638 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700639 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700640 }
641
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800642
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700643 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700644 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700645
646 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700647 swap(fbWidth, fbHeight);
648
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800649 float asX = 0;
650 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530651 float asW = (float)fbWidth;
652 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800653
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800654 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530655 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
656 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
657 asX = ((float)fbWidth - asW) / 2;
658 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800659
660 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530661 xRatio = (float)x/(float)fbWidth;
662 yRatio = (float)y/(float)fbHeight;
663 wRatio = (float)w/(float)fbWidth;
664 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800665
666 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530667 x = int((xRatio * asW) + asX);
668 y = int((yRatio * asH) + asY);
669 w = int(wRatio * asW);
670 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800671
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700672 // Convert it back to hwc_rect_t
673 rect.left = x;
674 rect.top = y;
675 rect.right = w + rect.left;
676 rect.bottom = h + rect.top;
677
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800678 return;
679}
680
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700681// This function gets the destination position for Seconday display
682// based on the position and aspect ratio with orientation
683void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
684 hwc_rect_t& inRect, hwc_rect_t& outRect) {
685 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530686 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
687 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700688 //display position(x,y,w,h) in correct aspectratio after rotation
689 int xPos = 0;
690 int yPos = 0;
691 float width = fbWidth;
692 float height = fbHeight;
693 // Width/Height used for calculation, after rotation
694 float actualWidth = fbWidth;
695 float actualHeight = fbHeight;
696
697 float wRatio = 1.0;
698 float hRatio = 1.0;
699 float xRatio = 1.0;
700 float yRatio = 1.0;
701 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
702
703 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
704 inRect.bottom - inRect.top);
705 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
706 outRect.bottom - outRect.top);
707
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530708 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700709 eTransform extorient = static_cast<eTransform>(extOrientation);
710 // To calculate the destination co-ordinates in the new orientation
711 preRotateSource(extorient, whf, inPos);
712
713 if(extOrientation & HAL_TRANSFORM_ROT_90) {
714 // Swap width/height for input position
715 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700716 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
717 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700718 xPos = rect.left;
719 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530720 width = float(rect.right - rect.left);
721 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700722 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700723 xRatio = (float)((float)inPos.x/actualWidth);
724 yRatio = (float)((float)inPos.y/actualHeight);
725 wRatio = (float)((float)inPos.w/actualWidth);
726 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800727
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530728 //Calculate the pos9ition...
729 outPos.x = uint32_t((xRatio * width) + (float)xPos);
730 outPos.y = uint32_t((yRatio * height) + (float)yPos);
731 outPos.w = uint32_t(wRatio * width);
732 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700733 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
734 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
735 outPos.w, outPos.h);
736
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700737 // For sidesync, the dest fb will be in portrait orientation, and the crop
738 // will be updated to avoid the black side bands, and it will be upscaled
739 // to fit the dest RB, so recalculate
740 // the position based on the new width and height
741 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
742 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800743 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700744 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530745 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700746 // GetaspectRatio -- tricky to get the correct aspect ratio
747 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700748 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530749 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700750 xPos = r.left;
751 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530752 float tempHeight = float(r.bottom - r.top);
753 yRatio = (float)yPos/height;
754 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700755 hRatio = tempHeight/height;
756
757 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530758 outPos.x = uint32_t(xRatio * fbWidth);
759 outPos.y = uint32_t(yRatio * fbHeight);
760 outPos.w = uint32_t(wRatio * fbWidth);
761 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700762
763 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
764 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
765 outPos.x, outPos.y,
766 outPos.w, outPos.h);
767 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700768 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700769 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700770 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700771 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700772 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
773 extW = ctx->mHWCVirtual->getScalingWidth();
774 extH = ctx->mHWCVirtual->getScalingHeight();
775 }
776 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
777 __FUNCTION__, extW, extH);
778
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530779 fbWidth = (float)ctx->dpyAttr[dpy].xres;
780 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700781 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530782 xRatio = (float)outPos.x/fbWidth;
783 yRatio = (float)outPos.y/fbHeight;
784 wRatio = (float)outPos.w/fbWidth;
785 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700786
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530787 outPos.x = uint32_t(xRatio * (float)extW);
788 outPos.y = uint32_t(yRatio * (float)extH);
789 outPos.w = uint32_t(wRatio * (float)extW);
790 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700791 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700792 // Convert Dim to hwc_rect_t
793 outRect.left = outPos.x;
794 outRect.top = outPos.y;
795 outRect.right = outPos.x + outPos.w;
796 outRect.bottom = outPos.y + outPos.h;
797
798 return;
799}
800
801bool isPrimaryPortrait(hwc_context_t *ctx) {
802 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
803 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
804 if(fbWidth < fbHeight) {
805 return true;
806 }
807 return false;
808}
809
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700810bool isOrientationPortrait(hwc_context_t *ctx) {
811 if(isPrimaryPortrait(ctx)) {
812 return !(ctx->deviceOrientation & 0x1);
813 }
814 return (ctx->deviceOrientation & 0x1);
815}
816
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700817void calcExtDisplayPosition(hwc_context_t *ctx,
818 private_handle_t *hnd,
819 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700820 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700821 hwc_rect_t& displayFrame,
822 int& transform,
823 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700824 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700825 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530826 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700827 if(!isYuvBuffer(hnd)) {
828 if(extOrient & HWC_TRANSFORM_ROT_90) {
829 int dstWidth = ctx->dpyAttr[dpy].xres;
830 int dstHeight = ctx->dpyAttr[dpy].yres;;
831 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
832 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
833 if(!isPrimaryPortrait(ctx)) {
834 swap(srcWidth, srcHeight);
835 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700836 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700837 srcHeight, displayFrame);
838 // Crop - this is needed, because for sidesync, the dest fb will
839 // be in portrait orientation, so update the crop to not show the
840 // black side bands.
841 if (isOrientationPortrait(ctx)) {
842 sourceCrop = displayFrame;
843 displayFrame.left = 0;
844 displayFrame.top = 0;
845 displayFrame.right = dstWidth;
846 displayFrame.bottom = dstHeight;
847 }
848 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700849 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700850 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700851 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700852 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530853 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
854 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700855 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700856 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700857 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700858 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
859 extW = ctx->mHWCVirtual->getScalingWidth();
860 extH = ctx->mHWCVirtual->getScalingHeight();
861 }
862 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
863 __FUNCTION__, extW, extH);
864
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700865 //Calculate the ratio...
866 float wRatio = ((float)extW)/fbWidth;
867 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700868
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700869 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530870 displayFrame.left = int(wRatio*(float)displayFrame.left);
871 displayFrame.top = int(hRatio*(float)displayFrame.top);
872 displayFrame.right = int(wRatio*(float)displayFrame.right);
873 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700874 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
875 " for MDPDownscale feature [%d %d %d %d]",
876 displayFrame.left, displayFrame.top,
877 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700878 }
879 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700880 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700881 getAspectRatioPosition(ctx, dpy, extOrient,
882 displayFrame, displayFrame);
883 }
884 }
885 // If there is a external orientation set, use that
886 if(extOrient) {
887 transform = extOrient;
888 orient = static_cast<ovutils::eTransform >(extOrient);
889 }
890 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
891 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700892 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700893}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700894
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700895/* Returns the orientation which needs to be set on External for
896 * SideSync/Buffer Mirrormode
897 */
898int getMirrorModeOrientation(hwc_context_t *ctx) {
899 int extOrientation = 0;
900 int deviceOrientation = ctx->deviceOrientation;
901 if(!isPrimaryPortrait(ctx))
902 deviceOrientation = (deviceOrientation + 1) % 4;
903 if (deviceOrientation == 0)
904 extOrientation = HWC_TRANSFORM_ROT_270;
905 else if (deviceOrientation == 1)//90
906 extOrientation = 0;
907 else if (deviceOrientation == 2)//180
908 extOrientation = HWC_TRANSFORM_ROT_90;
909 else if (deviceOrientation == 3)//270
910 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
911
912 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700913}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700914
Raj kamal59fea562014-04-01 16:52:19 +0530915/* Get External State names */
916const char* getExternalDisplayState(uint32_t external_state) {
917 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
918 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
919 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
920 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
921 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
922
923 if(external_state >= EXTERNAL_MAXSTATES) {
924 return "EXTERNAL_INVALID";
925 }
926
927 return externalStates[external_state];
928}
929
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530930bool isDownscaleRequired(hwc_layer_1_t const* layer) {
931 hwc_rect_t displayFrame = layer->displayFrame;
932 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
933 int dst_w, dst_h, src_w, src_h;
934 dst_w = displayFrame.right - displayFrame.left;
935 dst_h = displayFrame.bottom - displayFrame.top;
936 src_w = sourceCrop.right - sourceCrop.left;
937 src_h = sourceCrop.bottom - sourceCrop.top;
938
939 if(((src_w > dst_w) || (src_h > dst_h)))
940 return true;
941
942 return false;
943}
944bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500945 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500946 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700947 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500948
949 dst_w = displayFrame.right - displayFrame.left;
950 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500951 src_w = sourceCrop.right - sourceCrop.left;
952 src_h = sourceCrop.bottom - sourceCrop.top;
953
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800954 if(layer->transform & HWC_TRANSFORM_ROT_90)
955 swap(src_w, src_h);
956
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800957 if(((src_w != dst_w) || (src_h != dst_h)))
958 return true;
959
960 return false;
961}
962
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700963// Checks if layer needs scaling with split
964bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
965 const int& dpy) {
966
967 int src_width_l, src_height_l;
968 int src_width_r, src_height_r;
969 int dst_width_l, dst_height_l;
970 int dst_width_r, dst_height_r;
971 int hw_w = ctx->dpyAttr[dpy].xres;
972 int hw_h = ctx->dpyAttr[dpy].yres;
973 hwc_rect_t cropL, dstL, cropR, dstR;
974 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700975 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700976 hwc_rect_t displayFrame = layer->displayFrame;
977 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700978
979 cropL = sourceCrop;
980 dstL = displayFrame;
981 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800982 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700983 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
984
985 cropR = sourceCrop;
986 dstR = displayFrame;
987 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800988 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700989 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
990
991 // Sanitize Crop to stitch
992 sanitizeSourceCrop(cropL, cropR, hnd);
993
994 // Calculate the left dst
995 dst_width_l = dstL.right - dstL.left;
996 dst_height_l = dstL.bottom - dstL.top;
997 src_width_l = cropL.right - cropL.left;
998 src_height_l = cropL.bottom - cropL.top;
999
1000 // check if there is any scaling on the left
1001 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
1002 return true;
1003
1004 // Calculate the right dst
1005 dst_width_r = dstR.right - dstR.left;
1006 dst_height_r = dstR.bottom - dstR.top;
1007 src_width_r = cropR.right - cropR.left;
1008 src_height_r = cropR.bottom - cropR.top;
1009
1010 // check if there is any scaling on the right
1011 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
1012 return true;
1013
1014 return false;
1015}
1016
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301017bool isAlphaScaled(hwc_layer_1_t const* layer) {
1018 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301019 return true;
1020 }
1021 return false;
1022}
1023
1024bool isAlphaPresent(hwc_layer_1_t const* layer) {
1025 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001026 if(hnd) {
1027 int format = hnd->format;
1028 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301029 case HAL_PIXEL_FORMAT_RGBA_8888:
1030 case HAL_PIXEL_FORMAT_BGRA_8888:
1031 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -05001032 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301033 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001034 }
Naseer Ahmed018e5452012-12-03 14:46:15 -05001035 }
1036 return false;
1037}
1038
radhakrishnac3198ff2015-03-10 17:10:02 +05301039bool isAlphaPresentinFB(hwc_context_t *ctx, int dpy) {
1040 switch(ctx->dpyAttr[dpy].fbformat) {
1041 case HAL_PIXEL_FORMAT_RGBA_8888:
1042 case HAL_PIXEL_FORMAT_BGRA_8888:
1043 return true;
1044 default : return false;
1045 }
1046 return false;
1047}
1048
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001049static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
1050 hwc_rect_t& crop, hwc_rect_t& dst) {
1051 int hw_w = ctx->dpyAttr[dpy].xres;
1052 int hw_h = ctx->dpyAttr[dpy].yres;
1053 if(dst.left < 0 || dst.top < 0 ||
1054 dst.right > hw_w || dst.bottom > hw_h) {
1055 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001056 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001057 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1058 }
1059}
1060
1061static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1062 const int& dpy) {
1063 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1064 hwc_layer_1_t *layer = &list->hwLayers[i];
1065 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001066 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1067 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001068 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001069 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001070 (hwc_rect_t&)crop,
1071 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301072 layer->sourceCropf.left = (float)crop.left;
1073 layer->sourceCropf.right = (float)crop.right;
1074 layer->sourceCropf.top = (float)crop.top;
1075 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001076 }
1077}
1078
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001079void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001080 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001081 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1082 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301083 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1084 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001085 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301086 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001087 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001088 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001089 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001090 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001091 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301092 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001093 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301094 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001095 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001096 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1097 uint32_t refreshRate = 0;
1098 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001099 int s3dFormat = HAL_NO_3D;
1100 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001101
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001102 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001103 resetROI(ctx, dpy);
1104
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001105 trimList(ctx, list, dpy);
1106 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001107 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001108 hwc_layer_1_t const* layer = &list->hwLayers[i];
1109 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001110
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001111#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001112 // Window boxing feature is applicable obly for external display, So
1113 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001114 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001115 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001116 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001117 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1118 ctx->listStats[dpy].isDisplayAnimating = true;
1119 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001120 if(isSecureDisplayBuffer(hnd)) {
1121 ctx->listStats[dpy].secureUI = true;
1122 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001123#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001124 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1125 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001126 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001127
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001128 //reset yuv indices
1129 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301130 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001131
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001132 if (isSecureBuffer(hnd)) {
1133 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001134 if(not isYuvBuffer(hnd)) {
1135 // cache secureRGB layer parameters like we cache for YUV layers
1136 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1137 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1138 secureRGBCount++;
1139 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001140 }
1141
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001142 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001143 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001144 }
1145
1146 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001147 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301148 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001149 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001150
Raj Kamal389d6e32014-08-04 14:43:24 +05301151 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301152 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301153 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301154 yuv4k2kCount++;
1155 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001156
1157 // Gets set if one YUV layer is 3D
1158 if (displaySupports3D(ctx,dpy)) {
1159 s3dFormat = get3DFormat(hnd);
1160 if(s3dFormat != HAL_NO_3D)
1161 s3dLayerCount++;
1162 }
1163
Naseer Ahmed29a26812012-06-14 00:56:20 -07001164 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301165 if(layer->blending == HWC_BLENDING_PREMULT)
1166 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001167
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001168#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301169 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001170 //dyn fps: get refreshrate from metadata
1171 //Support multiple refresh rates if they are same
1172 //else set to default
1173 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1174 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1175 // Valid refreshRate in metadata and within the range
1176 uint32_t rate = roundOff(mdata->refreshrate);
1177 if((rate >= mdpHw.getMinFpsSupported() &&
1178 rate <= mdpHw.getMaxFpsSupported())) {
1179 if (!refreshRate) {
1180 refreshRate = rate;
1181 } else if(refreshRate != rate) {
1182 // multiple refreshrate requests, set to default
1183 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1184 }
1185 }
1186 }
1187 }
1188#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001189 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001190
1191 //Set the TV's 3D mode based on format if it was not forced
1192 //Only one 3D YUV layer is supported on external
1193 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1194 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1195 //XXX: Rapidly going in and out of 3D mode in some cases such
1196 // as rotation might cause flickers. The OEMs are recommended to disable
1197 // rotation on HDMI globally or in the app that plays 3D video
1198 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1199 }
1200
Ping Li9404e2a2013-04-24 16:36:03 -04001201 if(ctx->listStats[dpy].yuvCount > 0) {
1202 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1203 if (atoi(property) != 1) {
1204 property_set("hw.cabl.yuv", "1");
1205 }
1206 }
1207 } else {
1208 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1209 if (atoi(property) != 0) {
1210 property_set("hw.cabl.yuv", "0");
1211 }
1212 }
1213 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001214
1215 //The marking of video begin/end is useful on some targets where we need
1216 //to have a padding round to be able to shift pipes across mixers.
1217 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1218 ctx->mVideoTransFlag = true;
1219 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301220
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001221 if(dpy == HWC_DISPLAY_PRIMARY) {
1222 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001223 //Store the requested fresh rate
1224 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1225 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001226 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001227}
1228
Naseer Ahmed018e5452012-12-03 14:46:15 -05001229
Saurabh Shah68107422013-07-09 11:12:42 -07001230static void calc_cut(double& leftCutRatio, double& topCutRatio,
1231 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001232 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001233 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001234 }
1235 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001236 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001237 }
1238 if(orient & HAL_TRANSFORM_ROT_90) {
1239 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001240 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001241 leftCutRatio = topCutRatio;
1242 topCutRatio = rightCutRatio;
1243 rightCutRatio = bottomCutRatio;
1244 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001245 }
1246}
1247
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001248bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001249 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1250 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1251 ctx->mSecuring) {
1252 return true;
1253 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001254 if (isSecureModePolicy(ctx->mMDP.version)) {
1255 private_handle_t *hnd = (private_handle_t *)layer->handle;
1256 if(ctx->mSecureMode) {
1257 if (! isSecureBuffer(hnd)) {
1258 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1259 __FUNCTION__);
1260 return true;
1261 }
1262 } else {
1263 if (isSecureBuffer(hnd)) {
1264 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1265 __FUNCTION__);
1266 return true;
1267 }
1268 }
1269 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001270 return false;
1271}
1272
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001273bool isSecureModePolicy(int mdpVersion) {
1274 if (mdpVersion < qdutils::MDSS_V5)
1275 return true;
1276 else
1277 return false;
1278}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001279
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001280bool isRotatorSupportedFormat(private_handle_t *hnd) {
1281 // Following rotator src formats are supported by mdp driver
1282 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001283 if(hnd != NULL) {
1284 switch(hnd->format) {
1285 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001286 case HAL_PIXEL_FORMAT_RGBA_5551:
1287 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001288 case HAL_PIXEL_FORMAT_RGB_565:
1289 case HAL_PIXEL_FORMAT_RGB_888:
1290 case HAL_PIXEL_FORMAT_BGRA_8888:
1291 return true;
1292 default:
1293 return false;
1294 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001295 }
1296 return false;
1297}
1298
1299bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001300 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001301 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001302 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001303 !ctx->mMDP.version < qdutils::MDSS_V5)
1304 || isYuvBuffer(hnd)) {
1305 return true;
1306 }
1307 return false;
1308}
1309
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001310// returns true if Action safe dimensions are set and target supports Actionsafe
1311bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1312 // if external supports underscan, do nothing
1313 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001314 // Disable Action safe for 8974 due to HW limitation for downscaling
1315 // layers with overlapped region
1316 // Disable Actionsafe for non HDMI displays.
1317 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1318 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001319 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001320 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001321 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001322
1323 char value[PROPERTY_VALUE_MAX];
1324 // Read action safe properties
1325 property_get("persist.sys.actionsafe.width", value, "0");
1326 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1327 property_get("persist.sys.actionsafe.height", value, "0");
1328 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1329
1330 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1331 //No action safe ratio set, return
1332 return false;
1333 }
1334 return true;
1335}
1336
Naseer Ahmed522ce662013-03-18 20:14:05 -04001337int getBlending(int blending) {
1338 switch(blending) {
1339 case HWC_BLENDING_NONE:
1340 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1341 case HWC_BLENDING_PREMULT:
1342 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1343 case HWC_BLENDING_COVERAGE :
1344 default:
1345 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1346 }
1347}
1348
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001349//Crops source buffer against destination and FB boundaries
1350void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001351 const hwc_rect_t& scissor, int orient) {
1352
Saurabh Shah27c1d652012-08-14 19:30:28 -07001353 int& crop_l = crop.left;
1354 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001355 int& crop_r = crop.right;
1356 int& crop_b = crop.bottom;
1357 int crop_w = crop.right - crop.left;
1358 int crop_h = crop.bottom - crop.top;
1359
Saurabh Shah27c1d652012-08-14 19:30:28 -07001360 int& dst_l = dst.left;
1361 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001362 int& dst_r = dst.right;
1363 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001364 int dst_w = abs(dst.right - dst.left);
1365 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001366
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001367 const int& sci_l = scissor.left;
1368 const int& sci_t = scissor.top;
1369 const int& sci_r = scissor.right;
1370 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001371
Saurabh Shah68107422013-07-09 11:12:42 -07001372 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1373 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001374
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001375 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001376 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001377 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001378 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001379
1380 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001381 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001382 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001383 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001384
1385 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001386 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001387 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001388 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001389
1390 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001391 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001392 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001393 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001394
Saurabh Shah541b59d2012-10-11 11:08:12 -07001395 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301396 crop_l += (int)round((double)crop_w * leftCutRatio);
1397 crop_t += (int)round((double)crop_h * topCutRatio);
1398 crop_r -= (int)round((double)crop_w * rightCutRatio);
1399 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001400}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001401
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301402bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1403 const hwc_layer_1_t* layer2) {
1404 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1405 layer2->displayFrame);
1406 return isValidRect(irect);
1407}
1408
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001409bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1410{
1411 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1412 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1413}
1414
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001415bool isValidRect(const hwc_rect& rect)
1416{
1417 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301418}
1419
Ramakant Singh21cec722014-03-07 19:11:45 +05301420bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1421 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1422 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1423 return true ;
1424 return false;
1425}
1426
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001427hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1428{
1429 hwc_rect_t res;
1430
1431 if(!isValidRect(rect))
1432 return (hwc_rect_t){0, 0, 0, 0};
1433
1434 res.left = rect.left + x_off;
1435 res.top = rect.top + y_off;
1436 res.right = rect.right + x_off;
1437 res.bottom = rect.bottom + y_off;
1438
1439 return res;
1440}
1441
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001442/* computes the intersection of two rects */
1443hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1444{
1445 hwc_rect_t res;
1446
1447 if(!isValidRect(rect1) || !isValidRect(rect2)){
1448 return (hwc_rect_t){0, 0, 0, 0};
1449 }
1450
1451
1452 res.left = max(rect1.left, rect2.left);
1453 res.top = max(rect1.top, rect2.top);
1454 res.right = min(rect1.right, rect2.right);
1455 res.bottom = min(rect1.bottom, rect2.bottom);
1456
1457 if(!isValidRect(res))
1458 return (hwc_rect_t){0, 0, 0, 0};
1459
1460 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301461}
1462
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001463/* computes the union of two rects */
1464hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1465{
1466 hwc_rect_t res;
1467
1468 if(!isValidRect(rect1)){
1469 return rect2;
1470 }
1471
1472 if(!isValidRect(rect2)){
1473 return rect1;
1474 }
1475
1476 res.left = min(rect1.left, rect2.left);
1477 res.top = min(rect1.top, rect2.top);
1478 res.right = max(rect1.right, rect2.right);
1479 res.bottom = max(rect1.bottom, rect2.bottom);
1480
1481 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301482}
1483
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001484/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1485 * a single rect */
1486hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301487
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001488 hwc_rect_t res = rect1;
1489
1490 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1491 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1492 res.top = rect2.bottom;
1493 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1494 res.bottom = rect2.top;
1495 }
1496 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1497 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1498 res.left = rect2.right;
1499 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1500 res.right = rect2.left;
1501 }
1502 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301503}
1504
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001505void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301506 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301507 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301508 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001509 //If it is opaque see if we can substract this region from below
1510 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301511 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1512 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301513 int j= i-1;
1514 hwc_rect_t& topframe =
1515 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1516 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301517 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001518 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1519 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001520 hwc_rect_t bottomCrop =
1521 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001522 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1523 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001524
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001525 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1526 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001527 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001528 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001529 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001530 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001531 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001532 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301533 layer->sourceCropf.left =(float)bottomCrop.left;
1534 layer->sourceCropf.top = (float)bottomCrop.top;
1535 layer->sourceCropf.right = (float)bottomCrop.right;
1536 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001537#ifdef QCOM_BSP
1538 //Update layer dirtyRect
1539 layer->dirtyRect = getIntersection(bottomCrop,
1540 layer->dirtyRect);
1541#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001542 }
1543 }
1544 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301545 }
1546 }
1547 i--;
1548 }
1549}
1550
Naseer Ahmed64b81212013-02-14 10:29:47 -05001551void getNonWormholeRegion(hwc_display_contents_1_t* list,
1552 hwc_rect_t& nwr)
1553{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301554 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001555 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1556 //Initiliaze nwr to first frame
1557 nwr.left = list->hwLayers[0].displayFrame.left;
1558 nwr.top = list->hwLayers[0].displayFrame.top;
1559 nwr.right = list->hwLayers[0].displayFrame.right;
1560 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1561
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301562 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001563 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001564 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001565 }
1566
1567 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001568 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001569}
1570
Saurabh Shah747af1e2013-02-26 10:25:12 -08001571void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001572 if(LIKELY(list)) {
1573 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1574 //Close the acquireFenceFds
1575 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1576 if(list->hwLayers[i].acquireFenceFd >= 0) {
1577 close(list->hwLayers[i].acquireFenceFd);
1578 list->hwLayers[i].acquireFenceFd = -1;
1579 }
1580 }
1581 //Writeback
1582 if(list->outbufAcquireFenceFd >= 0) {
1583 close(list->outbufAcquireFenceFd);
1584 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001585 }
1586 }
1587}
1588
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001589int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001590 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001591 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001592 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001593 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001594 int count = 0;
1595 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001596 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001597 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001598 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001599
1600 struct mdp_buf_sync data;
1601 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001602 data.acq_fen_fd = acquireFd;
1603 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001604 data.retire_fen_fd = &retireFd;
1605 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001606
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001607 char property[PROPERTY_VALUE_MAX];
1608 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1609 if(atoi(property) == 0)
1610 swapzero = true;
1611 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001612
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001613 bool isExtAnimating = false;
1614 if(dpy)
1615 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001616
Saurabh Shah23a813c2013-03-20 16:58:12 -07001617 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001618 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001619 int rotFd = ctx->mRotMgr->getRotDevFd();
1620 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001621 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1622 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1623 if((currRot == NULL) || (currLayer == NULL)) {
1624 continue;
1625 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001626 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001627 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001628 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001629 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001630 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001631 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001632 if(currLayer->acquireFenceFd >= 0) {
1633 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1634 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001635 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301636 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301637 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1638
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001639 if(ret < 0) {
1640 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1641 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001642 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001643 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001644 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001645 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001646 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001647 dup(rotReleaseFd);
1648 //A buffer is free to be used by producer as soon as its copied to
1649 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001650 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001651 rotReleaseFd;
1652 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001653 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001654
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301655 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001656 if(list->outbufAcquireFenceFd >= 0) {
1657 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301658 if(LIKELY(!swapzero) )
1659 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001660 }
1661
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001662 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301663 if(((isAbcInUse(ctx)== true ) ||
1664 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001665 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301666 if(LIKELY(!swapzero) ) {
1667 // if ABC is enabled for more than one layer.
1668 // renderBufIndexforABC will work as FB.Hence
1669 // set the acquireFD from fd - which is coming from copybit
1670 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1671 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1672 acquireFd[count++] = fd;
1673 else
1674 continue;
1675 } else
1676 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1677 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001678 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001679 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301680 if(LIKELY(!swapzero) ) {
1681 if(fd >= 0) {
1682 //set the acquireFD from fd - which is coming from c2d
1683 acquireFd[count++] = fd;
1684 // Buffer sync IOCTL should be async when using c2d fence is
1685 // used
1686 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1687 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1688 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1689 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001690 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001691 }
1692
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001693 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001694 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301695 if(LIKELY(!swapzero) )
1696 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001697 }
1698
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001699 data.acq_fen_fd_cnt = count;
1700 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001701
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001702 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001703 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001704 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001705 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001706
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001707 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001708 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1709 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301710 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001711 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1712 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001713 close(releaseFd);
1714 releaseFd = -1;
1715 close(retireFd);
1716 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001717 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001718
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001719 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001720 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001721#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001722 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001723#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001724 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001725 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001726 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001727 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001728 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001729 // Release all the app layer fds immediately,
1730 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001731 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001732 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001733#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001734 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301735 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301736
1737 // if ABC is enabled for more than one layer
1738 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1739 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1740 list->hwLayers[i].releaseFenceFd = dup(fd);
1741 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1742 (isAbcInUse(ctx) == false)){
1743 //For Blit, the app layers should be released when the Blit
1744 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301745 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001746 } else
1747#endif
1748 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301749 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1750 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001751 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001752 }
1753 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001754
1755 if(fd >= 0) {
1756 close(fd);
1757 fd = -1;
1758 }
1759
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001760 if (ctx->mCopyBit[dpy]) {
1761 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001762 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1763 else
1764 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1765 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001766
Saurabh Shah23a813c2013-03-20 16:58:12 -07001767 //Signals when MDP finishes reading rotator buffers.
1768 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001769 close(releaseFd);
1770 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001771
Arun Kumar K.R51835182013-11-19 11:20:28 -08001772 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001773 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001774 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001775 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001776 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001777 return ret;
1778}
1779
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001780void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001781 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001782 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001783 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001784 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001785
1786 if(layer->blending == HWC_BLENDING_PREMULT) {
1787 ovutils::setMdpFlags(mdpFlags,
1788 ovutils::OV_MDP_BLEND_FG_PREMULT);
1789 }
1790
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001791 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1792 metadata->interlaced) {
1793 ovutils::setMdpFlags(mdpFlags,
1794 ovutils::OV_MDP_DEINTERLACE);
1795 }
1796
1797 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1798 if(isSecureBuffer(hnd)) {
1799 ovutils::setMdpFlags(mdpFlags,
1800 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301801 ovutils::setMdpFlags(mdpFlags,
1802 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1803 }
1804
1805 if(isProtectedBuffer(hnd)) {
1806 ovutils::setMdpFlags(mdpFlags,
1807 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001808 }
1809
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001810 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001811 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001812 ovutils::setMdpFlags(mdpFlags,
1813 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1814 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001815
1816 //Pre-rotation will be used using rotator.
1817 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1818 ovutils::setMdpFlags(mdpFlags,
1819 ovutils::OV_MDP_SOURCE_ROTATED_90);
1820 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001821 //No 90 component and no rot-downscale then flips done by MDP
1822 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001823 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1824 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001825 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1826 }
1827
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001828 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001829 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1830 }
1831 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001832
1833 if(metadata &&
1834 ((metadata->operation & PP_PARAM_HSIC)
1835 || (metadata->operation & PP_PARAM_IGC)
1836 || (metadata->operation & PP_PARAM_SHARP2))) {
1837 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1838 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001839}
1840
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301841int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001842 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001843 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001844
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301845 // Fix alignments for TILED format
1846 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1847 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1848 whf.w = utils::alignup(whf.w, 64);
1849 whf.h = utils::alignup(whf.h, 32);
1850 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001851 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001852
1853 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1854 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001855 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1856 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001857 rot->setCrop(rotCrop);
1858 }
1859
Saurabh Shahacf10202013-02-26 10:15:15 -08001860 rot->setFlags(mdpFlags);
1861 rot->setTransform(orient);
1862 rot->setDownscale(downscale);
1863 if(!rot->commit()) return -1;
1864 return 0;
1865}
1866
Saurabh Shahe2474082013-05-15 16:32:13 -07001867int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001868 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001869 const hwc_rect_t& pos, const MetaData_t *metadata,
1870 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001871 ov->setSource(parg, dest);
1872 ov->setTransform(orient, dest);
1873
1874 int crop_w = crop.right - crop.left;
1875 int crop_h = crop.bottom - crop.top;
1876 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1877 ov->setCrop(dcrop, dest);
1878
1879 int posW = pos.right - pos.left;
1880 int posH = pos.bottom - pos.top;
1881 Dim position(pos.left, pos.top, posW, posH);
1882 ov->setPosition(position, dest);
1883
Saurabh Shah5daeee52013-01-23 16:52:26 +08001884 if (metadata)
1885 ov->setVisualParams(*metadata, dest);
1886
Saurabh Shahacf10202013-02-26 10:15:15 -08001887 if (!ov->commit(dest)) {
1888 return -1;
1889 }
1890 return 0;
1891}
1892
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001893int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1894 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001895 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001896
1897 hwc_rect_t dst = layer->displayFrame;
1898 trimLayer(ctx, dpy, 0, dst, dst);
1899
1900 int w = ctx->dpyAttr[dpy].xres;
1901 int h = ctx->dpyAttr[dpy].yres;
1902 int dst_w = dst.right - dst.left;
1903 int dst_h = dst.bottom - dst.top;
1904 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001905 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001906
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001907 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001908 if (layer->blending == HWC_BLENDING_PREMULT)
1909 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1910
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001911 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001912 layer->planeAlpha,
1913 (ovutils::eBlending) getBlending(layer->blending));
1914
1915 // Configure MDP pipe for Color layer
1916 Dim pos(dst.left, dst.top, dst_w, dst_h);
1917 ctx->mOverlay->setSource(parg, dest);
1918 ctx->mOverlay->setColor(color, dest);
1919 ctx->mOverlay->setTransform(0, dest);
1920 ctx->mOverlay->setCrop(pos, dest);
1921 ctx->mOverlay->setPosition(pos, dest);
1922
1923 if (!ctx->mOverlay->commit(dest)) {
1924 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1925 return -1;
1926 }
1927 return 0;
1928}
1929
Saurabh Shahe2474082013-05-15 16:32:13 -07001930void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001931 hwc_rect_t& crop, Rotator *rot) {
1932 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001933 crop.right - crop.left,
1934 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001935 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1936 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001937 //B-family rotator internally could modify destination dimensions if
1938 //downscaling is supported
1939 whf = rot->getDstWhf();
1940 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001941 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001942 //A-family rotator rotates entire buffer irrespective of crop, forcing
1943 //us to recompute the crop based on transform
1944 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1945 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001946 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001947
1948 crop.left = transformedCrop.x;
1949 crop.top = transformedCrop.y;
1950 crop.right = transformedCrop.x + transformedCrop.w;
1951 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001952}
1953
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001954int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1955 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1956 return 0;
1957 }
1958
1959 int downscale = 0;
1960 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1961 hwc_rect_t dst = layer->displayFrame;
1962 private_handle_t *hnd = (private_handle_t *)layer->handle;
1963
1964 if(not hnd) {
1965 return 0;
1966 }
1967
1968 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1969 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1970 && metadata->interlaced;
1971 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001972 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001973
1974 if(isYuvBuffer(hnd)) {
1975 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1976 ctx->mMDP.version < qdutils::MDSS_V5) {
1977 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1978 crop.bottom - crop.top, dst.right - dst.left,
1979 dst.bottom - dst.top, format, isInterlaced);
1980 } else {
1981 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1982 crop.bottom - crop.top);
1983 Dim pos(dst.left, dst.top, dst.right - dst.left,
1984 dst.bottom - dst.top);
1985 if(transform & HAL_TRANSFORM_ROT_90) {
1986 swap(adjCrop.w, adjCrop.h);
1987 }
1988 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1989 pos.h, format, isInterlaced);
1990 }
1991 }
1992 return downscale;
1993}
1994
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001995bool isZoomModeEnabled(hwc_rect_t crop) {
1996 // This does not work for zooming in top left corner of the image
1997 return(crop.top > 0 || crop.left > 0);
1998}
1999
2000void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
2001 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
2002 crop.left, crop.top, crop.right, crop.bottom);
2003 if(isZoomModeEnabled(crop)) {
2004 Dim srcCrop(crop.left, crop.top,
2005 crop.right - crop.left,
2006 crop.bottom - crop.top);
2007 int extW = ctx->dpyAttr[dpy].xres;
2008 int extH = ctx->dpyAttr[dpy].yres;
2009 //Crop the original video in order to fit external display aspect ratio
2010 if(srcCrop.w * extH < extW * srcCrop.h) {
2011 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
2012 crop.top += offset;
2013 crop.bottom -= offset;
2014 } else {
2015 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
2016 crop.left += offset;
2017 crop.right -= offset;
2018 }
2019 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2020 " source crop [%d %d %d %d]", extW, extH, dpy,
2021 crop.left, crop.top, crop.right, crop.bottom);
2022 }
2023}
2024
2025void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
2026 hwc_rect_t& dst, int dpy) {
2027 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
2028 dst.left, dst.top, dst.right, dst.bottom);
2029 Dim srcCrop(crop.left, crop.top,
2030 crop.right - crop.left,
2031 crop.bottom - crop.top);
2032 int extW = ctx->dpyAttr[dpy].xres;
2033 int extH = ctx->dpyAttr[dpy].yres;
2034 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07002035 // when zoom in mode is enabled or the ratio between video aspect ratio
2036 // and external display aspect ratio is below the minimum tolerance level
2037 // and above maximum tolerance level
2038 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
2039 float extDisplayAspectRatio = ((float)extW / (float)extH);
2040 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
2041 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
2042 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002043 dst.left = 0;
2044 dst.top = 0;
2045 dst.right = extW;
2046 dst.bottom = extH;
2047 }
2048 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2049 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
2050 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
2051 crop.left, crop.top, crop.right, crop.bottom);
2052}
2053
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002054void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002055 hwc_rect_t& dst, int dpy) {
2056 updateCropAIVVideoMode(ctx, crop, dpy);
2057 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2058}
2059
Saurabh Shah88e4d272013-09-03 13:31:29 -07002060int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002061 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002062 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002063
2064 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002065
Saurabh Shahacf10202013-02-26 10:15:15 -08002066 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002067 if (layer->flags & HWC_COLOR_FILL) {
2068 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002069 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002070 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002071 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2072 return -1;
2073 }
2074
Saurabh Shah5daeee52013-01-23 16:52:26 +08002075 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2076
Saurabh Shah62e1d732013-09-17 10:44:05 -07002077 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002078 hwc_rect_t dst = layer->displayFrame;
2079 int transform = layer->transform;
2080 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002081 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002082 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302083 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002084
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002085 // Handle R/B swap
2086 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2087 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2088 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2089 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2090 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2091 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002092 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002093 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2094 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002095 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002096 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002097 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002098 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002099
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002100 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002101 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002102 *rot = ctx->mRotMgr->getNext();
2103 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002104 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002105 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2106 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002107 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002108 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2109 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002110 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002111 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002112 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002113 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002114 }
2115
Saurabh Shah76fd6552013-03-14 14:45:38 -07002116 //For the mdp, since either we are pre-rotating or MDP does flips
2117 orient = OVERLAY_TRANSFORM_0;
2118 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002119 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002120 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2121 (ovutils::eBlending) getBlending(layer->blending));
2122
Saurabh Shah5daeee52013-01-23 16:52:26 +08002123 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002124 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2125 return -1;
2126 }
2127 return 0;
2128}
2129
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002130//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002131void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002132 private_handle_t *hnd) {
2133 if(cropL.right - cropL.left) {
2134 if(isYuvBuffer(hnd)) {
2135 //Always safe to even down left
2136 ovutils::even_floor(cropL.left);
2137 //If right is even, automatically width is even, since left is
2138 //already even
2139 ovutils::even_floor(cropL.right);
2140 }
2141 //Make sure there are no gaps between left and right splits if the layer
2142 //is spread across BOTH halves
2143 if(cropR.right - cropR.left) {
2144 cropR.left = cropL.right;
2145 }
2146 }
2147
2148 if(cropR.right - cropR.left) {
2149 if(isYuvBuffer(hnd)) {
2150 //Always safe to even down left
2151 ovutils::even_floor(cropR.left);
2152 //If right is even, automatically width is even, since left is
2153 //already even
2154 ovutils::even_floor(cropR.right);
2155 }
2156 }
2157}
2158
Saurabh Shah88e4d272013-09-03 13:31:29 -07002159int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002160 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002161 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002162 Rotator **rot) {
2163 private_handle_t *hnd = (private_handle_t *)layer->handle;
2164 if(!hnd) {
2165 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2166 return -1;
2167 }
2168
Saurabh Shah5daeee52013-01-23 16:52:26 +08002169 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2170
Saurabh Shahacf10202013-02-26 10:15:15 -08002171 int hw_w = ctx->dpyAttr[dpy].xres;
2172 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002173 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002174 hwc_rect_t dst = layer->displayFrame;
2175 int transform = layer->transform;
2176 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002177 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002178 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302179 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002180
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002181 // Handle R/B swap
2182 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2183 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2184 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2185 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2186 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2187 }
2188
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002189 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002190 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2191 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002192 }
2193
2194 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002195 ActionSafe, and extorientation features. */
2196 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002197 int downscale = getRotDownscale(ctx, layer);
2198 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002199
2200 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2201 //Enable overfetch
2202 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2203 }
2204
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002205 //Will do something only if feature enabled and conditions suitable
2206 //hollow call otherwise
2207 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2208 overlay::Writeback *wb = overlay::Writeback::getInstance();
2209 whf.format = wb->getOutputFormat();
2210 }
2211
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002212 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002213 (*rot) = ctx->mRotMgr->getNext();
2214 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002215 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002216 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002217 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2218 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002219 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002220 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002221 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002222 rotFlags |= ROT_PREROTATED;
2223 }
2224
2225 eMdpFlags mdpFlagsR = mdpFlagsL;
2226 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2227
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002228 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2229 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002230
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002231 const int lSplit = getLeftSplit(ctx, dpy);
2232
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002233 // Calculate Left rects
2234 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002235 tmp_cropL = crop;
2236 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002237 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002238 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002239 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2240 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002241
2242 // Calculate Right rects
2243 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002244 tmp_cropR = crop;
2245 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002246 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002247 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002248 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2249 }
2250
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002251 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2252
Saurabh Shah94d62362013-07-02 10:58:48 -07002253 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002254 //Not needed if the layer is confined to one half of the screen.
2255 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002256 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2257 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002258 hwc_rect_t new_cropR;
2259 new_cropR.left = tmp_cropL.left;
2260 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2261
2262 hwc_rect_t new_cropL;
2263 new_cropL.left = new_cropR.right;
2264 new_cropL.right = tmp_cropR.right;
2265
2266 tmp_cropL.left = new_cropL.left;
2267 tmp_cropL.right = new_cropL.right;
2268
2269 tmp_cropR.left = new_cropR.left;
2270 tmp_cropR.right = new_cropR.right;
2271
2272 }
2273
Saurabh Shah76fd6552013-03-14 14:45:38 -07002274 //For the mdp, since either we are pre-rotating or MDP does flips
2275 orient = OVERLAY_TRANSFORM_0;
2276 transform = 0;
2277
Saurabh Shahacf10202013-02-26 10:15:15 -08002278 //configure left mixer
2279 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002280 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002281 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2282 (ovutils::eBlending) getBlending(layer->blending));
2283
Saurabh Shahacf10202013-02-26 10:15:15 -08002284 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002285 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002286 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2287 return -1;
2288 }
2289 }
2290
2291 //configure right mixer
2292 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002293 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002294 static_cast<eRotFlags>(rotFlags),
2295 layer->planeAlpha,
2296 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002297 tmp_dstR.right = tmp_dstR.right - lSplit;
2298 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002299 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002300 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002301 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2302 return -1;
2303 }
2304 }
2305
2306 return 0;
2307}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002308
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002309int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2310 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2311 const eDest& lDest, const eDest& rDest,
2312 Rotator **rot) {
2313 private_handle_t *hnd = (private_handle_t *)layer->handle;
2314 if(!hnd) {
2315 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2316 return -1;
2317 }
2318 //Both pipes are configured to the same mixer
2319 eZorder lz = z;
2320 eZorder rz = (eZorder)(z + 1);
2321
2322 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2323
2324 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2325 hwc_rect_t dst = layer->displayFrame;
2326 int transform = layer->transform;
2327 eTransform orient = static_cast<eTransform>(transform);
2328 int rotFlags = ROT_FLAGS_NONE;
2329 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2330 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2331
2332 int downscale = getRotDownscale(ctx, layer);
2333 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2334
2335 //XXX: Check if rotation is supported and valid for 3D
2336 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2337 (*rot) = ctx->mRotMgr->getNext();
2338 if((*rot) == NULL) return -1;
2339 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2340 //Configure rotator for pre-rotation
2341 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2342 ALOGE("%s: configRotator failed!", __FUNCTION__);
2343 return -1;
2344 }
2345 updateSource(orient, whf, crop, *rot);
2346 rotFlags |= ROT_PREROTATED;
2347 }
2348
2349 eMdpFlags mdpFlagsR = mdpFlagsL;
2350
2351 hwc_rect_t cropL = crop, dstL = dst;
2352 hwc_rect_t cropR = crop, dstR = dst;
2353 int hw_w = ctx->dpyAttr[dpy].xres;
2354 int hw_h = ctx->dpyAttr[dpy].yres;
2355
2356 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2357 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2358 // Calculate Left rects
2359 // XXX: This assumes crop.right/2 is the center point of the video
2360 cropL.right = crop.right/2;
2361 dstL.left = dst.left/2;
2362 dstL.right = dst.right/2;
2363
2364 // Calculate Right rects
2365 cropR.left = crop.right/2;
2366 dstR.left = hw_w/2 + dst.left/2;
2367 dstR.right = hw_w/2 + dst.right/2;
2368 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2369 // Calculate Left rects
2370 cropL.bottom = crop.bottom/2;
2371 dstL.top = dst.top/2;
2372 dstL.bottom = dst.bottom/2;
2373
2374 // Calculate Right rects
2375 cropR.top = crop.bottom/2;
2376 dstR.top = hw_h/2 + dst.top/2;
2377 dstR.bottom = hw_h/2 + dst.bottom/2;
2378 } else {
2379 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2380 return -1;
2381 }
2382
2383 //For the mdp, since either we are pre-rotating or MDP does flips
2384 orient = OVERLAY_TRANSFORM_0;
2385 transform = 0;
2386
2387 //configure left pipe
2388 if(lDest != OV_INVALID) {
2389 PipeArgs pargL(mdpFlagsL, whf, lz,
2390 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2391 (ovutils::eBlending) getBlending(layer->blending));
2392
2393 if(configMdp(ctx->mOverlay, pargL, orient,
2394 cropL, dstL, metadata, lDest) < 0) {
2395 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2396 return -1;
2397 }
2398 }
2399
2400 //configure right pipe
2401 if(rDest != OV_INVALID) {
2402 PipeArgs pargR(mdpFlagsR, whf, rz,
2403 static_cast<eRotFlags>(rotFlags),
2404 layer->planeAlpha,
2405 (ovutils::eBlending) getBlending(layer->blending));
2406 if(configMdp(ctx->mOverlay, pargR, orient,
2407 cropR, dstR, metadata, rDest) < 0) {
2408 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2409 return -1;
2410 }
2411 }
2412
2413 return 0;
2414}
2415
radhakrishnac9a67412013-09-25 17:40:42 +05302416int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2417 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002418 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302419 Rotator **rot) {
2420 private_handle_t *hnd = (private_handle_t *)layer->handle;
2421 if(!hnd) {
2422 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2423 return -1;
2424 }
2425
2426 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2427
radhakrishnac9a67412013-09-25 17:40:42 +05302428 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2429 hwc_rect_t dst = layer->displayFrame;
2430 int transform = layer->transform;
2431 eTransform orient = static_cast<eTransform>(transform);
2432 const int downscale = 0;
2433 int rotFlags = ROT_FLAGS_NONE;
2434 //Splitting only YUV layer on primary panel needs different zorders
2435 //for both layers as both the layers are configured to single mixer
2436 eZorder lz = z;
2437 eZorder rz = (eZorder)(z + 1);
2438
2439 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302440 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302441
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002442 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002443 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2444 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002445 }
2446
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002447 /* Calculate the external display position based on MDP downscale,
2448 ActionSafe, and extorientation features. */
2449 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2450
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002451 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302452 trimLayer(ctx, dpy, transform, crop, dst);
2453
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002454 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302455 (*rot) = ctx->mRotMgr->getNext();
2456 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002457 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302458 //Configure rotator for pre-rotation
2459 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2460 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302461 return -1;
2462 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002463 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302464 rotFlags |= ROT_PREROTATED;
2465 }
2466
2467 eMdpFlags mdpFlagsR = mdpFlagsL;
2468 int lSplit = dst.left + (dst.right - dst.left)/2;
2469
2470 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2471 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2472
2473 if(lDest != OV_INVALID) {
2474 tmp_cropL = crop;
2475 tmp_dstL = dst;
2476 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2477 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2478 }
2479 if(rDest != OV_INVALID) {
2480 tmp_cropR = crop;
2481 tmp_dstR = dst;
2482 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2483 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2484 }
2485
2486 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2487
2488 //When buffer is H-flipped, contents of mixer config also needs to swapped
2489 //Not needed if the layer is confined to one half of the screen.
2490 //If rotator has been used then it has also done the flips, so ignore them.
2491 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2492 && rDest != OV_INVALID && (*rot) == NULL) {
2493 hwc_rect_t new_cropR;
2494 new_cropR.left = tmp_cropL.left;
2495 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2496
2497 hwc_rect_t new_cropL;
2498 new_cropL.left = new_cropR.right;
2499 new_cropL.right = tmp_cropR.right;
2500
2501 tmp_cropL.left = new_cropL.left;
2502 tmp_cropL.right = new_cropL.right;
2503
2504 tmp_cropR.left = new_cropR.left;
2505 tmp_cropR.right = new_cropR.right;
2506
2507 }
2508
2509 //For the mdp, since either we are pre-rotating or MDP does flips
2510 orient = OVERLAY_TRANSFORM_0;
2511 transform = 0;
2512
2513 //configure left half
2514 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002515 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302516 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2517 (ovutils::eBlending) getBlending(layer->blending));
2518
2519 if(configMdp(ctx->mOverlay, pargL, orient,
2520 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2521 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2522 return -1;
2523 }
2524 }
2525
2526 //configure right half
2527 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002528 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302529 static_cast<eRotFlags>(rotFlags),
2530 layer->planeAlpha,
2531 (ovutils::eBlending) getBlending(layer->blending));
2532 if(configMdp(ctx->mOverlay, pargR, orient,
2533 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2534 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2535 return -1;
2536 }
2537 }
2538
2539 return 0;
2540}
2541
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002542bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302543 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002544 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002545 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302546 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302547 * in LINE and BLOCK modes for writeback panels.
2548 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002549 if(dpy == HWC_DISPLAY_PRIMARY)
2550 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002551 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302552 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2553 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002554 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002555 return true;
2556}
2557
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002558int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2559 //Default even split for all displays with high res
2560 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2561 if(dpy == HWC_DISPLAY_PRIMARY &&
2562 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2563 //Override if split published by driver for primary
2564 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2565 }
2566 return lSplit;
2567}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002568
Saurabh Shah88e4d272013-09-03 13:31:29 -07002569bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302570 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002571 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002572 return true;
2573 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302574 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002575 return true;
2576 }
2577 return false;
2578}
2579
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002580//clear prev layer prop flags and realloc for current frame
2581void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2582 if(ctx->layerProp[dpy]) {
2583 delete[] ctx->layerProp[dpy];
2584 ctx->layerProp[dpy] = NULL;
2585 }
2586 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2587}
2588
Ramakant Singh0def28c2014-03-28 20:43:13 +05302589bool isAbcInUse(hwc_context_t *ctx){
2590 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2591}
2592
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002593void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2594 if (ohnd != NULL && ohnd->base) {
2595 char dumpFilename[PATH_MAX];
2596 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002597 int width = getWidth(ohnd);
2598 int height = getHeight(ohnd);
2599 int format = ohnd->format;
2600 //dummy aligned w & h.
2601 int alW = 0, alH = 0;
2602 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002603 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2604 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002605 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2606 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002607 FILE* fp = fopen(dumpFilename, "w+");
2608 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002609 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002610 fclose(fp);
2611 }
2612 ALOGD("Buffer[%s] Dump to %s: %s",
2613 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2614 }
2615}
2616
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002617bool isGLESComp(hwc_context_t *ctx,
2618 hwc_display_contents_1_t* list) {
2619 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2620 for(int index = 0; index < numAppLayers; index++) {
2621 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2622 if(layer->compositionType == HWC_FRAMEBUFFER)
2623 return true;
2624 }
2625 return false;
2626}
2627
2628void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2629 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002630 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002631 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002632
2633#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002634 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2635 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2636 hint to default if the previous composition is GPU or current GPU
2637 composition is due to idle fallback */
2638 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2639 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2640 if(!gpuHint->mEGLDisplay) {
2641 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2642 return;
2643 }
2644 gpuHint->mEGLContext = eglGetCurrentContext();
2645 if(!gpuHint->mEGLContext) {
2646 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2647 return;
2648 }
2649 }
2650 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002651 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2652 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002653 EGLint attr_list[] = {EGL_GPU_HINT_1,
2654 EGL_GPU_LEVEL_3,
2655 EGL_NONE };
2656 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2657 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2658 gpuHint->mEGLContext, attr_list)) {
2659 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2660 } else {
2661 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002662 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002663 }
2664 } else {
2665 EGLint attr_list[] = {EGL_GPU_HINT_1,
2666 EGL_GPU_LEVEL_0,
2667 EGL_NONE };
2668 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2669 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2670 gpuHint->mEGLContext, attr_list)) {
2671 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2672 } else {
2673 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2674 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002675 if(MDPComp::isIdleFallback()) {
2676 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2677 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002678 }
2679 } else {
2680 /* set the GPU hint flag to default for MDP composition */
2681 EGLint attr_list[] = {EGL_GPU_HINT_1,
2682 EGL_GPU_LEVEL_0,
2683 EGL_NONE };
2684 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2685 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2686 gpuHint->mEGLContext, attr_list)) {
2687 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2688 } else {
2689 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2690 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002691 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002692 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002693#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002694}
2695
Sushil Chauhandefd3522014-05-13 18:17:12 -07002696bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2697 // To be peripheral, 3 boundaries should match.
2698 uint8_t eqBounds = 0;
2699 if (rect1.left == rect2.left)
2700 eqBounds++;
2701 if (rect1.top == rect2.top)
2702 eqBounds++;
2703 if (rect1.right == rect2.right)
2704 eqBounds++;
2705 if (rect1.bottom == rect2.bottom)
2706 eqBounds++;
2707 return (eqBounds == 3);
2708}
2709
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302710void processBootAnimCompleted(hwc_context_t *ctx) {
2711 char value[PROPERTY_VALUE_MAX];
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302712 int ret = -1;
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302713
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302714 // Applying default mode after bootanimation is finished
2715 property_get("init.svc.bootanim", value, "running");
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302716
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302717 if (!strncmp(value,"stopped",strlen("stopped"))) {
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302718 ctx->mBootAnimCompleted = true;
Zohaib Alam83ea46d2015-03-23 15:44:19 -04002719
2720 //one-shot action check if bootanimation completed then apply
2721 //default display mode.
2722 qdcmApplyDefaultAfterBootAnimationDone(ctx);
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302723 }
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302724}
2725
Saurabh Shahcd018352014-11-11 13:54:19 -08002726void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2727 const private_handle_t *hnd,
2728 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002729 const int& transform,const int& downscale,
2730 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002731 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302732 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002733 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002734 return;
2735 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002736 //Disabled at runtime
2737 if(not ctx->mBWCEnabled) return;
2738 //BWC not supported with rot-downscale
2739 if(downscale) return;
2740 //Not enabled for secondary displays
2741 if(dpy) return;
2742 //Not enabled for non-video buffers
2743 if(not isYuvBuffer(hnd)) return;
2744
Saurabh Shahb6810df2014-06-17 16:00:22 -07002745 int src_w = crop.right - crop.left;
2746 int src_h = crop.bottom - crop.top;
2747 int dst_w = dst.right - dst.left;
2748 int dst_h = dst.bottom - dst.top;
2749 if(transform & HAL_TRANSFORM_ROT_90) {
2750 swap(src_w, src_h);
2751 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002752 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002753 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002754 return;
2755 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002756 //Decimation necessary, cannot use BWC. H/W requirement.
2757 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002758 uint8_t horzDeci = 0;
2759 uint8_t vertDeci = 0;
2760 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2761 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002762 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002763 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002764
2765 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2766}
2767
Saurabh Shah23a813c2013-03-20 16:58:12 -07002768void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302769 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002770 mLayer[mCount] = layer;
2771 mRot[mCount] = rot;
2772 mCount++;
2773}
2774
2775void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302776 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002777 mLayer[i] = 0;
2778 mRot[i] = 0;
2779 }
2780 mCount = 0;
2781}
2782
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002783void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002784 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002785 reset();
2786}
2787
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302788bool LayerRotMap::isRotCached(uint32_t index) const {
2789 overlay::Rotator* rot = getRot(index);
2790 hwc_layer_1_t* layer = getLayer(index);
2791
2792 if(rot and layer and layer->handle) {
2793 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2794 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2795 }
2796 return false;
2797}
2798
Saurabh Shah23a813c2013-03-20 16:58:12 -07002799void LayerRotMap::setReleaseFd(const int& fence) {
2800 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302801 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2802 /* Ensure that none of the above (Rotator-instance,
2803 * layer and layer-handle) are NULL*/
2804 if(isRotCached(i))
2805 mRot[i]->setPrevBufReleaseFd(dup(fence));
2806 else
2807 mRot[i]->setCurrBufReleaseFd(dup(fence));
2808 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002809 }
2810}
2811
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002812hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2813 int lRoiWidth = 0, rRoiWidth = 0;
2814 int half_frame_width = fullFrame.right/2;
2815
2816 hwc_rect lFrame = fullFrame;
2817 hwc_rect rFrame = fullFrame;
2818 lFrame.right = (lFrame.right - lFrame.left)/2;
2819 rFrame.left = lFrame.right;
2820
2821 hwc_rect lRoi = getIntersection(roi, lFrame);
2822 hwc_rect rRoi = getIntersection(roi, rFrame);
2823
2824 lRoiWidth = lRoi.right - lRoi.left;
2825 rRoiWidth = rRoi.right - rRoi.left;
2826
2827 if(lRoiWidth && rRoiWidth) {
2828 if(lRoiWidth < rRoiWidth)
2829 roi.left = half_frame_width - rRoiWidth;
2830 else
2831 roi.right = half_frame_width + lRoiWidth;
2832 }
2833 return roi;
2834}
2835
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002836void resetROI(hwc_context_t *ctx, const int dpy) {
2837 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2838 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002839
2840 /* When source split is enabled, both the panels are calibrated
2841 * in a single coordinate system. So only one ROI is generated
2842 * for the whole panel extending equally from the midpoint and
2843 * populated for the left side. */
2844 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2845 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002846 const int lSplit = getLeftSplit(ctx, dpy);
2847 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2848 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2849 } else {
2850 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2851 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2852 }
2853}
2854
2855hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002856{
2857 if(!isValidRect(roi))
2858 return roi;
2859
2860 struct hwc_rect t_roi = roi;
2861
2862 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2863 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2864 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2865 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2866 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002867 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002868
2869 /* Align to minimum width recommended by the panel */
2870 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2871 if((t_roi.left + MIN_WIDTH) > boundary.right)
2872 t_roi.left = t_roi.right - MIN_WIDTH;
2873 else
2874 t_roi.right = t_roi.left + MIN_WIDTH;
2875 }
2876
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002877 /* Align to minimum height recommended by the panel */
2878 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2879 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2880 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2881 else
2882 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2883 }
2884
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002885 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002886 if(LEFT_ALIGN)
2887 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2888
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002889 if(WIDTH_ALIGN) {
2890 int width = t_roi.right - t_roi.left;
2891 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2892 t_roi.right = t_roi.left + width;
2893
2894 if(t_roi.right > boundary.right) {
2895 t_roi.right = boundary.right;
2896 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002897
2898 if(LEFT_ALIGN)
2899 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002900 }
2901 }
2902
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002903
2904 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002905 if(TOP_ALIGN)
2906 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2907
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002908 if(HEIGHT_ALIGN) {
2909 int height = t_roi.bottom - t_roi.top;
2910 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2911 t_roi.bottom = t_roi.top + height;
2912
2913 if(t_roi.bottom > boundary.bottom) {
2914 t_roi.bottom = boundary.bottom;
2915 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002916
2917 if(TOP_ALIGN)
2918 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002919 }
2920 }
2921
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002922
2923 return t_roi;
2924}
2925
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002926void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002927 if(ctx->dpyAttr[dpy].connected) {
2928 ctx->mDrawLock.lock();
2929 ctx->dpyAttr[dpy].isActive = true;
2930 ctx->dpyAttr[dpy].isPause = true;
2931 ctx->mDrawLock.unlock();
2932 ctx->proc->invalidate(ctx->proc);
2933
2934 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2935 * 2 / 1000);
2936
2937 // At this point all the pipes used by External have been
2938 // marked as UNSET.
2939 ctx->mDrawLock.lock();
2940 // Perform commit to unstage the pipes.
2941 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2942 ALOGE("%s: display commit fail! for %d dpy",
2943 __FUNCTION__, dpy);
2944 }
2945 ctx->mDrawLock.unlock();
2946 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002947 }
2948 return;
2949}
2950
2951void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002952 if(ctx->dpyAttr[dpy].connected) {
2953 ctx->mDrawLock.lock();
2954 ctx->dpyAttr[dpy].isConfiguring = true;
2955 ctx->dpyAttr[dpy].isActive = true;
2956 ctx->mDrawLock.unlock();
2957 ctx->proc->invalidate(ctx->proc);
2958
2959 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2960 * 2 / 1000);
2961
2962 //At this point external has all the pipes it would need.
2963 ctx->mDrawLock.lock();
2964 ctx->dpyAttr[dpy].isPause = false;
2965 ctx->mDrawLock.unlock();
2966 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002967 }
2968 return;
2969}
2970
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002971void clearPipeResources(hwc_context_t* ctx, int dpy) {
2972 if(ctx->mOverlay) {
2973 ctx->mOverlay->configBegin();
2974 ctx->mOverlay->configDone();
2975 }
2976 if(ctx->mRotMgr) {
2977 ctx->mRotMgr->clear();
2978 }
2979 // Call a display commit to ensure that pipes and associated
2980 // fd's are cleaned up.
2981 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2982 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2983 }
2984}
2985
2986// Handles online events when HDMI is the primary display. In particular,
2987// online events for hdmi connected before AND after boot up and HWC init.
2988void handle_online(hwc_context_t* ctx, int dpy) {
2989 // Close the current fd if it was opened earlier on when HWC
2990 // was initialized.
2991 if (ctx->dpyAttr[dpy].fd >= 0) {
2992 close(ctx->dpyAttr[dpy].fd);
2993 ctx->dpyAttr[dpy].fd = -1;
2994 }
2995 // TODO: If HDMI is connected after the display has booted up,
2996 // and the best configuration is different from the default
2997 // then we need to deal with this appropriately.
Arun Kumar K.R205df772015-02-20 18:45:58 -08002998 int error = ctx->mHDMIDisplay->configure();
2999 if (error < 0) {
3000 ALOGE("Error opening FrameBuffer");
3001 return;
3002 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003003 updateDisplayInfo(ctx, dpy);
3004 initCompositionResources(ctx, dpy);
3005 ctx->dpyAttr[dpy].connected = true;
3006}
3007
3008// Handles offline events for HDMI. This can be used for offline events
3009// initiated by the HDMI driver and the CEC framework.
3010void handle_offline(hwc_context_t* ctx, int dpy) {
3011 destroyCompositionResources(ctx, dpy);
3012 // Clear all pipe resources and call a display commit to ensure
3013 // that all the fd's are closed. This will ensure that the HDMI
3014 // core turns off and that we receive an event the next time the
3015 // cable is connected.
3016 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
3017 clearPipeResources(ctx, dpy);
3018 }
3019 ctx->mHDMIDisplay->teardown();
3020 resetDisplayInfo(ctx, dpy);
3021 ctx->dpyAttr[dpy].connected = false;
3022 ctx->dpyAttr[dpy].isActive = false;
3023}
3024
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05003025int convertS3DFormatToMode(int s3DFormat) {
3026 int ret;
3027 switch(s3DFormat) {
3028 case HAL_3D_SIDE_BY_SIDE_L_R:
3029 case HAL_3D_SIDE_BY_SIDE_R_L:
3030 ret = HDMI_S3D_SIDE_BY_SIDE;
3031 break;
3032 case HAL_3D_TOP_BOTTOM:
3033 ret = HDMI_S3D_TOP_AND_BOTTOM;
3034 break;
3035 default:
3036 ret = HDMI_S3D_NONE;
3037 }
3038 return ret;
3039}
3040
3041bool needs3DComposition(hwc_context_t* ctx, int dpy) {
3042 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
3043 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3044}
3045
3046void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3047 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3048 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3049 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3050 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3051 }
3052 }
3053}
3054
3055bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3056 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3057 ((dpy == HWC_DISPLAY_PRIMARY) &&
3058 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3059}
3060
3061
Saurabh Shahacf10202013-02-26 10:15:15 -08003062};//namespace qhwc