blob: a3cb196cdb8be0b7debd9e62d7faa1cc045e9685 [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"
Ramakant Singh98c533c2014-09-30 19:01:54 +053046#include <sys/sysinfo.h>
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +053047#include <dlfcn.h>
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050048#include <video/msm_hdmi_modes.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080049
50using namespace qClient;
51using namespace qService;
52using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080053using namespace overlay;
54using namespace overlay::utils;
55namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080056
Saurabh Shah74eff4d2014-03-28 16:33:13 -070057#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070058#ifdef __cplusplus
59extern "C" {
60#endif
61
62EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
63 EGLint *attrib_list);
64#define EGL_GPU_HINT_1 0x32D0
65#define EGL_GPU_HINT_2 0x32D1
66
67#define EGL_GPU_LEVEL_0 0x0
68#define EGL_GPU_LEVEL_1 0x1
69#define EGL_GPU_LEVEL_2 0x2
70#define EGL_GPU_LEVEL_3 0x3
71#define EGL_GPU_LEVEL_4 0x4
72#define EGL_GPU_LEVEL_5 0x5
73
74#ifdef __cplusplus
75}
76#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070077#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070078
Ramakant Singhbe390c72014-12-03 23:04:21 +053079#define PROP_DEFAULT_APPBUFFER "hw.sf.app_buff_count"
Ramakant Singh98c533c2014-09-30 19:01:54 +053080#define MAX_RAM_SIZE 512*1024*1024
81#define qHD_WIDTH 540
82
83
Naseer Ahmed29a26812012-06-14 00:56:20 -070084namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070085
Arun Kumar K.R053dc502014-11-13 11:13:43 -080086// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
87uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070088
radhakrishnac3198ff2015-03-10 17:10:02 +053089static uint32_t getFBformat(fb_var_screeninfo vinfo) {
90 uint32_t fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
91
92#ifdef GET_FRAMEBUFFER_FORMAT_FROM_HWC
93 // Here, we are adding the formats that are supported by both GPU and MDP.
94 // The formats that fall in this category are RGBA_8888, RGB_565, RGB_888
95 switch(vinfo.bits_per_pixel) {
96 case 16:
97 fbformat = HAL_PIXEL_FORMAT_RGB_565;
98 break;
99 case 24:
100 if ((vinfo.transp.offset == 0) && (vinfo.transp.length == 0))
101 fbformat = HAL_PIXEL_FORMAT_RGB_888;
102 break;
103 case 32:
104 if ((vinfo.red.offset == 0) && (vinfo.green.offset == 8) &&
105 (vinfo.blue.offset == 16) && (vinfo.transp.offset == 24))
106 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
107 break;
108 default:
109 fbformat = HAL_PIXEL_FORMAT_RGBA_8888;
110 }
111#endif
112 return fbformat;
113}
114
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530115bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
116{
Jeykumar Sankaran39305802014-12-12 17:55:57 -0800117 return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530118 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
119 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
120}
121
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800122static void handleFbScaling(hwc_context_t *ctx, int xresPanel, int yresPanel,
123 int width, int height) {
124 const int dpy = HWC_DISPLAY_PRIMARY;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530125 //Store original display resolution.
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800126 ctx->dpyAttr[dpy].xresFB = xresPanel;
127 ctx->dpyAttr[dpy].yresFB = yresPanel;
128 ctx->dpyAttr[dpy].fbScaling = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530129 char property[PROPERTY_VALUE_MAX] = {'\0'};
130 char *yptr = NULL;
131 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
132 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530133 if(yptr) {
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800134 int xresFB = atoi(property);
135 int yresFB = atoi(yptr + 1);
136 if (isValidResolution(ctx, xresFB, yresFB) &&
137 xresFB != xresPanel && yresFB != yresPanel) {
138 ctx->dpyAttr[dpy].xresFB = xresFB;
139 ctx->dpyAttr[dpy].yresFB = yresFB;
140 ctx->dpyAttr[dpy].fbScaling = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530141
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800142 //Calculate DPI according to changed resolution.
143 float xdpi = ((float)xresFB * 25.4f) / (float)width;
144 float ydpi = ((float)yresFB * 25.4f) / (float)height;
145 ctx->dpyAttr[dpy].xdpi = xdpi;
146 ctx->dpyAttr[dpy].ydpi = ydpi;
Raj Kamal4a443082014-10-12 21:07:59 +0530147 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530148 }
149 }
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800150 ctx->dpyAttr[dpy].fbWidthScaleRatio = (float) ctx->dpyAttr[dpy].xres /
151 (float) ctx->dpyAttr[dpy].xresFB;
152 ctx->dpyAttr[dpy].fbHeightScaleRatio = (float) ctx->dpyAttr[dpy].yres /
153 (float) ctx->dpyAttr[dpy].yresFB;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530154}
155
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700156// Initialize hdmi display attributes based on
157// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700158void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
radhakrishnac3198ff2015-03-10 17:10:02 +0530159 struct fb_var_screeninfo info;
160
161 if (ioctl(ctx->mHDMIDisplay->getFd(), FBIOGET_VSCREENINFO, &info) == -1) {
162 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s",
163 __FUNCTION__, strerror(errno));
164 }
165
166 ctx->dpyAttr[dpy].fbformat = getFBformat(info);
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700167 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
168 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
169 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
170 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
171 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700172 //FIXME: for now assume HDMI as secure
173 //Will need to read the HDCP status from the driver
174 //and update this accordingly
175 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700176 ctx->mViewFrame[dpy].left = 0;
177 ctx->mViewFrame[dpy].top = 0;
178 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
179 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
180}
181
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700182// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700183void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
184 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
185 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
186 // We reset the fd to -1 here but External display class is responsible
187 // for it when the display is disconnected. This is handled as part of
188 // EXTERNAL_OFFLINE event.
189 ctx->dpyAttr[dpy].fd = -1;
190}
191
192// Initialize composition resources
193void initCompositionResources(hwc_context_t* ctx, int dpy) {
194 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
195 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
196}
197
198void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
199 if(ctx->mFBUpdate[dpy]) {
200 delete ctx->mFBUpdate[dpy];
201 ctx->mFBUpdate[dpy] = NULL;
202 }
203 if(ctx->mMDPComp[dpy]) {
204 delete ctx->mMDPComp[dpy];
205 ctx->mMDPComp[dpy] = NULL;
206 }
207}
208
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800209static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700210{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800211 struct fb_fix_screeninfo finfo;
212 struct fb_var_screeninfo info;
213
214 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530215 if(fb_fd < 0) {
216 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800217 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530218 }
219
220 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
221 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
222 strerror(errno));
223 close(fb_fd);
224 return -errno;
225 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800226
227 if (int(info.width) <= 0 || int(info.height) <= 0) {
228 // the driver doesn't return that information
229 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530230 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
231 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700232 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800233
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530234 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
235 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800236
237#ifdef MSMFB_METADATA_GET
238 struct msmfb_metadata metadata;
239 memset(&metadata, 0 , sizeof(metadata));
240 metadata.op = metadata_op_frame_rate;
241
242 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530243 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
244 strerror(errno));
245 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800246 return -errno;
247 }
248
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530249 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800250#else
251 //XXX: Remove reserved field usage on all baselines
252 //The reserved[3] field is used to store FPS by the driver.
253 float fps = info.reserved[3] & 0xFF;
254#endif
255
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530256 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
257 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
258 strerror(errno));
259 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800260 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530261 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800262
263 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
264 //xres, yres may not be 32 aligned
265 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
266 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
267 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
268 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
269 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700270 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
271 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700272 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530273 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
274 (uint32_t)(1000000000l / fps);
radhakrishnac3198ff2015-03-10 17:10:02 +0530275 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fbformat = getFBformat(info);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800276
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800277 handleFbScaling(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530278
Naseer Ahmed22616d92013-05-15 17:20:26 -0400279 //Unblank primary on first boot
280 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
281 ALOGE("%s: Failed to unblank display", __FUNCTION__);
282 return -errno;
283 }
284 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
285
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800286 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700287}
288
Ramakant Singh98c533c2014-09-30 19:01:54 +0530289static void changeDefaultAppBufferCount() {
290 struct sysinfo info;
291 unsigned long int ramSize = 0;
292 if (!sysinfo(&info)) {
293 ramSize = info.totalram ;
294 }
295 int fb_fd = -1;
296 struct fb_var_screeninfo sInfo ={0};
297 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
298 if (fb_fd >=0) {
299 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
300 close(fb_fd);
301 }
302 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
303 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
Sanjeev Jakkilinkif8bc0362015-02-23 20:20:17 +0530304 property_set(PROP_DEFAULT_APPBUFFER, "3");
Ramakant Singh98c533c2014-09-30 19:01:54 +0530305 }
306}
307
Arun Kumar K.R205df772015-02-20 18:45:58 -0800308int initContext(hwc_context_t *ctx)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700309{
Arun Kumar K.R205df772015-02-20 18:45:58 -0800310 int error = -1;
311 int compositionType = 0;
312
313 //Right now hwc starts the service but anybody could do it, or it could be
314 //independent process as well.
315 QService::init();
316 sp<IQClient> client = new QClient(ctx);
317 sp<IQService> iqs = interface_cast<IQService>(
318 defaultServiceManager()->getService(
319 String16("display.qservice")));
320 if (iqs.get()) {
321 iqs->connect(client);
322 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
323 } else {
324 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
325 return error;
326 }
327
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700328 overlay::Overlay::initOverlay();
329 ctx->mHDMIDisplay = new HDMIDisplay();
330 uint32_t priW = 0, priH = 0;
331 // 1. HDMI as Primary
332 // -If HDMI cable is connected, read display configs from edid data
333 // -If HDMI cable is not connected then use default data in vscreeninfo
334 // 2. HDMI as External
335 // -Initialize HDMI class for use with external display
336 // -Use vscreeninfo to populate display configs
337 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
338 int connected = ctx->mHDMIDisplay->getConnectedState();
339 if(connected == 1) {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800340 error = ctx->mHDMIDisplay->configure();
341 if (error < 0) {
342 goto OpenFBError;
343 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700344 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
345 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
346 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800347 error = openFramebufferDevice(ctx);
348 if(error < 0) {
349 goto OpenFBError;
350 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700351 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
352 }
353 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800354 error = openFramebufferDevice(ctx);
355 if(error < 0) {
356 goto OpenFBError;
357 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700358 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
359 // Send the primary resolution to the hdmi display class
360 // to be used for MDP scaling functionality
361 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
362 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
363 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
364 }
365
Raj kamal59fea562014-04-01 16:52:19 +0530366 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700367 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
368 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
369 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800370 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800371 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800372 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800373
Ramakant Singh98c533c2014-09-30 19:01:54 +0530374 //default_app_buffer for ferrum
375 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
376 changeDefaultAppBufferCount();
377 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700378 // Initialize composition objects for the primary display
379 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800380
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800381 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800382 // decide if we need to open the copybit module.
Arun Kumar K.R205df772015-02-20 18:45:58 -0800383 compositionType =
384 qdutils::QCCompositionType::getInstance().getCompositionType();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800385
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800386 // Only MDP copybit is used
387 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
388 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530389 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
390 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800391 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530392 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800393 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
394 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800395 }
396
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700397 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700398 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
399 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
400 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
401 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700402 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
403 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
404 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800405
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700406 //Initialize the primary display viewFrame info
407 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
408 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
409 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
410 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
411 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
412 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530413
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700414 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700415 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700416 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700417 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800418 ctx->dpyAttr[i].mActionSafePresent = false;
419 ctx->dpyAttr[i].mAsWidthRatio = 0;
420 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500421 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
422 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700423 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700424
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500425 //Make sure that the 3D mode is unset at bootup
426 //This makes sure that the state is accurate on framework reboots
427 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
428
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530429 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
430 ctx->mPrevHwLayerCount[i] = 0;
431 }
432
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500433 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700434 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700435
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400436 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500437 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700438 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530439 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800440
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700441 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700442 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700443 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400444
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700445 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
446 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
447
Ramakant Singh0def28c2014-03-28 20:43:13 +0530448 ctx->enableABC = false;
449 property_get("debug.sf.hwc.canUseABC", value, "0");
450 ctx->enableABC = atoi(value) ? true : false;
451
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530452 // Initializing boot anim completed check to false
453 ctx->mBootAnimCompleted = false;
454
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700455 // Initialize gpu perfomance hint related parameters
456 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700457#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700458 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
459
460 ctx->mGPUHintInfo.mEGLDisplay = NULL;
461 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700462 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700463 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700464#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700465 // Read the system property to determine if windowboxing feature is enabled.
466 ctx->mWindowboxFeature = false;
467 if(property_get("sys.hwc.windowbox_feature", value, "false")
468 && !strcmp(value, "true")) {
469 ctx->mWindowboxFeature = true;
470 }
471
Raj Kamal0d53fc62014-11-25 17:36:36 +0530472 ctx->mUseMetaDataRefreshRate = true;
473 if(property_get("persist.metadata_dynfps.disable", value, "false")
474 && !strcmp(value, "true")) {
475 ctx->mUseMetaDataRefreshRate = false;
476 }
477
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700478 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800479 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700480 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700481 ALOGI("MDP version: %d", ctx->mMDP.version);
Arun Kumar K.R205df772015-02-20 18:45:58 -0800482
483 return 0;
484
485OpenFBError:
486 ALOGE("%s: Fatal Error: FB Open failed!!!", __FUNCTION__);
487 delete ctx->mHDMIDisplay;
488 return error;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700489}
490
491void closeContext(hwc_context_t *ctx)
492{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500493 if(ctx->mOverlay) {
494 delete ctx->mOverlay;
495 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700496 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700497
Saurabh Shahacf10202013-02-26 10:15:15 -0800498 if(ctx->mRotMgr) {
499 delete ctx->mRotMgr;
500 ctx->mRotMgr = NULL;
501 }
502
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700503 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800504 if(ctx->mCopyBit[i]) {
505 delete ctx->mCopyBit[i];
506 ctx->mCopyBit[i] = NULL;
507 }
508 }
509
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800510 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700511 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
512 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700513 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700514
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700515 if(ctx->mHDMIDisplay) {
516 delete ctx->mHDMIDisplay;
517 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700518 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400519
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700520 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700521 destroyCompositionResources(ctx, i);
522
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700523 if(ctx->mHwcDebug[i]) {
524 delete ctx->mHwcDebug[i];
525 ctx->mHwcDebug[i] = NULL;
526 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700527 if(ctx->mLayerRotMap[i]) {
528 delete ctx->mLayerRotMap[i];
529 ctx->mLayerRotMap[i] = NULL;
530 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800531 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800532 if(ctx->mHWCVirtual) {
533 delete ctx->mHWCVirtual;
534 ctx->mHWCVirtual = NULL;
535 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700536 if(ctx->mAD) {
537 delete ctx->mAD;
538 ctx->mAD = NULL;
539 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800540
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400541 if(ctx->mQService) {
542 delete ctx->mQService;
543 ctx->mQService = NULL;
544 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700545}
546
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700547//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530548uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700549 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
550 uint32_t rate = refreshRate;
551 for(int i=0; i< count; i++) {
552 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
553 // Most likely used for video, the fps can fluctuate
554 // Ex: b/w 29 and 30 for 30 fps clip
555 rate = stdRefreshRates[i];
556 break;
557 }
558 }
559 return rate;
560}
561
562//Helper func to set the dyn fps
563void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
564 //Update only if different
565 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
566 return;
567 const int fbNum = Overlay::getFbForDpy(dpy);
568 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
569 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800570 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700571
572 int fd = open(sysfsPath, O_WRONLY);
573 if(fd >= 0) {
574 char str[64];
575 snprintf(str, sizeof(str), "%d", refreshRate);
576 ssize_t ret = write(fd, str, strlen(str));
577 if(ret < 0) {
578 ALOGE("%s: Failed to write %d with error %s",
579 __FUNCTION__, refreshRate, strerror(errno));
580 } else {
581 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
582 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
583 __FUNCTION__, refreshRate);
584 }
585 close(fd);
586 } else {
587 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
588 strerror(errno));
589 }
590}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500591
592void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700593{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500594 va_list varargs;
595 va_start(varargs, fmt);
596 buf.appendFormatV(fmt, varargs);
597 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700598}
599
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700600int getExtOrientation(hwc_context_t* ctx) {
601 int extOrient = ctx->mExtOrientation;
602 if(ctx->mBufferMirrorMode)
603 extOrient = getMirrorModeOrientation(ctx);
604 return extOrient;
605}
606
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800607/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700608void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
609 // Position
610 int x = rect.left, y = rect.top;
611 int w = rect.right - rect.left;
612 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800613
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800614 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800615 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800616 // Read action safe properties
617 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
618 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700619
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800620 float wRatio = 1.0;
621 float hRatio = 1.0;
622 float xRatio = 1.0;
623 float yRatio = 1.0;
624
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700625 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
626 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700627 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
628 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700629 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700630 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700631 }
632
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800633
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700634 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700635 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700636
637 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700638 swap(fbWidth, fbHeight);
639
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800640 float asX = 0;
641 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530642 float asW = (float)fbWidth;
643 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800644
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800645 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530646 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
647 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
648 asX = ((float)fbWidth - asW) / 2;
649 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800650
651 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530652 xRatio = (float)x/(float)fbWidth;
653 yRatio = (float)y/(float)fbHeight;
654 wRatio = (float)w/(float)fbWidth;
655 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800656
657 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530658 x = int((xRatio * asW) + asX);
659 y = int((yRatio * asH) + asY);
660 w = int(wRatio * asW);
661 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800662
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700663 // Convert it back to hwc_rect_t
664 rect.left = x;
665 rect.top = y;
666 rect.right = w + rect.left;
667 rect.bottom = h + rect.top;
668
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800669 return;
670}
671
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700672// This function gets the destination position for Seconday display
673// based on the position and aspect ratio with orientation
674void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
675 hwc_rect_t& inRect, hwc_rect_t& outRect) {
676 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530677 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
678 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700679 //display position(x,y,w,h) in correct aspectratio after rotation
680 int xPos = 0;
681 int yPos = 0;
682 float width = fbWidth;
683 float height = fbHeight;
684 // Width/Height used for calculation, after rotation
685 float actualWidth = fbWidth;
686 float actualHeight = fbHeight;
687
688 float wRatio = 1.0;
689 float hRatio = 1.0;
690 float xRatio = 1.0;
691 float yRatio = 1.0;
692 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
693
694 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
695 inRect.bottom - inRect.top);
696 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
697 outRect.bottom - outRect.top);
698
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530699 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700700 eTransform extorient = static_cast<eTransform>(extOrientation);
701 // To calculate the destination co-ordinates in the new orientation
702 preRotateSource(extorient, whf, inPos);
703
704 if(extOrientation & HAL_TRANSFORM_ROT_90) {
705 // Swap width/height for input position
706 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700707 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
708 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700709 xPos = rect.left;
710 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530711 width = float(rect.right - rect.left);
712 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700713 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700714 xRatio = (float)((float)inPos.x/actualWidth);
715 yRatio = (float)((float)inPos.y/actualHeight);
716 wRatio = (float)((float)inPos.w/actualWidth);
717 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800718
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530719 //Calculate the pos9ition...
720 outPos.x = uint32_t((xRatio * width) + (float)xPos);
721 outPos.y = uint32_t((yRatio * height) + (float)yPos);
722 outPos.w = uint32_t(wRatio * width);
723 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700724 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
725 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
726 outPos.w, outPos.h);
727
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700728 // For sidesync, the dest fb will be in portrait orientation, and the crop
729 // will be updated to avoid the black side bands, and it will be upscaled
730 // to fit the dest RB, so recalculate
731 // the position based on the new width and height
732 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
733 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800734 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700735 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530736 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700737 // GetaspectRatio -- tricky to get the correct aspect ratio
738 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700739 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530740 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700741 xPos = r.left;
742 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530743 float tempHeight = float(r.bottom - r.top);
744 yRatio = (float)yPos/height;
745 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700746 hRatio = tempHeight/height;
747
748 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530749 outPos.x = uint32_t(xRatio * fbWidth);
750 outPos.y = uint32_t(yRatio * fbHeight);
751 outPos.w = uint32_t(wRatio * fbWidth);
752 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700753
754 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
755 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
756 outPos.x, outPos.y,
757 outPos.w, outPos.h);
758 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700759 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700760 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700761 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700762 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700763 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
764 extW = ctx->mHWCVirtual->getScalingWidth();
765 extH = ctx->mHWCVirtual->getScalingHeight();
766 }
767 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
768 __FUNCTION__, extW, extH);
769
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530770 fbWidth = (float)ctx->dpyAttr[dpy].xres;
771 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700772 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530773 xRatio = (float)outPos.x/fbWidth;
774 yRatio = (float)outPos.y/fbHeight;
775 wRatio = (float)outPos.w/fbWidth;
776 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700777
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530778 outPos.x = uint32_t(xRatio * (float)extW);
779 outPos.y = uint32_t(yRatio * (float)extH);
780 outPos.w = uint32_t(wRatio * (float)extW);
781 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700782 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700783 // Convert Dim to hwc_rect_t
784 outRect.left = outPos.x;
785 outRect.top = outPos.y;
786 outRect.right = outPos.x + outPos.w;
787 outRect.bottom = outPos.y + outPos.h;
788
789 return;
790}
791
792bool isPrimaryPortrait(hwc_context_t *ctx) {
793 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
794 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
795 if(fbWidth < fbHeight) {
796 return true;
797 }
798 return false;
799}
800
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700801bool isOrientationPortrait(hwc_context_t *ctx) {
802 if(isPrimaryPortrait(ctx)) {
803 return !(ctx->deviceOrientation & 0x1);
804 }
805 return (ctx->deviceOrientation & 0x1);
806}
807
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700808void calcExtDisplayPosition(hwc_context_t *ctx,
809 private_handle_t *hnd,
810 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700811 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700812 hwc_rect_t& displayFrame,
813 int& transform,
814 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700815 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700816 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530817 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700818 if(!isYuvBuffer(hnd)) {
819 if(extOrient & HWC_TRANSFORM_ROT_90) {
820 int dstWidth = ctx->dpyAttr[dpy].xres;
821 int dstHeight = ctx->dpyAttr[dpy].yres;;
822 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
823 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
824 if(!isPrimaryPortrait(ctx)) {
825 swap(srcWidth, srcHeight);
826 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700827 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700828 srcHeight, displayFrame);
829 // Crop - this is needed, because for sidesync, the dest fb will
830 // be in portrait orientation, so update the crop to not show the
831 // black side bands.
832 if (isOrientationPortrait(ctx)) {
833 sourceCrop = displayFrame;
834 displayFrame.left = 0;
835 displayFrame.top = 0;
836 displayFrame.right = dstWidth;
837 displayFrame.bottom = dstHeight;
838 }
839 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700840 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700841 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700842 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700843 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530844 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
845 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700846 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700847 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700848 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700849 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
850 extW = ctx->mHWCVirtual->getScalingWidth();
851 extH = ctx->mHWCVirtual->getScalingHeight();
852 }
853 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
854 __FUNCTION__, extW, extH);
855
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700856 //Calculate the ratio...
857 float wRatio = ((float)extW)/fbWidth;
858 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700859
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700860 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530861 displayFrame.left = int(wRatio*(float)displayFrame.left);
862 displayFrame.top = int(hRatio*(float)displayFrame.top);
863 displayFrame.right = int(wRatio*(float)displayFrame.right);
864 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700865 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
866 " for MDPDownscale feature [%d %d %d %d]",
867 displayFrame.left, displayFrame.top,
868 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700869 }
870 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700871 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700872 getAspectRatioPosition(ctx, dpy, extOrient,
873 displayFrame, displayFrame);
874 }
875 }
876 // If there is a external orientation set, use that
877 if(extOrient) {
878 transform = extOrient;
879 orient = static_cast<ovutils::eTransform >(extOrient);
880 }
881 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
882 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700883 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700884}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700885
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700886/* Returns the orientation which needs to be set on External for
887 * SideSync/Buffer Mirrormode
888 */
889int getMirrorModeOrientation(hwc_context_t *ctx) {
890 int extOrientation = 0;
891 int deviceOrientation = ctx->deviceOrientation;
892 if(!isPrimaryPortrait(ctx))
893 deviceOrientation = (deviceOrientation + 1) % 4;
894 if (deviceOrientation == 0)
895 extOrientation = HWC_TRANSFORM_ROT_270;
896 else if (deviceOrientation == 1)//90
897 extOrientation = 0;
898 else if (deviceOrientation == 2)//180
899 extOrientation = HWC_TRANSFORM_ROT_90;
900 else if (deviceOrientation == 3)//270
901 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
902
903 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700904}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700905
Raj kamal59fea562014-04-01 16:52:19 +0530906/* Get External State names */
907const char* getExternalDisplayState(uint32_t external_state) {
908 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
909 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
910 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
911 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
912 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
913
914 if(external_state >= EXTERNAL_MAXSTATES) {
915 return "EXTERNAL_INVALID";
916 }
917
918 return externalStates[external_state];
919}
920
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530921bool isDownscaleRequired(hwc_layer_1_t const* layer) {
922 hwc_rect_t displayFrame = layer->displayFrame;
923 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
924 int dst_w, dst_h, src_w, src_h;
925 dst_w = displayFrame.right - displayFrame.left;
926 dst_h = displayFrame.bottom - displayFrame.top;
927 src_w = sourceCrop.right - sourceCrop.left;
928 src_h = sourceCrop.bottom - sourceCrop.top;
929
930 if(((src_w > dst_w) || (src_h > dst_h)))
931 return true;
932
933 return false;
934}
935bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500936 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500937 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700938 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500939
940 dst_w = displayFrame.right - displayFrame.left;
941 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500942 src_w = sourceCrop.right - sourceCrop.left;
943 src_h = sourceCrop.bottom - sourceCrop.top;
944
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800945 if(layer->transform & HWC_TRANSFORM_ROT_90)
946 swap(src_w, src_h);
947
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800948 if(((src_w != dst_w) || (src_h != dst_h)))
949 return true;
950
951 return false;
952}
953
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700954// Checks if layer needs scaling with split
955bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
956 const int& dpy) {
957
958 int src_width_l, src_height_l;
959 int src_width_r, src_height_r;
960 int dst_width_l, dst_height_l;
961 int dst_width_r, dst_height_r;
962 int hw_w = ctx->dpyAttr[dpy].xres;
963 int hw_h = ctx->dpyAttr[dpy].yres;
964 hwc_rect_t cropL, dstL, cropR, dstR;
965 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700966 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700967 hwc_rect_t displayFrame = layer->displayFrame;
968 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700969
970 cropL = sourceCrop;
971 dstL = displayFrame;
972 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800973 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700974 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
975
976 cropR = sourceCrop;
977 dstR = displayFrame;
978 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800979 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700980 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
981
982 // Sanitize Crop to stitch
983 sanitizeSourceCrop(cropL, cropR, hnd);
984
985 // Calculate the left dst
986 dst_width_l = dstL.right - dstL.left;
987 dst_height_l = dstL.bottom - dstL.top;
988 src_width_l = cropL.right - cropL.left;
989 src_height_l = cropL.bottom - cropL.top;
990
991 // check if there is any scaling on the left
992 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
993 return true;
994
995 // Calculate the right dst
996 dst_width_r = dstR.right - dstR.left;
997 dst_height_r = dstR.bottom - dstR.top;
998 src_width_r = cropR.right - cropR.left;
999 src_height_r = cropR.bottom - cropR.top;
1000
1001 // check if there is any scaling on the right
1002 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
1003 return true;
1004
1005 return false;
1006}
1007
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301008bool isAlphaScaled(hwc_layer_1_t const* layer) {
1009 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301010 return true;
1011 }
1012 return false;
1013}
1014
1015bool isAlphaPresent(hwc_layer_1_t const* layer) {
1016 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001017 if(hnd) {
1018 int format = hnd->format;
1019 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301020 case HAL_PIXEL_FORMAT_RGBA_8888:
1021 case HAL_PIXEL_FORMAT_BGRA_8888:
1022 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -05001023 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +05301024 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -04001025 }
Naseer Ahmed018e5452012-12-03 14:46:15 -05001026 }
1027 return false;
1028}
1029
radhakrishnac3198ff2015-03-10 17:10:02 +05301030bool isAlphaPresentinFB(hwc_context_t *ctx, int dpy) {
1031 switch(ctx->dpyAttr[dpy].fbformat) {
1032 case HAL_PIXEL_FORMAT_RGBA_8888:
1033 case HAL_PIXEL_FORMAT_BGRA_8888:
1034 return true;
1035 default : return false;
1036 }
1037 return false;
1038}
1039
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001040static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
1041 hwc_rect_t& crop, hwc_rect_t& dst) {
1042 int hw_w = ctx->dpyAttr[dpy].xres;
1043 int hw_h = ctx->dpyAttr[dpy].yres;
1044 if(dst.left < 0 || dst.top < 0 ||
1045 dst.right > hw_w || dst.bottom > hw_h) {
1046 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001047 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001048 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1049 }
1050}
1051
1052static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1053 const int& dpy) {
1054 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1055 hwc_layer_1_t *layer = &list->hwLayers[i];
1056 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001057 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1058 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001059 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001060 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001061 (hwc_rect_t&)crop,
1062 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301063 layer->sourceCropf.left = (float)crop.left;
1064 layer->sourceCropf.right = (float)crop.right;
1065 layer->sourceCropf.top = (float)crop.top;
1066 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001067 }
1068}
1069
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001070void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001071 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001072 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1073 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301074 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1075 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001076 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301077 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001078 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001079 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001080 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001081 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001082 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301083 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001084 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301085 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001086 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001087 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1088 uint32_t refreshRate = 0;
1089 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001090 int s3dFormat = HAL_NO_3D;
1091 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001092
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001093 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001094 resetROI(ctx, dpy);
1095
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001096 trimList(ctx, list, dpy);
1097 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001098 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001099 hwc_layer_1_t const* layer = &list->hwLayers[i];
1100 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001101
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001102#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001103 // Window boxing feature is applicable obly for external display, So
1104 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001105 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001106 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001107 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001108 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1109 ctx->listStats[dpy].isDisplayAnimating = true;
1110 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001111 if(isSecureDisplayBuffer(hnd)) {
1112 ctx->listStats[dpy].secureUI = true;
1113 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001114#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001115 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1116 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001117 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001118
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001119 //reset yuv indices
1120 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301121 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001122
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001123 if (isSecureBuffer(hnd)) {
1124 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001125 if(not isYuvBuffer(hnd)) {
1126 // cache secureRGB layer parameters like we cache for YUV layers
1127 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1128 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1129 secureRGBCount++;
1130 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001131 }
1132
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001133 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001134 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001135 }
1136
1137 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001138 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301139 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001140 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001141
Raj Kamal389d6e32014-08-04 14:43:24 +05301142 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301143 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301144 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301145 yuv4k2kCount++;
1146 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001147
1148 // Gets set if one YUV layer is 3D
1149 if (displaySupports3D(ctx,dpy)) {
1150 s3dFormat = get3DFormat(hnd);
1151 if(s3dFormat != HAL_NO_3D)
1152 s3dLayerCount++;
1153 }
1154
Naseer Ahmed29a26812012-06-14 00:56:20 -07001155 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301156 if(layer->blending == HWC_BLENDING_PREMULT)
1157 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001158
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001159#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301160 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001161 //dyn fps: get refreshrate from metadata
1162 //Support multiple refresh rates if they are same
1163 //else set to default
1164 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1165 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1166 // Valid refreshRate in metadata and within the range
1167 uint32_t rate = roundOff(mdata->refreshrate);
1168 if((rate >= mdpHw.getMinFpsSupported() &&
1169 rate <= mdpHw.getMaxFpsSupported())) {
1170 if (!refreshRate) {
1171 refreshRate = rate;
1172 } else if(refreshRate != rate) {
1173 // multiple refreshrate requests, set to default
1174 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1175 }
1176 }
1177 }
1178 }
1179#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001180 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001181
1182 //Set the TV's 3D mode based on format if it was not forced
1183 //Only one 3D YUV layer is supported on external
1184 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1185 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1186 //XXX: Rapidly going in and out of 3D mode in some cases such
1187 // as rotation might cause flickers. The OEMs are recommended to disable
1188 // rotation on HDMI globally or in the app that plays 3D video
1189 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1190 }
1191
Ping Li9404e2a2013-04-24 16:36:03 -04001192 if(ctx->listStats[dpy].yuvCount > 0) {
1193 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1194 if (atoi(property) != 1) {
1195 property_set("hw.cabl.yuv", "1");
1196 }
1197 }
1198 } else {
1199 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1200 if (atoi(property) != 0) {
1201 property_set("hw.cabl.yuv", "0");
1202 }
1203 }
1204 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001205
1206 //The marking of video begin/end is useful on some targets where we need
1207 //to have a padding round to be able to shift pipes across mixers.
1208 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1209 ctx->mVideoTransFlag = true;
1210 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301211
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001212 if(dpy == HWC_DISPLAY_PRIMARY) {
1213 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001214 //Store the requested fresh rate
1215 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1216 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001217 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001218}
1219
Naseer Ahmed018e5452012-12-03 14:46:15 -05001220
Saurabh Shah68107422013-07-09 11:12:42 -07001221static void calc_cut(double& leftCutRatio, double& topCutRatio,
1222 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001223 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001224 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001225 }
1226 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001227 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001228 }
1229 if(orient & HAL_TRANSFORM_ROT_90) {
1230 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001231 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001232 leftCutRatio = topCutRatio;
1233 topCutRatio = rightCutRatio;
1234 rightCutRatio = bottomCutRatio;
1235 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001236 }
1237}
1238
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001239bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001240 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1241 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1242 ctx->mSecuring) {
1243 return true;
1244 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001245 if (isSecureModePolicy(ctx->mMDP.version)) {
1246 private_handle_t *hnd = (private_handle_t *)layer->handle;
1247 if(ctx->mSecureMode) {
1248 if (! isSecureBuffer(hnd)) {
1249 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1250 __FUNCTION__);
1251 return true;
1252 }
1253 } else {
1254 if (isSecureBuffer(hnd)) {
1255 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1256 __FUNCTION__);
1257 return true;
1258 }
1259 }
1260 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001261 return false;
1262}
1263
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001264bool isSecureModePolicy(int mdpVersion) {
1265 if (mdpVersion < qdutils::MDSS_V5)
1266 return true;
1267 else
1268 return false;
1269}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001270
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001271bool isRotatorSupportedFormat(private_handle_t *hnd) {
1272 // Following rotator src formats are supported by mdp driver
1273 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001274 if(hnd != NULL) {
1275 switch(hnd->format) {
1276 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001277 case HAL_PIXEL_FORMAT_RGBA_5551:
1278 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001279 case HAL_PIXEL_FORMAT_RGB_565:
1280 case HAL_PIXEL_FORMAT_RGB_888:
1281 case HAL_PIXEL_FORMAT_BGRA_8888:
1282 return true;
1283 default:
1284 return false;
1285 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001286 }
1287 return false;
1288}
1289
1290bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001291 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001292 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001293 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001294 !ctx->mMDP.version < qdutils::MDSS_V5)
1295 || isYuvBuffer(hnd)) {
1296 return true;
1297 }
1298 return false;
1299}
1300
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001301// returns true if Action safe dimensions are set and target supports Actionsafe
1302bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1303 // if external supports underscan, do nothing
1304 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001305 // Disable Action safe for 8974 due to HW limitation for downscaling
1306 // layers with overlapped region
1307 // Disable Actionsafe for non HDMI displays.
1308 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1309 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001310 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001311 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001312 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001313
1314 char value[PROPERTY_VALUE_MAX];
1315 // Read action safe properties
1316 property_get("persist.sys.actionsafe.width", value, "0");
1317 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1318 property_get("persist.sys.actionsafe.height", value, "0");
1319 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1320
1321 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1322 //No action safe ratio set, return
1323 return false;
1324 }
1325 return true;
1326}
1327
Naseer Ahmed522ce662013-03-18 20:14:05 -04001328int getBlending(int blending) {
1329 switch(blending) {
1330 case HWC_BLENDING_NONE:
1331 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1332 case HWC_BLENDING_PREMULT:
1333 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1334 case HWC_BLENDING_COVERAGE :
1335 default:
1336 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1337 }
1338}
1339
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001340//Crops source buffer against destination and FB boundaries
1341void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001342 const hwc_rect_t& scissor, int orient) {
1343
Saurabh Shah27c1d652012-08-14 19:30:28 -07001344 int& crop_l = crop.left;
1345 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001346 int& crop_r = crop.right;
1347 int& crop_b = crop.bottom;
1348 int crop_w = crop.right - crop.left;
1349 int crop_h = crop.bottom - crop.top;
1350
Saurabh Shah27c1d652012-08-14 19:30:28 -07001351 int& dst_l = dst.left;
1352 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001353 int& dst_r = dst.right;
1354 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001355 int dst_w = abs(dst.right - dst.left);
1356 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001357
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001358 const int& sci_l = scissor.left;
1359 const int& sci_t = scissor.top;
1360 const int& sci_r = scissor.right;
1361 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001362
Saurabh Shah68107422013-07-09 11:12:42 -07001363 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1364 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001365
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001366 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001367 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001368 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001369 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001370
1371 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001372 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001373 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001374 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001375
1376 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001377 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001378 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001379 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001380
1381 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001382 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001383 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001384 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001385
Saurabh Shah541b59d2012-10-11 11:08:12 -07001386 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301387 crop_l += (int)round((double)crop_w * leftCutRatio);
1388 crop_t += (int)round((double)crop_h * topCutRatio);
1389 crop_r -= (int)round((double)crop_w * rightCutRatio);
1390 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001391}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001392
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301393bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1394 const hwc_layer_1_t* layer2) {
1395 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1396 layer2->displayFrame);
1397 return isValidRect(irect);
1398}
1399
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001400bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1401{
1402 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1403 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1404}
1405
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001406bool isValidRect(const hwc_rect& rect)
1407{
1408 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301409}
1410
Ramakant Singh21cec722014-03-07 19:11:45 +05301411bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1412 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1413 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1414 return true ;
1415 return false;
1416}
1417
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001418hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1419{
1420 hwc_rect_t res;
1421
1422 if(!isValidRect(rect))
1423 return (hwc_rect_t){0, 0, 0, 0};
1424
1425 res.left = rect.left + x_off;
1426 res.top = rect.top + y_off;
1427 res.right = rect.right + x_off;
1428 res.bottom = rect.bottom + y_off;
1429
1430 return res;
1431}
1432
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001433/* computes the intersection of two rects */
1434hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1435{
1436 hwc_rect_t res;
1437
1438 if(!isValidRect(rect1) || !isValidRect(rect2)){
1439 return (hwc_rect_t){0, 0, 0, 0};
1440 }
1441
1442
1443 res.left = max(rect1.left, rect2.left);
1444 res.top = max(rect1.top, rect2.top);
1445 res.right = min(rect1.right, rect2.right);
1446 res.bottom = min(rect1.bottom, rect2.bottom);
1447
1448 if(!isValidRect(res))
1449 return (hwc_rect_t){0, 0, 0, 0};
1450
1451 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301452}
1453
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001454/* computes the union of two rects */
1455hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1456{
1457 hwc_rect_t res;
1458
1459 if(!isValidRect(rect1)){
1460 return rect2;
1461 }
1462
1463 if(!isValidRect(rect2)){
1464 return rect1;
1465 }
1466
1467 res.left = min(rect1.left, rect2.left);
1468 res.top = min(rect1.top, rect2.top);
1469 res.right = max(rect1.right, rect2.right);
1470 res.bottom = max(rect1.bottom, rect2.bottom);
1471
1472 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301473}
1474
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001475/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1476 * a single rect */
1477hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301478
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001479 hwc_rect_t res = rect1;
1480
1481 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1482 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1483 res.top = rect2.bottom;
1484 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1485 res.bottom = rect2.top;
1486 }
1487 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1488 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1489 res.left = rect2.right;
1490 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1491 res.right = rect2.left;
1492 }
1493 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301494}
1495
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001496void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301497 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301498 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301499 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001500 //If it is opaque see if we can substract this region from below
1501 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301502 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1503 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301504 int j= i-1;
1505 hwc_rect_t& topframe =
1506 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1507 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301508 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001509 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1510 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001511 hwc_rect_t bottomCrop =
1512 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001513 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1514 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001515
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001516 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1517 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001518 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001519 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001520 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001521 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001522 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001523 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301524 layer->sourceCropf.left =(float)bottomCrop.left;
1525 layer->sourceCropf.top = (float)bottomCrop.top;
1526 layer->sourceCropf.right = (float)bottomCrop.right;
1527 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001528#ifdef QCOM_BSP
1529 //Update layer dirtyRect
1530 layer->dirtyRect = getIntersection(bottomCrop,
1531 layer->dirtyRect);
1532#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001533 }
1534 }
1535 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301536 }
1537 }
1538 i--;
1539 }
1540}
1541
Naseer Ahmed64b81212013-02-14 10:29:47 -05001542void getNonWormholeRegion(hwc_display_contents_1_t* list,
1543 hwc_rect_t& nwr)
1544{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301545 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001546 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1547 //Initiliaze nwr to first frame
1548 nwr.left = list->hwLayers[0].displayFrame.left;
1549 nwr.top = list->hwLayers[0].displayFrame.top;
1550 nwr.right = list->hwLayers[0].displayFrame.right;
1551 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1552
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301553 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001554 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001555 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001556 }
1557
1558 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001559 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001560}
1561
Saurabh Shah747af1e2013-02-26 10:25:12 -08001562void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001563 if(LIKELY(list)) {
1564 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1565 //Close the acquireFenceFds
1566 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1567 if(list->hwLayers[i].acquireFenceFd >= 0) {
1568 close(list->hwLayers[i].acquireFenceFd);
1569 list->hwLayers[i].acquireFenceFd = -1;
1570 }
1571 }
1572 //Writeback
1573 if(list->outbufAcquireFenceFd >= 0) {
1574 close(list->outbufAcquireFenceFd);
1575 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001576 }
1577 }
1578}
1579
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001580int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001581 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001582 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001583 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001584 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001585 int count = 0;
1586 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001587 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001588 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001589 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001590
1591 struct mdp_buf_sync data;
1592 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001593 data.acq_fen_fd = acquireFd;
1594 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001595 data.retire_fen_fd = &retireFd;
1596 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001597
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001598 char property[PROPERTY_VALUE_MAX];
1599 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1600 if(atoi(property) == 0)
1601 swapzero = true;
1602 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001603
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001604 bool isExtAnimating = false;
1605 if(dpy)
1606 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001607
Saurabh Shah23a813c2013-03-20 16:58:12 -07001608 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001609 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001610 int rotFd = ctx->mRotMgr->getRotDevFd();
1611 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001612 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1613 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1614 if((currRot == NULL) || (currLayer == NULL)) {
1615 continue;
1616 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001617 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001618 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001619 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001620 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001621 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001622 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001623 if(currLayer->acquireFenceFd >= 0) {
1624 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1625 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001626 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301627 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301628 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1629
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001630 if(ret < 0) {
1631 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1632 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001633 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001634 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001635 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001636 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001637 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001638 dup(rotReleaseFd);
1639 //A buffer is free to be used by producer as soon as its copied to
1640 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001641 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001642 rotReleaseFd;
1643 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001644 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001645
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301646 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001647 if(list->outbufAcquireFenceFd >= 0) {
1648 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301649 if(LIKELY(!swapzero) )
1650 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001651 }
1652
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001653 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301654 if(((isAbcInUse(ctx)== true ) ||
1655 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001656 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301657 if(LIKELY(!swapzero) ) {
1658 // if ABC is enabled for more than one layer.
1659 // renderBufIndexforABC will work as FB.Hence
1660 // set the acquireFD from fd - which is coming from copybit
1661 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1662 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1663 acquireFd[count++] = fd;
1664 else
1665 continue;
1666 } else
1667 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1668 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001669 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001670 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301671 if(LIKELY(!swapzero) ) {
1672 if(fd >= 0) {
1673 //set the acquireFD from fd - which is coming from c2d
1674 acquireFd[count++] = fd;
1675 // Buffer sync IOCTL should be async when using c2d fence is
1676 // used
1677 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1678 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1679 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1680 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001681 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001682 }
1683
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001684 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001685 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301686 if(LIKELY(!swapzero) )
1687 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001688 }
1689
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001690 data.acq_fen_fd_cnt = count;
1691 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001692
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001693 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001694 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001695 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001696 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001697
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001698 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001699 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1700 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301701 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001702 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1703 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001704 close(releaseFd);
1705 releaseFd = -1;
1706 close(retireFd);
1707 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001708 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001709
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001710 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001711 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001712#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001713 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001714#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001715 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001716 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001717 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001718 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001719 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001720 // Release all the app layer fds immediately,
1721 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001722 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001723 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001724#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001725 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301726 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301727
1728 // if ABC is enabled for more than one layer
1729 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1730 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1731 list->hwLayers[i].releaseFenceFd = dup(fd);
1732 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1733 (isAbcInUse(ctx) == false)){
1734 //For Blit, the app layers should be released when the Blit
1735 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301736 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001737 } else
1738#endif
1739 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301740 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1741 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001742 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001743 }
1744 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001745
1746 if(fd >= 0) {
1747 close(fd);
1748 fd = -1;
1749 }
1750
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001751 if (ctx->mCopyBit[dpy]) {
1752 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001753 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1754 else
1755 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1756 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001757
Saurabh Shah23a813c2013-03-20 16:58:12 -07001758 //Signals when MDP finishes reading rotator buffers.
1759 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001760 close(releaseFd);
1761 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001762
Arun Kumar K.R51835182013-11-19 11:20:28 -08001763 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001764 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001765 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001766 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001767 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001768 return ret;
1769}
1770
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001771void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001772 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001773 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001774 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001775 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001776
1777 if(layer->blending == HWC_BLENDING_PREMULT) {
1778 ovutils::setMdpFlags(mdpFlags,
1779 ovutils::OV_MDP_BLEND_FG_PREMULT);
1780 }
1781
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001782 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1783 metadata->interlaced) {
1784 ovutils::setMdpFlags(mdpFlags,
1785 ovutils::OV_MDP_DEINTERLACE);
1786 }
1787
1788 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1789 if(isSecureBuffer(hnd)) {
1790 ovutils::setMdpFlags(mdpFlags,
1791 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301792 ovutils::setMdpFlags(mdpFlags,
1793 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1794 }
1795
1796 if(isProtectedBuffer(hnd)) {
1797 ovutils::setMdpFlags(mdpFlags,
1798 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001799 }
1800
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001801 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001802 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001803 ovutils::setMdpFlags(mdpFlags,
1804 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1805 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001806
1807 //Pre-rotation will be used using rotator.
1808 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1809 ovutils::setMdpFlags(mdpFlags,
1810 ovutils::OV_MDP_SOURCE_ROTATED_90);
1811 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001812 //No 90 component and no rot-downscale then flips done by MDP
1813 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001814 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1815 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001816 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1817 }
1818
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001819 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001820 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1821 }
1822 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001823
1824 if(metadata &&
1825 ((metadata->operation & PP_PARAM_HSIC)
1826 || (metadata->operation & PP_PARAM_IGC)
1827 || (metadata->operation & PP_PARAM_SHARP2))) {
1828 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1829 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001830}
1831
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301832int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001833 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001834 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001835
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301836 // Fix alignments for TILED format
1837 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1838 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1839 whf.w = utils::alignup(whf.w, 64);
1840 whf.h = utils::alignup(whf.h, 32);
1841 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001842 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001843
1844 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1845 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001846 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1847 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001848 rot->setCrop(rotCrop);
1849 }
1850
Saurabh Shahacf10202013-02-26 10:15:15 -08001851 rot->setFlags(mdpFlags);
1852 rot->setTransform(orient);
1853 rot->setDownscale(downscale);
1854 if(!rot->commit()) return -1;
1855 return 0;
1856}
1857
Saurabh Shahe2474082013-05-15 16:32:13 -07001858int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001859 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001860 const hwc_rect_t& pos, const MetaData_t *metadata,
1861 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001862 ov->setSource(parg, dest);
1863 ov->setTransform(orient, dest);
1864
1865 int crop_w = crop.right - crop.left;
1866 int crop_h = crop.bottom - crop.top;
1867 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1868 ov->setCrop(dcrop, dest);
1869
1870 int posW = pos.right - pos.left;
1871 int posH = pos.bottom - pos.top;
1872 Dim position(pos.left, pos.top, posW, posH);
1873 ov->setPosition(position, dest);
1874
Saurabh Shah5daeee52013-01-23 16:52:26 +08001875 if (metadata)
1876 ov->setVisualParams(*metadata, dest);
1877
Saurabh Shahacf10202013-02-26 10:15:15 -08001878 if (!ov->commit(dest)) {
1879 return -1;
1880 }
1881 return 0;
1882}
1883
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001884int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1885 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001886 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001887
1888 hwc_rect_t dst = layer->displayFrame;
1889 trimLayer(ctx, dpy, 0, dst, dst);
1890
1891 int w = ctx->dpyAttr[dpy].xres;
1892 int h = ctx->dpyAttr[dpy].yres;
1893 int dst_w = dst.right - dst.left;
1894 int dst_h = dst.bottom - dst.top;
1895 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001896 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001897
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001898 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001899 if (layer->blending == HWC_BLENDING_PREMULT)
1900 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1901
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001902 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001903 layer->planeAlpha,
1904 (ovutils::eBlending) getBlending(layer->blending));
1905
1906 // Configure MDP pipe for Color layer
1907 Dim pos(dst.left, dst.top, dst_w, dst_h);
1908 ctx->mOverlay->setSource(parg, dest);
1909 ctx->mOverlay->setColor(color, dest);
1910 ctx->mOverlay->setTransform(0, dest);
1911 ctx->mOverlay->setCrop(pos, dest);
1912 ctx->mOverlay->setPosition(pos, dest);
1913
1914 if (!ctx->mOverlay->commit(dest)) {
1915 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1916 return -1;
1917 }
1918 return 0;
1919}
1920
Saurabh Shahe2474082013-05-15 16:32:13 -07001921void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001922 hwc_rect_t& crop, Rotator *rot) {
1923 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001924 crop.right - crop.left,
1925 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001926 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1927 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001928 //B-family rotator internally could modify destination dimensions if
1929 //downscaling is supported
1930 whf = rot->getDstWhf();
1931 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001932 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001933 //A-family rotator rotates entire buffer irrespective of crop, forcing
1934 //us to recompute the crop based on transform
1935 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1936 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001937 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001938
1939 crop.left = transformedCrop.x;
1940 crop.top = transformedCrop.y;
1941 crop.right = transformedCrop.x + transformedCrop.w;
1942 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001943}
1944
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001945int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1946 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1947 return 0;
1948 }
1949
1950 int downscale = 0;
1951 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1952 hwc_rect_t dst = layer->displayFrame;
1953 private_handle_t *hnd = (private_handle_t *)layer->handle;
1954
1955 if(not hnd) {
1956 return 0;
1957 }
1958
1959 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1960 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1961 && metadata->interlaced;
1962 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001963 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001964
1965 if(isYuvBuffer(hnd)) {
1966 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1967 ctx->mMDP.version < qdutils::MDSS_V5) {
1968 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1969 crop.bottom - crop.top, dst.right - dst.left,
1970 dst.bottom - dst.top, format, isInterlaced);
1971 } else {
1972 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1973 crop.bottom - crop.top);
1974 Dim pos(dst.left, dst.top, dst.right - dst.left,
1975 dst.bottom - dst.top);
1976 if(transform & HAL_TRANSFORM_ROT_90) {
1977 swap(adjCrop.w, adjCrop.h);
1978 }
1979 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1980 pos.h, format, isInterlaced);
1981 }
1982 }
1983 return downscale;
1984}
1985
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001986bool isZoomModeEnabled(hwc_rect_t crop) {
1987 // This does not work for zooming in top left corner of the image
1988 return(crop.top > 0 || crop.left > 0);
1989}
1990
1991void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1992 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1993 crop.left, crop.top, crop.right, crop.bottom);
1994 if(isZoomModeEnabled(crop)) {
1995 Dim srcCrop(crop.left, crop.top,
1996 crop.right - crop.left,
1997 crop.bottom - crop.top);
1998 int extW = ctx->dpyAttr[dpy].xres;
1999 int extH = ctx->dpyAttr[dpy].yres;
2000 //Crop the original video in order to fit external display aspect ratio
2001 if(srcCrop.w * extH < extW * srcCrop.h) {
2002 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
2003 crop.top += offset;
2004 crop.bottom -= offset;
2005 } else {
2006 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
2007 crop.left += offset;
2008 crop.right -= offset;
2009 }
2010 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2011 " source crop [%d %d %d %d]", extW, extH, dpy,
2012 crop.left, crop.top, crop.right, crop.bottom);
2013 }
2014}
2015
2016void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
2017 hwc_rect_t& dst, int dpy) {
2018 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
2019 dst.left, dst.top, dst.right, dst.bottom);
2020 Dim srcCrop(crop.left, crop.top,
2021 crop.right - crop.left,
2022 crop.bottom - crop.top);
2023 int extW = ctx->dpyAttr[dpy].xres;
2024 int extH = ctx->dpyAttr[dpy].yres;
2025 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07002026 // when zoom in mode is enabled or the ratio between video aspect ratio
2027 // and external display aspect ratio is below the minimum tolerance level
2028 // and above maximum tolerance level
2029 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
2030 float extDisplayAspectRatio = ((float)extW / (float)extH);
2031 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
2032 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
2033 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002034 dst.left = 0;
2035 dst.top = 0;
2036 dst.right = extW;
2037 dst.bottom = extH;
2038 }
2039 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2040 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
2041 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
2042 crop.left, crop.top, crop.right, crop.bottom);
2043}
2044
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002045void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002046 hwc_rect_t& dst, int dpy) {
2047 updateCropAIVVideoMode(ctx, crop, dpy);
2048 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2049}
2050
Saurabh Shah88e4d272013-09-03 13:31:29 -07002051int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002052 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002053 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002054
2055 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002056
Saurabh Shahacf10202013-02-26 10:15:15 -08002057 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002058 if (layer->flags & HWC_COLOR_FILL) {
2059 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002060 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002061 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002062 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2063 return -1;
2064 }
2065
Saurabh Shah5daeee52013-01-23 16:52:26 +08002066 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2067
Saurabh Shah62e1d732013-09-17 10:44:05 -07002068 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002069 hwc_rect_t dst = layer->displayFrame;
2070 int transform = layer->transform;
2071 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002072 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002073 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302074 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002075
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002076 // Handle R/B swap
2077 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2078 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2079 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2080 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2081 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2082 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002083 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002084 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2085 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002086 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002087 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002088 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002089 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002090
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002091 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002092 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002093 *rot = ctx->mRotMgr->getNext();
2094 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002095 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002096 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2097 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002098 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002099 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2100 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002101 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002102 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002103 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002104 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002105 }
2106
Saurabh Shah76fd6552013-03-14 14:45:38 -07002107 //For the mdp, since either we are pre-rotating or MDP does flips
2108 orient = OVERLAY_TRANSFORM_0;
2109 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002110 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002111 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2112 (ovutils::eBlending) getBlending(layer->blending));
2113
Saurabh Shah5daeee52013-01-23 16:52:26 +08002114 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002115 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2116 return -1;
2117 }
2118 return 0;
2119}
2120
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002121//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002122void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002123 private_handle_t *hnd) {
2124 if(cropL.right - cropL.left) {
2125 if(isYuvBuffer(hnd)) {
2126 //Always safe to even down left
2127 ovutils::even_floor(cropL.left);
2128 //If right is even, automatically width is even, since left is
2129 //already even
2130 ovutils::even_floor(cropL.right);
2131 }
2132 //Make sure there are no gaps between left and right splits if the layer
2133 //is spread across BOTH halves
2134 if(cropR.right - cropR.left) {
2135 cropR.left = cropL.right;
2136 }
2137 }
2138
2139 if(cropR.right - cropR.left) {
2140 if(isYuvBuffer(hnd)) {
2141 //Always safe to even down left
2142 ovutils::even_floor(cropR.left);
2143 //If right is even, automatically width is even, since left is
2144 //already even
2145 ovutils::even_floor(cropR.right);
2146 }
2147 }
2148}
2149
Saurabh Shah88e4d272013-09-03 13:31:29 -07002150int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002151 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002152 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002153 Rotator **rot) {
2154 private_handle_t *hnd = (private_handle_t *)layer->handle;
2155 if(!hnd) {
2156 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2157 return -1;
2158 }
2159
Saurabh Shah5daeee52013-01-23 16:52:26 +08002160 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2161
Saurabh Shahacf10202013-02-26 10:15:15 -08002162 int hw_w = ctx->dpyAttr[dpy].xres;
2163 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002164 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002165 hwc_rect_t dst = layer->displayFrame;
2166 int transform = layer->transform;
2167 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002168 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002169 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302170 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002171
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002172 // Handle R/B swap
2173 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2174 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2175 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2176 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2177 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2178 }
2179
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002180 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002181 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2182 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002183 }
2184
2185 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002186 ActionSafe, and extorientation features. */
2187 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002188 int downscale = getRotDownscale(ctx, layer);
2189 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002190
2191 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2192 //Enable overfetch
2193 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2194 }
2195
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002196 //Will do something only if feature enabled and conditions suitable
2197 //hollow call otherwise
2198 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2199 overlay::Writeback *wb = overlay::Writeback::getInstance();
2200 whf.format = wb->getOutputFormat();
2201 }
2202
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002203 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002204 (*rot) = ctx->mRotMgr->getNext();
2205 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002206 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002207 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002208 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2209 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002210 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002211 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002212 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002213 rotFlags |= ROT_PREROTATED;
2214 }
2215
2216 eMdpFlags mdpFlagsR = mdpFlagsL;
2217 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2218
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002219 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2220 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002221
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002222 const int lSplit = getLeftSplit(ctx, dpy);
2223
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002224 // Calculate Left rects
2225 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002226 tmp_cropL = crop;
2227 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002228 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002229 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002230 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2231 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002232
2233 // Calculate Right rects
2234 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002235 tmp_cropR = crop;
2236 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002237 hwc_rect_t scissor = {lSplit, 0, hw_w, 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_cropR, tmp_dstR, scissor, 0);
2240 }
2241
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002242 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2243
Saurabh Shah94d62362013-07-02 10:58:48 -07002244 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002245 //Not needed if the layer is confined to one half of the screen.
2246 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002247 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2248 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002249 hwc_rect_t new_cropR;
2250 new_cropR.left = tmp_cropL.left;
2251 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2252
2253 hwc_rect_t new_cropL;
2254 new_cropL.left = new_cropR.right;
2255 new_cropL.right = tmp_cropR.right;
2256
2257 tmp_cropL.left = new_cropL.left;
2258 tmp_cropL.right = new_cropL.right;
2259
2260 tmp_cropR.left = new_cropR.left;
2261 tmp_cropR.right = new_cropR.right;
2262
2263 }
2264
Saurabh Shah76fd6552013-03-14 14:45:38 -07002265 //For the mdp, since either we are pre-rotating or MDP does flips
2266 orient = OVERLAY_TRANSFORM_0;
2267 transform = 0;
2268
Saurabh Shahacf10202013-02-26 10:15:15 -08002269 //configure left mixer
2270 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002271 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002272 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2273 (ovutils::eBlending) getBlending(layer->blending));
2274
Saurabh Shahacf10202013-02-26 10:15:15 -08002275 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002276 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002277 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2278 return -1;
2279 }
2280 }
2281
2282 //configure right mixer
2283 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002284 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002285 static_cast<eRotFlags>(rotFlags),
2286 layer->planeAlpha,
2287 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002288 tmp_dstR.right = tmp_dstR.right - lSplit;
2289 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002290 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002291 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002292 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2293 return -1;
2294 }
2295 }
2296
2297 return 0;
2298}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002299
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002300int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2301 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2302 const eDest& lDest, const eDest& rDest,
2303 Rotator **rot) {
2304 private_handle_t *hnd = (private_handle_t *)layer->handle;
2305 if(!hnd) {
2306 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2307 return -1;
2308 }
2309 //Both pipes are configured to the same mixer
2310 eZorder lz = z;
2311 eZorder rz = (eZorder)(z + 1);
2312
2313 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2314
2315 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2316 hwc_rect_t dst = layer->displayFrame;
2317 int transform = layer->transform;
2318 eTransform orient = static_cast<eTransform>(transform);
2319 int rotFlags = ROT_FLAGS_NONE;
2320 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2321 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2322
2323 int downscale = getRotDownscale(ctx, layer);
2324 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2325
2326 //XXX: Check if rotation is supported and valid for 3D
2327 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2328 (*rot) = ctx->mRotMgr->getNext();
2329 if((*rot) == NULL) return -1;
2330 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2331 //Configure rotator for pre-rotation
2332 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2333 ALOGE("%s: configRotator failed!", __FUNCTION__);
2334 return -1;
2335 }
2336 updateSource(orient, whf, crop, *rot);
2337 rotFlags |= ROT_PREROTATED;
2338 }
2339
2340 eMdpFlags mdpFlagsR = mdpFlagsL;
2341
2342 hwc_rect_t cropL = crop, dstL = dst;
2343 hwc_rect_t cropR = crop, dstR = dst;
2344 int hw_w = ctx->dpyAttr[dpy].xres;
2345 int hw_h = ctx->dpyAttr[dpy].yres;
2346
2347 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2348 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2349 // Calculate Left rects
2350 // XXX: This assumes crop.right/2 is the center point of the video
2351 cropL.right = crop.right/2;
2352 dstL.left = dst.left/2;
2353 dstL.right = dst.right/2;
2354
2355 // Calculate Right rects
2356 cropR.left = crop.right/2;
2357 dstR.left = hw_w/2 + dst.left/2;
2358 dstR.right = hw_w/2 + dst.right/2;
2359 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2360 // Calculate Left rects
2361 cropL.bottom = crop.bottom/2;
2362 dstL.top = dst.top/2;
2363 dstL.bottom = dst.bottom/2;
2364
2365 // Calculate Right rects
2366 cropR.top = crop.bottom/2;
2367 dstR.top = hw_h/2 + dst.top/2;
2368 dstR.bottom = hw_h/2 + dst.bottom/2;
2369 } else {
2370 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2371 return -1;
2372 }
2373
2374 //For the mdp, since either we are pre-rotating or MDP does flips
2375 orient = OVERLAY_TRANSFORM_0;
2376 transform = 0;
2377
2378 //configure left pipe
2379 if(lDest != OV_INVALID) {
2380 PipeArgs pargL(mdpFlagsL, whf, lz,
2381 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2382 (ovutils::eBlending) getBlending(layer->blending));
2383
2384 if(configMdp(ctx->mOverlay, pargL, orient,
2385 cropL, dstL, metadata, lDest) < 0) {
2386 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2387 return -1;
2388 }
2389 }
2390
2391 //configure right pipe
2392 if(rDest != OV_INVALID) {
2393 PipeArgs pargR(mdpFlagsR, whf, rz,
2394 static_cast<eRotFlags>(rotFlags),
2395 layer->planeAlpha,
2396 (ovutils::eBlending) getBlending(layer->blending));
2397 if(configMdp(ctx->mOverlay, pargR, orient,
2398 cropR, dstR, metadata, rDest) < 0) {
2399 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2400 return -1;
2401 }
2402 }
2403
2404 return 0;
2405}
2406
radhakrishnac9a67412013-09-25 17:40:42 +05302407int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2408 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002409 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302410 Rotator **rot) {
2411 private_handle_t *hnd = (private_handle_t *)layer->handle;
2412 if(!hnd) {
2413 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2414 return -1;
2415 }
2416
2417 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2418
radhakrishnac9a67412013-09-25 17:40:42 +05302419 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2420 hwc_rect_t dst = layer->displayFrame;
2421 int transform = layer->transform;
2422 eTransform orient = static_cast<eTransform>(transform);
2423 const int downscale = 0;
2424 int rotFlags = ROT_FLAGS_NONE;
2425 //Splitting only YUV layer on primary panel needs different zorders
2426 //for both layers as both the layers are configured to single mixer
2427 eZorder lz = z;
2428 eZorder rz = (eZorder)(z + 1);
2429
2430 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302431 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302432
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002433 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002434 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2435 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002436 }
2437
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002438 /* Calculate the external display position based on MDP downscale,
2439 ActionSafe, and extorientation features. */
2440 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2441
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002442 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302443 trimLayer(ctx, dpy, transform, crop, dst);
2444
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002445 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302446 (*rot) = ctx->mRotMgr->getNext();
2447 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002448 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302449 //Configure rotator for pre-rotation
2450 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2451 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302452 return -1;
2453 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002454 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302455 rotFlags |= ROT_PREROTATED;
2456 }
2457
2458 eMdpFlags mdpFlagsR = mdpFlagsL;
2459 int lSplit = dst.left + (dst.right - dst.left)/2;
2460
2461 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2462 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2463
2464 if(lDest != OV_INVALID) {
2465 tmp_cropL = crop;
2466 tmp_dstL = dst;
2467 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2468 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2469 }
2470 if(rDest != OV_INVALID) {
2471 tmp_cropR = crop;
2472 tmp_dstR = dst;
2473 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2474 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2475 }
2476
2477 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2478
2479 //When buffer is H-flipped, contents of mixer config also needs to swapped
2480 //Not needed if the layer is confined to one half of the screen.
2481 //If rotator has been used then it has also done the flips, so ignore them.
2482 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2483 && rDest != OV_INVALID && (*rot) == NULL) {
2484 hwc_rect_t new_cropR;
2485 new_cropR.left = tmp_cropL.left;
2486 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2487
2488 hwc_rect_t new_cropL;
2489 new_cropL.left = new_cropR.right;
2490 new_cropL.right = tmp_cropR.right;
2491
2492 tmp_cropL.left = new_cropL.left;
2493 tmp_cropL.right = new_cropL.right;
2494
2495 tmp_cropR.left = new_cropR.left;
2496 tmp_cropR.right = new_cropR.right;
2497
2498 }
2499
2500 //For the mdp, since either we are pre-rotating or MDP does flips
2501 orient = OVERLAY_TRANSFORM_0;
2502 transform = 0;
2503
2504 //configure left half
2505 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002506 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302507 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2508 (ovutils::eBlending) getBlending(layer->blending));
2509
2510 if(configMdp(ctx->mOverlay, pargL, orient,
2511 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2512 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2513 return -1;
2514 }
2515 }
2516
2517 //configure right half
2518 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002519 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302520 static_cast<eRotFlags>(rotFlags),
2521 layer->planeAlpha,
2522 (ovutils::eBlending) getBlending(layer->blending));
2523 if(configMdp(ctx->mOverlay, pargR, orient,
2524 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2525 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2526 return -1;
2527 }
2528 }
2529
2530 return 0;
2531}
2532
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002533bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302534 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002535 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002536 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302537 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302538 * in LINE and BLOCK modes for writeback panels.
2539 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002540 if(dpy == HWC_DISPLAY_PRIMARY)
2541 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002542 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302543 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2544 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002545 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002546 return true;
2547}
2548
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002549int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2550 //Default even split for all displays with high res
2551 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2552 if(dpy == HWC_DISPLAY_PRIMARY &&
2553 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2554 //Override if split published by driver for primary
2555 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2556 }
2557 return lSplit;
2558}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002559
Saurabh Shah88e4d272013-09-03 13:31:29 -07002560bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302561 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002562 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002563 return true;
2564 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302565 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002566 return true;
2567 }
2568 return false;
2569}
2570
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002571//clear prev layer prop flags and realloc for current frame
2572void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2573 if(ctx->layerProp[dpy]) {
2574 delete[] ctx->layerProp[dpy];
2575 ctx->layerProp[dpy] = NULL;
2576 }
2577 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2578}
2579
Ramakant Singh0def28c2014-03-28 20:43:13 +05302580bool isAbcInUse(hwc_context_t *ctx){
2581 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2582}
2583
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002584void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2585 if (ohnd != NULL && ohnd->base) {
2586 char dumpFilename[PATH_MAX];
2587 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002588 int width = getWidth(ohnd);
2589 int height = getHeight(ohnd);
2590 int format = ohnd->format;
2591 //dummy aligned w & h.
2592 int alW = 0, alH = 0;
2593 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002594 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2595 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002596 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2597 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002598 FILE* fp = fopen(dumpFilename, "w+");
2599 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002600 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002601 fclose(fp);
2602 }
2603 ALOGD("Buffer[%s] Dump to %s: %s",
2604 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2605 }
2606}
2607
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002608bool isGLESComp(hwc_context_t *ctx,
2609 hwc_display_contents_1_t* list) {
2610 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2611 for(int index = 0; index < numAppLayers; index++) {
2612 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2613 if(layer->compositionType == HWC_FRAMEBUFFER)
2614 return true;
2615 }
2616 return false;
2617}
2618
2619void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2620 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002621 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002622 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002623
2624#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002625 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2626 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2627 hint to default if the previous composition is GPU or current GPU
2628 composition is due to idle fallback */
2629 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2630 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2631 if(!gpuHint->mEGLDisplay) {
2632 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2633 return;
2634 }
2635 gpuHint->mEGLContext = eglGetCurrentContext();
2636 if(!gpuHint->mEGLContext) {
2637 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2638 return;
2639 }
2640 }
2641 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002642 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2643 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002644 EGLint attr_list[] = {EGL_GPU_HINT_1,
2645 EGL_GPU_LEVEL_3,
2646 EGL_NONE };
2647 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2648 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2649 gpuHint->mEGLContext, attr_list)) {
2650 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2651 } else {
2652 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002653 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002654 }
2655 } else {
2656 EGLint attr_list[] = {EGL_GPU_HINT_1,
2657 EGL_GPU_LEVEL_0,
2658 EGL_NONE };
2659 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2660 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2661 gpuHint->mEGLContext, attr_list)) {
2662 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2663 } else {
2664 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2665 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002666 if(MDPComp::isIdleFallback()) {
2667 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2668 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002669 }
2670 } else {
2671 /* set the GPU hint flag to default for MDP composition */
2672 EGLint attr_list[] = {EGL_GPU_HINT_1,
2673 EGL_GPU_LEVEL_0,
2674 EGL_NONE };
2675 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2676 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2677 gpuHint->mEGLContext, attr_list)) {
2678 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2679 } else {
2680 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2681 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002682 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002683 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002684#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002685}
2686
Sushil Chauhandefd3522014-05-13 18:17:12 -07002687bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2688 // To be peripheral, 3 boundaries should match.
2689 uint8_t eqBounds = 0;
2690 if (rect1.left == rect2.left)
2691 eqBounds++;
2692 if (rect1.top == rect2.top)
2693 eqBounds++;
2694 if (rect1.right == rect2.right)
2695 eqBounds++;
2696 if (rect1.bottom == rect2.bottom)
2697 eqBounds++;
2698 return (eqBounds == 3);
2699}
2700
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302701void processBootAnimCompleted(hwc_context_t *ctx) {
2702 char value[PROPERTY_VALUE_MAX];
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302703 int ret = -1;
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302704 int (*applyMode)(int) = NULL;
2705 void *modeHandle = NULL;
2706
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302707 // Applying default mode after bootanimation is finished
2708 property_get("init.svc.bootanim", value, "running");
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302709
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302710 if (!strncmp(value,"stopped",strlen("stopped"))) {
2711 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2712 if (modeHandle) {
2713 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2714 if (applyMode) {
2715 ret = applyMode(HWC_DISPLAY_PRIMARY);
2716 if (ret)
2717 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2718 } else {
2719 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2720 }
2721 dlclose(modeHandle);
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302722 } else {
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302723 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302724 }
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302725
Nitesh Gupta538e0f72015-03-25 13:22:35 +05302726 ctx->mBootAnimCompleted = true;
2727 }
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302728}
2729
Saurabh Shahcd018352014-11-11 13:54:19 -08002730void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2731 const private_handle_t *hnd,
2732 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002733 const int& transform,const int& downscale,
2734 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002735 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302736 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002737 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002738 return;
2739 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002740 //Disabled at runtime
2741 if(not ctx->mBWCEnabled) return;
2742 //BWC not supported with rot-downscale
2743 if(downscale) return;
2744 //Not enabled for secondary displays
2745 if(dpy) return;
2746 //Not enabled for non-video buffers
2747 if(not isYuvBuffer(hnd)) return;
2748
Saurabh Shahb6810df2014-06-17 16:00:22 -07002749 int src_w = crop.right - crop.left;
2750 int src_h = crop.bottom - crop.top;
2751 int dst_w = dst.right - dst.left;
2752 int dst_h = dst.bottom - dst.top;
2753 if(transform & HAL_TRANSFORM_ROT_90) {
2754 swap(src_w, src_h);
2755 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002756 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002757 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002758 return;
2759 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002760 //Decimation necessary, cannot use BWC. H/W requirement.
2761 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002762 uint8_t horzDeci = 0;
2763 uint8_t vertDeci = 0;
2764 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2765 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002766 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002767 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002768
2769 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2770}
2771
Saurabh Shah23a813c2013-03-20 16:58:12 -07002772void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302773 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002774 mLayer[mCount] = layer;
2775 mRot[mCount] = rot;
2776 mCount++;
2777}
2778
2779void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302780 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002781 mLayer[i] = 0;
2782 mRot[i] = 0;
2783 }
2784 mCount = 0;
2785}
2786
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002787void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002788 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002789 reset();
2790}
2791
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302792bool LayerRotMap::isRotCached(uint32_t index) const {
2793 overlay::Rotator* rot = getRot(index);
2794 hwc_layer_1_t* layer = getLayer(index);
2795
2796 if(rot and layer and layer->handle) {
2797 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2798 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2799 }
2800 return false;
2801}
2802
Saurabh Shah23a813c2013-03-20 16:58:12 -07002803void LayerRotMap::setReleaseFd(const int& fence) {
2804 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302805 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2806 /* Ensure that none of the above (Rotator-instance,
2807 * layer and layer-handle) are NULL*/
2808 if(isRotCached(i))
2809 mRot[i]->setPrevBufReleaseFd(dup(fence));
2810 else
2811 mRot[i]->setCurrBufReleaseFd(dup(fence));
2812 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002813 }
2814}
2815
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002816hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2817 int lRoiWidth = 0, rRoiWidth = 0;
2818 int half_frame_width = fullFrame.right/2;
2819
2820 hwc_rect lFrame = fullFrame;
2821 hwc_rect rFrame = fullFrame;
2822 lFrame.right = (lFrame.right - lFrame.left)/2;
2823 rFrame.left = lFrame.right;
2824
2825 hwc_rect lRoi = getIntersection(roi, lFrame);
2826 hwc_rect rRoi = getIntersection(roi, rFrame);
2827
2828 lRoiWidth = lRoi.right - lRoi.left;
2829 rRoiWidth = rRoi.right - rRoi.left;
2830
2831 if(lRoiWidth && rRoiWidth) {
2832 if(lRoiWidth < rRoiWidth)
2833 roi.left = half_frame_width - rRoiWidth;
2834 else
2835 roi.right = half_frame_width + lRoiWidth;
2836 }
2837 return roi;
2838}
2839
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002840void resetROI(hwc_context_t *ctx, const int dpy) {
2841 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2842 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002843
2844 /* When source split is enabled, both the panels are calibrated
2845 * in a single coordinate system. So only one ROI is generated
2846 * for the whole panel extending equally from the midpoint and
2847 * populated for the left side. */
2848 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2849 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002850 const int lSplit = getLeftSplit(ctx, dpy);
2851 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2852 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2853 } else {
2854 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2855 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2856 }
2857}
2858
2859hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002860{
2861 if(!isValidRect(roi))
2862 return roi;
2863
2864 struct hwc_rect t_roi = roi;
2865
2866 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2867 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2868 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2869 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2870 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002871 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002872
2873 /* Align to minimum width recommended by the panel */
2874 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2875 if((t_roi.left + MIN_WIDTH) > boundary.right)
2876 t_roi.left = t_roi.right - MIN_WIDTH;
2877 else
2878 t_roi.right = t_roi.left + MIN_WIDTH;
2879 }
2880
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002881 /* Align to minimum height recommended by the panel */
2882 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2883 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2884 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2885 else
2886 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2887 }
2888
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002889 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002890 if(LEFT_ALIGN)
2891 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2892
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002893 if(WIDTH_ALIGN) {
2894 int width = t_roi.right - t_roi.left;
2895 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2896 t_roi.right = t_roi.left + width;
2897
2898 if(t_roi.right > boundary.right) {
2899 t_roi.right = boundary.right;
2900 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002901
2902 if(LEFT_ALIGN)
2903 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002904 }
2905 }
2906
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002907
2908 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002909 if(TOP_ALIGN)
2910 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2911
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002912 if(HEIGHT_ALIGN) {
2913 int height = t_roi.bottom - t_roi.top;
2914 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2915 t_roi.bottom = t_roi.top + height;
2916
2917 if(t_roi.bottom > boundary.bottom) {
2918 t_roi.bottom = boundary.bottom;
2919 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002920
2921 if(TOP_ALIGN)
2922 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002923 }
2924 }
2925
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002926
2927 return t_roi;
2928}
2929
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002930void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002931 if(ctx->dpyAttr[dpy].connected) {
2932 ctx->mDrawLock.lock();
2933 ctx->dpyAttr[dpy].isActive = true;
2934 ctx->dpyAttr[dpy].isPause = true;
2935 ctx->mDrawLock.unlock();
2936 ctx->proc->invalidate(ctx->proc);
2937
2938 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2939 * 2 / 1000);
2940
2941 // At this point all the pipes used by External have been
2942 // marked as UNSET.
2943 ctx->mDrawLock.lock();
2944 // Perform commit to unstage the pipes.
2945 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2946 ALOGE("%s: display commit fail! for %d dpy",
2947 __FUNCTION__, dpy);
2948 }
2949 ctx->mDrawLock.unlock();
2950 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002951 }
2952 return;
2953}
2954
2955void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002956 if(ctx->dpyAttr[dpy].connected) {
2957 ctx->mDrawLock.lock();
2958 ctx->dpyAttr[dpy].isConfiguring = true;
2959 ctx->dpyAttr[dpy].isActive = true;
2960 ctx->mDrawLock.unlock();
2961 ctx->proc->invalidate(ctx->proc);
2962
2963 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2964 * 2 / 1000);
2965
2966 //At this point external has all the pipes it would need.
2967 ctx->mDrawLock.lock();
2968 ctx->dpyAttr[dpy].isPause = false;
2969 ctx->mDrawLock.unlock();
2970 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002971 }
2972 return;
2973}
2974
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002975void clearPipeResources(hwc_context_t* ctx, int dpy) {
2976 if(ctx->mOverlay) {
2977 ctx->mOverlay->configBegin();
2978 ctx->mOverlay->configDone();
2979 }
2980 if(ctx->mRotMgr) {
2981 ctx->mRotMgr->clear();
2982 }
2983 // Call a display commit to ensure that pipes and associated
2984 // fd's are cleaned up.
2985 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2986 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2987 }
2988}
2989
2990// Handles online events when HDMI is the primary display. In particular,
2991// online events for hdmi connected before AND after boot up and HWC init.
2992void handle_online(hwc_context_t* ctx, int dpy) {
2993 // Close the current fd if it was opened earlier on when HWC
2994 // was initialized.
2995 if (ctx->dpyAttr[dpy].fd >= 0) {
2996 close(ctx->dpyAttr[dpy].fd);
2997 ctx->dpyAttr[dpy].fd = -1;
2998 }
2999 // TODO: If HDMI is connected after the display has booted up,
3000 // and the best configuration is different from the default
3001 // then we need to deal with this appropriately.
Arun Kumar K.R205df772015-02-20 18:45:58 -08003002 int error = ctx->mHDMIDisplay->configure();
3003 if (error < 0) {
3004 ALOGE("Error opening FrameBuffer");
3005 return;
3006 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07003007 updateDisplayInfo(ctx, dpy);
3008 initCompositionResources(ctx, dpy);
3009 ctx->dpyAttr[dpy].connected = true;
3010}
3011
3012// Handles offline events for HDMI. This can be used for offline events
3013// initiated by the HDMI driver and the CEC framework.
3014void handle_offline(hwc_context_t* ctx, int dpy) {
3015 destroyCompositionResources(ctx, dpy);
3016 // Clear all pipe resources and call a display commit to ensure
3017 // that all the fd's are closed. This will ensure that the HDMI
3018 // core turns off and that we receive an event the next time the
3019 // cable is connected.
3020 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
3021 clearPipeResources(ctx, dpy);
3022 }
3023 ctx->mHDMIDisplay->teardown();
3024 resetDisplayInfo(ctx, dpy);
3025 ctx->dpyAttr[dpy].connected = false;
3026 ctx->dpyAttr[dpy].isActive = false;
3027}
3028
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05003029int convertS3DFormatToMode(int s3DFormat) {
3030 int ret;
3031 switch(s3DFormat) {
3032 case HAL_3D_SIDE_BY_SIDE_L_R:
3033 case HAL_3D_SIDE_BY_SIDE_R_L:
3034 ret = HDMI_S3D_SIDE_BY_SIDE;
3035 break;
3036 case HAL_3D_TOP_BOTTOM:
3037 ret = HDMI_S3D_TOP_AND_BOTTOM;
3038 break;
3039 default:
3040 ret = HDMI_S3D_NONE;
3041 }
3042 return ret;
3043}
3044
3045bool needs3DComposition(hwc_context_t* ctx, int dpy) {
3046 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
3047 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3048}
3049
3050void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3051 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3052 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3053 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3054 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3055 }
3056 }
3057}
3058
3059bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3060 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3061 ((dpy == HWC_DISPLAY_PRIMARY) &&
3062 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3063}
3064
3065
Saurabh Shahacf10202013-02-26 10:15:15 -08003066};//namespace qhwc