blob: da9004f3c1066f276b121056032d39b7174ba60d [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 Singhb8369bf2014-10-29 18:42:43 +053079#define PROP_DEFAULT_APPBUFFER "sf.default.app_buffer_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
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530122void changeResolution(hwc_context_t *ctx, int xres_orig, int yres_orig,
123 int width, int height) {
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530124 //Store original display resolution.
Dileep Kumar Reddie351d842014-03-25 10:39:21 +0530125 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_orig;
126 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_orig;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530127 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530128 char property[PROPERTY_VALUE_MAX] = {'\0'};
129 char *yptr = NULL;
130 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
131 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530132 if(yptr) {
133 int xres_new = atoi(property);
134 int yres_new = atoi(yptr + 1);
135 if (isValidResolution(ctx,xres_new,yres_new) &&
136 xres_new != xres_orig && yres_new != yres_orig) {
137 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_new;
138 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_new;
139 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530140
Raj Kamal4a443082014-10-12 21:07:59 +0530141 //Caluculate DPI according to changed resolution.
142 float xdpi = ((float)xres_new * 25.4f) / (float)width;
143 float ydpi = ((float)yres_new * 25.4f) / (float)height;
144 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
145 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
146 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530147 }
148 }
149}
150
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700151// Initialize hdmi display attributes based on
152// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700153void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
radhakrishnac3198ff2015-03-10 17:10:02 +0530154 struct fb_var_screeninfo info;
155
156 if (ioctl(ctx->mHDMIDisplay->getFd(), FBIOGET_VSCREENINFO, &info) == -1) {
157 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s",
158 __FUNCTION__, strerror(errno));
159 }
160
161 ctx->dpyAttr[dpy].fbformat = getFBformat(info);
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700162 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
163 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
164 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
165 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
166 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700167 //FIXME: for now assume HDMI as secure
168 //Will need to read the HDCP status from the driver
169 //and update this accordingly
170 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700171 ctx->mViewFrame[dpy].left = 0;
172 ctx->mViewFrame[dpy].top = 0;
173 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
174 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
175}
176
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700177// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700178void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
179 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
180 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
181 // We reset the fd to -1 here but External display class is responsible
182 // for it when the display is disconnected. This is handled as part of
183 // EXTERNAL_OFFLINE event.
184 ctx->dpyAttr[dpy].fd = -1;
185}
186
187// Initialize composition resources
188void initCompositionResources(hwc_context_t* ctx, int dpy) {
189 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
190 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
191}
192
193void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
194 if(ctx->mFBUpdate[dpy]) {
195 delete ctx->mFBUpdate[dpy];
196 ctx->mFBUpdate[dpy] = NULL;
197 }
198 if(ctx->mMDPComp[dpy]) {
199 delete ctx->mMDPComp[dpy];
200 ctx->mMDPComp[dpy] = NULL;
201 }
202}
203
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800204static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700205{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800206 struct fb_fix_screeninfo finfo;
207 struct fb_var_screeninfo info;
208
209 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530210 if(fb_fd < 0) {
211 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800212 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530213 }
214
215 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
216 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
217 strerror(errno));
218 close(fb_fd);
219 return -errno;
220 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800221
222 if (int(info.width) <= 0 || int(info.height) <= 0) {
223 // the driver doesn't return that information
224 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530225 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
226 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700227 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800228
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530229 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
230 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800231
232#ifdef MSMFB_METADATA_GET
233 struct msmfb_metadata metadata;
234 memset(&metadata, 0 , sizeof(metadata));
235 metadata.op = metadata_op_frame_rate;
236
237 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530238 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
239 strerror(errno));
240 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800241 return -errno;
242 }
243
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530244 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800245#else
246 //XXX: Remove reserved field usage on all baselines
247 //The reserved[3] field is used to store FPS by the driver.
248 float fps = info.reserved[3] & 0xFF;
249#endif
250
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530251 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
252 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
253 strerror(errno));
254 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800255 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530256 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800257
258 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
259 //xres, yres may not be 32 aligned
260 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
261 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
262 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
263 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
264 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700265 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
266 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700267 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530268 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
269 (uint32_t)(1000000000l / fps);
radhakrishnac3198ff2015-03-10 17:10:02 +0530270 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fbformat = getFBformat(info);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800271
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530272 //To change resolution of primary display
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530273 changeResolution(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530274
Naseer Ahmed22616d92013-05-15 17:20:26 -0400275 //Unblank primary on first boot
276 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
277 ALOGE("%s: Failed to unblank display", __FUNCTION__);
278 return -errno;
279 }
280 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
281
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800282 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700283}
284
Ramakant Singh98c533c2014-09-30 19:01:54 +0530285static void changeDefaultAppBufferCount() {
286 struct sysinfo info;
287 unsigned long int ramSize = 0;
288 if (!sysinfo(&info)) {
289 ramSize = info.totalram ;
290 }
291 int fb_fd = -1;
292 struct fb_var_screeninfo sInfo ={0};
293 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
294 if (fb_fd >=0) {
295 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
296 close(fb_fd);
297 }
298 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
299 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
300 property_set(PROP_DEFAULT_APPBUFFER, "2");
301 }
302}
303
Naseer Ahmed29a26812012-06-14 00:56:20 -0700304void initContext(hwc_context_t *ctx)
305{
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700306 overlay::Overlay::initOverlay();
307 ctx->mHDMIDisplay = new HDMIDisplay();
308 uint32_t priW = 0, priH = 0;
309 // 1. HDMI as Primary
310 // -If HDMI cable is connected, read display configs from edid data
311 // -If HDMI cable is not connected then use default data in vscreeninfo
312 // 2. HDMI as External
313 // -Initialize HDMI class for use with external display
314 // -Use vscreeninfo to populate display configs
315 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
316 int connected = ctx->mHDMIDisplay->getConnectedState();
317 if(connected == 1) {
318 ctx->mHDMIDisplay->configure();
319 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
320 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
321 } else {
322 openFramebufferDevice(ctx);
323 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
324 }
325 } else {
326 openFramebufferDevice(ctx);
327 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
328 // Send the primary resolution to the hdmi display class
329 // to be used for MDP scaling functionality
330 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
331 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
332 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
333 }
334
Raj kamal59fea562014-04-01 16:52:19 +0530335 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700336 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
337 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
338 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800339 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800340 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800341 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800342
Ramakant Singh98c533c2014-09-30 19:01:54 +0530343 //default_app_buffer for ferrum
344 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
345 changeDefaultAppBufferCount();
346 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700347 // Initialize composition objects for the primary display
348 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800349
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800350 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800351 // decide if we need to open the copybit module.
352 int compositionType =
353 qdutils::QCCompositionType::getInstance().getCompositionType();
354
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800355 // Only MDP copybit is used
356 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
357 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530358 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
359 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800360 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530361 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800362 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
363 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800364 }
365
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700366 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700367 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
368 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
369 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
370 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700371 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
372 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
373 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800374
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700375 //Initialize the primary display viewFrame info
376 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
377 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
378 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
379 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
380 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
381 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530382
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700383 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700384 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700385 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700386 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800387 ctx->dpyAttr[i].mActionSafePresent = false;
388 ctx->dpyAttr[i].mAsWidthRatio = 0;
389 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500390 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
391 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700392 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700393
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500394 //Make sure that the 3D mode is unset at bootup
395 //This makes sure that the state is accurate on framework reboots
396 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
397
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530398 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
399 ctx->mPrevHwLayerCount[i] = 0;
400 }
401
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500402 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700403 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700404
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400405 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500406 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700407 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530408 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800409
410 //Right now hwc starts the service but anybody could do it, or it could be
411 //independent process as well.
412 QService::init();
413 sp<IQClient> client = new QClient(ctx);
Charles Bindab39382014-06-30 10:34:30 -0700414 android::sp<qService::IQService> qservice_sp = interface_cast<IQService>(
Saurabh Shah86c17292013-02-08 15:24:13 -0800415 defaultServiceManager()->getService(
Charles Bindab39382014-06-30 10:34:30 -0700416 String16("display.qservice")));
417 if (qservice_sp.get()) {
418 qservice_sp->connect(client);
419 } else {
420 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
421 return ;
422 }
Saurabh Shah86c17292013-02-08 15:24:13 -0800423
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700424 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700425 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700426 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400427
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700428 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
429 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
430
Ramakant Singh0def28c2014-03-28 20:43:13 +0530431 ctx->enableABC = false;
432 property_get("debug.sf.hwc.canUseABC", value, "0");
433 ctx->enableABC = atoi(value) ? true : false;
434
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530435 // Initializing boot anim completed check to false
436 ctx->mBootAnimCompleted = false;
437
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700438 // Initialize gpu perfomance hint related parameters
439 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700440#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700441 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
442
443 ctx->mGPUHintInfo.mEGLDisplay = NULL;
444 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700445 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700446 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700447#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700448 // Read the system property to determine if windowboxing feature is enabled.
449 ctx->mWindowboxFeature = false;
450 if(property_get("sys.hwc.windowbox_feature", value, "false")
451 && !strcmp(value, "true")) {
452 ctx->mWindowboxFeature = true;
453 }
454
Raj Kamal0d53fc62014-11-25 17:36:36 +0530455 ctx->mUseMetaDataRefreshRate = true;
456 if(property_get("persist.metadata_dynfps.disable", value, "false")
457 && !strcmp(value, "true")) {
458 ctx->mUseMetaDataRefreshRate = false;
459 }
460
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700461 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800462 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700463 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700464 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700465}
466
467void closeContext(hwc_context_t *ctx)
468{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500469 if(ctx->mOverlay) {
470 delete ctx->mOverlay;
471 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700472 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700473
Saurabh Shahacf10202013-02-26 10:15:15 -0800474 if(ctx->mRotMgr) {
475 delete ctx->mRotMgr;
476 ctx->mRotMgr = NULL;
477 }
478
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700479 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800480 if(ctx->mCopyBit[i]) {
481 delete ctx->mCopyBit[i];
482 ctx->mCopyBit[i] = NULL;
483 }
484 }
485
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800486 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700487 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
488 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700489 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700490
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700491 if(ctx->mHDMIDisplay) {
492 delete ctx->mHDMIDisplay;
493 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700494 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400495
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700496 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700497 destroyCompositionResources(ctx, i);
498
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700499 if(ctx->mHwcDebug[i]) {
500 delete ctx->mHwcDebug[i];
501 ctx->mHwcDebug[i] = NULL;
502 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700503 if(ctx->mLayerRotMap[i]) {
504 delete ctx->mLayerRotMap[i];
505 ctx->mLayerRotMap[i] = NULL;
506 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800507 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800508 if(ctx->mHWCVirtual) {
509 delete ctx->mHWCVirtual;
510 ctx->mHWCVirtual = NULL;
511 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700512 if(ctx->mAD) {
513 delete ctx->mAD;
514 ctx->mAD = NULL;
515 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800516
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800517
Naseer Ahmed29a26812012-06-14 00:56:20 -0700518}
519
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700520//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530521uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700522 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
523 uint32_t rate = refreshRate;
524 for(int i=0; i< count; i++) {
525 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
526 // Most likely used for video, the fps can fluctuate
527 // Ex: b/w 29 and 30 for 30 fps clip
528 rate = stdRefreshRates[i];
529 break;
530 }
531 }
532 return rate;
533}
534
535//Helper func to set the dyn fps
536void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
537 //Update only if different
538 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
539 return;
540 const int fbNum = Overlay::getFbForDpy(dpy);
541 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
542 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800543 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700544
545 int fd = open(sysfsPath, O_WRONLY);
546 if(fd >= 0) {
547 char str[64];
548 snprintf(str, sizeof(str), "%d", refreshRate);
549 ssize_t ret = write(fd, str, strlen(str));
550 if(ret < 0) {
551 ALOGE("%s: Failed to write %d with error %s",
552 __FUNCTION__, refreshRate, strerror(errno));
553 } else {
554 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
555 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
556 __FUNCTION__, refreshRate);
557 }
558 close(fd);
559 } else {
560 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
561 strerror(errno));
562 }
563}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500564
565void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700566{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500567 va_list varargs;
568 va_start(varargs, fmt);
569 buf.appendFormatV(fmt, varargs);
570 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700571}
572
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700573int getExtOrientation(hwc_context_t* ctx) {
574 int extOrient = ctx->mExtOrientation;
575 if(ctx->mBufferMirrorMode)
576 extOrient = getMirrorModeOrientation(ctx);
577 return extOrient;
578}
579
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800580/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700581void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
582 // Position
583 int x = rect.left, y = rect.top;
584 int w = rect.right - rect.left;
585 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800586
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800587 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800588 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800589 // Read action safe properties
590 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
591 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700592
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800593 float wRatio = 1.0;
594 float hRatio = 1.0;
595 float xRatio = 1.0;
596 float yRatio = 1.0;
597
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700598 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
599 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700600 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
601 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700602 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700603 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700604 }
605
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800606
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700607 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700608 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700609
610 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700611 swap(fbWidth, fbHeight);
612
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800613 float asX = 0;
614 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530615 float asW = (float)fbWidth;
616 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800617
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800618 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530619 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
620 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
621 asX = ((float)fbWidth - asW) / 2;
622 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800623
624 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530625 xRatio = (float)x/(float)fbWidth;
626 yRatio = (float)y/(float)fbHeight;
627 wRatio = (float)w/(float)fbWidth;
628 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800629
630 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530631 x = int((xRatio * asW) + asX);
632 y = int((yRatio * asH) + asY);
633 w = int(wRatio * asW);
634 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800635
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700636 // Convert it back to hwc_rect_t
637 rect.left = x;
638 rect.top = y;
639 rect.right = w + rect.left;
640 rect.bottom = h + rect.top;
641
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800642 return;
643}
644
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700645// This function gets the destination position for Seconday display
646// based on the position and aspect ratio with orientation
647void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
648 hwc_rect_t& inRect, hwc_rect_t& outRect) {
649 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530650 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
651 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700652 //display position(x,y,w,h) in correct aspectratio after rotation
653 int xPos = 0;
654 int yPos = 0;
655 float width = fbWidth;
656 float height = fbHeight;
657 // Width/Height used for calculation, after rotation
658 float actualWidth = fbWidth;
659 float actualHeight = fbHeight;
660
661 float wRatio = 1.0;
662 float hRatio = 1.0;
663 float xRatio = 1.0;
664 float yRatio = 1.0;
665 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
666
667 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
668 inRect.bottom - inRect.top);
669 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
670 outRect.bottom - outRect.top);
671
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530672 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700673 eTransform extorient = static_cast<eTransform>(extOrientation);
674 // To calculate the destination co-ordinates in the new orientation
675 preRotateSource(extorient, whf, inPos);
676
677 if(extOrientation & HAL_TRANSFORM_ROT_90) {
678 // Swap width/height for input position
679 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700680 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
681 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700682 xPos = rect.left;
683 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530684 width = float(rect.right - rect.left);
685 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700686 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700687 xRatio = (float)((float)inPos.x/actualWidth);
688 yRatio = (float)((float)inPos.y/actualHeight);
689 wRatio = (float)((float)inPos.w/actualWidth);
690 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800691
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530692 //Calculate the pos9ition...
693 outPos.x = uint32_t((xRatio * width) + (float)xPos);
694 outPos.y = uint32_t((yRatio * height) + (float)yPos);
695 outPos.w = uint32_t(wRatio * width);
696 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700697 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
698 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
699 outPos.w, outPos.h);
700
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700701 // For sidesync, the dest fb will be in portrait orientation, and the crop
702 // will be updated to avoid the black side bands, and it will be upscaled
703 // to fit the dest RB, so recalculate
704 // the position based on the new width and height
705 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
706 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800707 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700708 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530709 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700710 // GetaspectRatio -- tricky to get the correct aspect ratio
711 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700712 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530713 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700714 xPos = r.left;
715 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530716 float tempHeight = float(r.bottom - r.top);
717 yRatio = (float)yPos/height;
718 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700719 hRatio = tempHeight/height;
720
721 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530722 outPos.x = uint32_t(xRatio * fbWidth);
723 outPos.y = uint32_t(yRatio * fbHeight);
724 outPos.w = uint32_t(wRatio * fbWidth);
725 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700726
727 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
728 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
729 outPos.x, outPos.y,
730 outPos.w, outPos.h);
731 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700732 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700733 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700734 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700735 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700736 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
737 extW = ctx->mHWCVirtual->getScalingWidth();
738 extH = ctx->mHWCVirtual->getScalingHeight();
739 }
740 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
741 __FUNCTION__, extW, extH);
742
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530743 fbWidth = (float)ctx->dpyAttr[dpy].xres;
744 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700745 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530746 xRatio = (float)outPos.x/fbWidth;
747 yRatio = (float)outPos.y/fbHeight;
748 wRatio = (float)outPos.w/fbWidth;
749 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700750
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530751 outPos.x = uint32_t(xRatio * (float)extW);
752 outPos.y = uint32_t(yRatio * (float)extH);
753 outPos.w = uint32_t(wRatio * (float)extW);
754 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700755 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700756 // Convert Dim to hwc_rect_t
757 outRect.left = outPos.x;
758 outRect.top = outPos.y;
759 outRect.right = outPos.x + outPos.w;
760 outRect.bottom = outPos.y + outPos.h;
761
762 return;
763}
764
765bool isPrimaryPortrait(hwc_context_t *ctx) {
766 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
767 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
768 if(fbWidth < fbHeight) {
769 return true;
770 }
771 return false;
772}
773
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700774bool isOrientationPortrait(hwc_context_t *ctx) {
775 if(isPrimaryPortrait(ctx)) {
776 return !(ctx->deviceOrientation & 0x1);
777 }
778 return (ctx->deviceOrientation & 0x1);
779}
780
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700781void calcExtDisplayPosition(hwc_context_t *ctx,
782 private_handle_t *hnd,
783 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700784 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700785 hwc_rect_t& displayFrame,
786 int& transform,
787 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700788 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700789 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530790 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700791 if(!isYuvBuffer(hnd)) {
792 if(extOrient & HWC_TRANSFORM_ROT_90) {
793 int dstWidth = ctx->dpyAttr[dpy].xres;
794 int dstHeight = ctx->dpyAttr[dpy].yres;;
795 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
796 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
797 if(!isPrimaryPortrait(ctx)) {
798 swap(srcWidth, srcHeight);
799 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700800 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700801 srcHeight, displayFrame);
802 // Crop - this is needed, because for sidesync, the dest fb will
803 // be in portrait orientation, so update the crop to not show the
804 // black side bands.
805 if (isOrientationPortrait(ctx)) {
806 sourceCrop = displayFrame;
807 displayFrame.left = 0;
808 displayFrame.top = 0;
809 displayFrame.right = dstWidth;
810 displayFrame.bottom = dstHeight;
811 }
812 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700813 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700814 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700815 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700816 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530817 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
818 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700819 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700820 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700821 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700822 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
823 extW = ctx->mHWCVirtual->getScalingWidth();
824 extH = ctx->mHWCVirtual->getScalingHeight();
825 }
826 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
827 __FUNCTION__, extW, extH);
828
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700829 //Calculate the ratio...
830 float wRatio = ((float)extW)/fbWidth;
831 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700832
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700833 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530834 displayFrame.left = int(wRatio*(float)displayFrame.left);
835 displayFrame.top = int(hRatio*(float)displayFrame.top);
836 displayFrame.right = int(wRatio*(float)displayFrame.right);
837 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700838 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
839 " for MDPDownscale feature [%d %d %d %d]",
840 displayFrame.left, displayFrame.top,
841 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700842 }
843 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700844 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700845 getAspectRatioPosition(ctx, dpy, extOrient,
846 displayFrame, displayFrame);
847 }
848 }
849 // If there is a external orientation set, use that
850 if(extOrient) {
851 transform = extOrient;
852 orient = static_cast<ovutils::eTransform >(extOrient);
853 }
854 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
855 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700856 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700857}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700858
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700859/* Returns the orientation which needs to be set on External for
860 * SideSync/Buffer Mirrormode
861 */
862int getMirrorModeOrientation(hwc_context_t *ctx) {
863 int extOrientation = 0;
864 int deviceOrientation = ctx->deviceOrientation;
865 if(!isPrimaryPortrait(ctx))
866 deviceOrientation = (deviceOrientation + 1) % 4;
867 if (deviceOrientation == 0)
868 extOrientation = HWC_TRANSFORM_ROT_270;
869 else if (deviceOrientation == 1)//90
870 extOrientation = 0;
871 else if (deviceOrientation == 2)//180
872 extOrientation = HWC_TRANSFORM_ROT_90;
873 else if (deviceOrientation == 3)//270
874 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
875
876 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700877}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700878
Raj kamal59fea562014-04-01 16:52:19 +0530879/* Get External State names */
880const char* getExternalDisplayState(uint32_t external_state) {
881 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
882 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
883 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
884 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
885 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
886
887 if(external_state >= EXTERNAL_MAXSTATES) {
888 return "EXTERNAL_INVALID";
889 }
890
891 return externalStates[external_state];
892}
893
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530894bool isDownscaleRequired(hwc_layer_1_t const* layer) {
895 hwc_rect_t displayFrame = layer->displayFrame;
896 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
897 int dst_w, dst_h, src_w, src_h;
898 dst_w = displayFrame.right - displayFrame.left;
899 dst_h = displayFrame.bottom - displayFrame.top;
900 src_w = sourceCrop.right - sourceCrop.left;
901 src_h = sourceCrop.bottom - sourceCrop.top;
902
903 if(((src_w > dst_w) || (src_h > dst_h)))
904 return true;
905
906 return false;
907}
908bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500909 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500910 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700911 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500912
913 dst_w = displayFrame.right - displayFrame.left;
914 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500915 src_w = sourceCrop.right - sourceCrop.left;
916 src_h = sourceCrop.bottom - sourceCrop.top;
917
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800918 if(layer->transform & HWC_TRANSFORM_ROT_90)
919 swap(src_w, src_h);
920
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800921 if(((src_w != dst_w) || (src_h != dst_h)))
922 return true;
923
924 return false;
925}
926
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700927// Checks if layer needs scaling with split
928bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
929 const int& dpy) {
930
931 int src_width_l, src_height_l;
932 int src_width_r, src_height_r;
933 int dst_width_l, dst_height_l;
934 int dst_width_r, dst_height_r;
935 int hw_w = ctx->dpyAttr[dpy].xres;
936 int hw_h = ctx->dpyAttr[dpy].yres;
937 hwc_rect_t cropL, dstL, cropR, dstR;
938 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700939 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700940 hwc_rect_t displayFrame = layer->displayFrame;
941 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700942
943 cropL = sourceCrop;
944 dstL = displayFrame;
945 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800946 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700947 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
948
949 cropR = sourceCrop;
950 dstR = displayFrame;
951 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800952 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700953 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
954
955 // Sanitize Crop to stitch
956 sanitizeSourceCrop(cropL, cropR, hnd);
957
958 // Calculate the left dst
959 dst_width_l = dstL.right - dstL.left;
960 dst_height_l = dstL.bottom - dstL.top;
961 src_width_l = cropL.right - cropL.left;
962 src_height_l = cropL.bottom - cropL.top;
963
964 // check if there is any scaling on the left
965 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
966 return true;
967
968 // Calculate the right dst
969 dst_width_r = dstR.right - dstR.left;
970 dst_height_r = dstR.bottom - dstR.top;
971 src_width_r = cropR.right - cropR.left;
972 src_height_r = cropR.bottom - cropR.top;
973
974 // check if there is any scaling on the right
975 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
976 return true;
977
978 return false;
979}
980
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530981bool isAlphaScaled(hwc_layer_1_t const* layer) {
982 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530983 return true;
984 }
985 return false;
986}
987
988bool isAlphaPresent(hwc_layer_1_t const* layer) {
989 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400990 if(hnd) {
991 int format = hnd->format;
992 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530993 case HAL_PIXEL_FORMAT_RGBA_8888:
994 case HAL_PIXEL_FORMAT_BGRA_8888:
995 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500996 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530997 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400998 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500999 }
1000 return false;
1001}
1002
radhakrishnac3198ff2015-03-10 17:10:02 +05301003bool isAlphaPresentinFB(hwc_context_t *ctx, int dpy) {
1004 switch(ctx->dpyAttr[dpy].fbformat) {
1005 case HAL_PIXEL_FORMAT_RGBA_8888:
1006 case HAL_PIXEL_FORMAT_BGRA_8888:
1007 return true;
1008 default : return false;
1009 }
1010 return false;
1011}
1012
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001013static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
1014 hwc_rect_t& crop, hwc_rect_t& dst) {
1015 int hw_w = ctx->dpyAttr[dpy].xres;
1016 int hw_h = ctx->dpyAttr[dpy].yres;
1017 if(dst.left < 0 || dst.top < 0 ||
1018 dst.right > hw_w || dst.bottom > hw_h) {
1019 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001020 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001021 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1022 }
1023}
1024
1025static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1026 const int& dpy) {
1027 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1028 hwc_layer_1_t *layer = &list->hwLayers[i];
1029 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001030 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1031 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001032 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001033 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001034 (hwc_rect_t&)crop,
1035 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301036 layer->sourceCropf.left = (float)crop.left;
1037 layer->sourceCropf.right = (float)crop.right;
1038 layer->sourceCropf.top = (float)crop.top;
1039 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001040 }
1041}
1042
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001043void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001044 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001045 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1046 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301047 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1048 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001049 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301050 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001051 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001052 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001053 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001054 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001055 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301056 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001057 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301058 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001059 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001060 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1061 uint32_t refreshRate = 0;
1062 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001063 int s3dFormat = HAL_NO_3D;
1064 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001065
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001066 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001067 resetROI(ctx, dpy);
1068
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001069 trimList(ctx, list, dpy);
1070 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001071 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001072 hwc_layer_1_t const* layer = &list->hwLayers[i];
1073 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001074
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001075#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001076 // Window boxing feature is applicable obly for external display, So
1077 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001078 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001079 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001080 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001081 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1082 ctx->listStats[dpy].isDisplayAnimating = true;
1083 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001084 if(isSecureDisplayBuffer(hnd)) {
1085 ctx->listStats[dpy].secureUI = true;
1086 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001087#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001088 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1089 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001090 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001091
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001092 //reset yuv indices
1093 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301094 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001095
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001096 if (isSecureBuffer(hnd)) {
1097 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001098 if(not isYuvBuffer(hnd)) {
1099 // cache secureRGB layer parameters like we cache for YUV layers
1100 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1101 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1102 secureRGBCount++;
1103 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001104 }
1105
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001106 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001107 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001108 }
1109
1110 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001111 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301112 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001113 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001114
Raj Kamal389d6e32014-08-04 14:43:24 +05301115 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301116 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301117 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301118 yuv4k2kCount++;
1119 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001120
1121 // Gets set if one YUV layer is 3D
1122 if (displaySupports3D(ctx,dpy)) {
1123 s3dFormat = get3DFormat(hnd);
1124 if(s3dFormat != HAL_NO_3D)
1125 s3dLayerCount++;
1126 }
1127
Naseer Ahmed29a26812012-06-14 00:56:20 -07001128 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301129 if(layer->blending == HWC_BLENDING_PREMULT)
1130 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001131
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001132#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301133 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001134 //dyn fps: get refreshrate from metadata
1135 //Support multiple refresh rates if they are same
1136 //else set to default
1137 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1138 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1139 // Valid refreshRate in metadata and within the range
1140 uint32_t rate = roundOff(mdata->refreshrate);
1141 if((rate >= mdpHw.getMinFpsSupported() &&
1142 rate <= mdpHw.getMaxFpsSupported())) {
1143 if (!refreshRate) {
1144 refreshRate = rate;
1145 } else if(refreshRate != rate) {
1146 // multiple refreshrate requests, set to default
1147 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1148 }
1149 }
1150 }
1151 }
1152#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001153 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001154
1155 //Set the TV's 3D mode based on format if it was not forced
1156 //Only one 3D YUV layer is supported on external
1157 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1158 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1159 //XXX: Rapidly going in and out of 3D mode in some cases such
1160 // as rotation might cause flickers. The OEMs are recommended to disable
1161 // rotation on HDMI globally or in the app that plays 3D video
1162 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1163 }
1164
Ping Li9404e2a2013-04-24 16:36:03 -04001165 if(ctx->listStats[dpy].yuvCount > 0) {
1166 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1167 if (atoi(property) != 1) {
1168 property_set("hw.cabl.yuv", "1");
1169 }
1170 }
1171 } else {
1172 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1173 if (atoi(property) != 0) {
1174 property_set("hw.cabl.yuv", "0");
1175 }
1176 }
1177 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001178
1179 //The marking of video begin/end is useful on some targets where we need
1180 //to have a padding round to be able to shift pipes across mixers.
1181 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1182 ctx->mVideoTransFlag = true;
1183 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301184
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001185 if(dpy == HWC_DISPLAY_PRIMARY) {
1186 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001187 //Store the requested fresh rate
1188 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1189 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001190 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001191}
1192
Naseer Ahmed018e5452012-12-03 14:46:15 -05001193
Saurabh Shah68107422013-07-09 11:12:42 -07001194static void calc_cut(double& leftCutRatio, double& topCutRatio,
1195 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001196 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001197 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001198 }
1199 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001200 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001201 }
1202 if(orient & HAL_TRANSFORM_ROT_90) {
1203 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001204 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001205 leftCutRatio = topCutRatio;
1206 topCutRatio = rightCutRatio;
1207 rightCutRatio = bottomCutRatio;
1208 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001209 }
1210}
1211
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001212bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001213 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1214 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1215 ctx->mSecuring) {
1216 return true;
1217 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001218 if (isSecureModePolicy(ctx->mMDP.version)) {
1219 private_handle_t *hnd = (private_handle_t *)layer->handle;
1220 if(ctx->mSecureMode) {
1221 if (! isSecureBuffer(hnd)) {
1222 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1223 __FUNCTION__);
1224 return true;
1225 }
1226 } else {
1227 if (isSecureBuffer(hnd)) {
1228 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1229 __FUNCTION__);
1230 return true;
1231 }
1232 }
1233 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001234 return false;
1235}
1236
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001237bool isSecureModePolicy(int mdpVersion) {
1238 if (mdpVersion < qdutils::MDSS_V5)
1239 return true;
1240 else
1241 return false;
1242}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001243
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001244bool isRotatorSupportedFormat(private_handle_t *hnd) {
1245 // Following rotator src formats are supported by mdp driver
1246 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001247 if(hnd != NULL) {
1248 switch(hnd->format) {
1249 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001250 case HAL_PIXEL_FORMAT_RGBA_5551:
1251 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001252 case HAL_PIXEL_FORMAT_RGB_565:
1253 case HAL_PIXEL_FORMAT_RGB_888:
1254 case HAL_PIXEL_FORMAT_BGRA_8888:
1255 return true;
1256 default:
1257 return false;
1258 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001259 }
1260 return false;
1261}
1262
1263bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001264 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001265 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001266 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001267 !ctx->mMDP.version < qdutils::MDSS_V5)
1268 || isYuvBuffer(hnd)) {
1269 return true;
1270 }
1271 return false;
1272}
1273
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001274// returns true if Action safe dimensions are set and target supports Actionsafe
1275bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1276 // if external supports underscan, do nothing
1277 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001278 // Disable Action safe for 8974 due to HW limitation for downscaling
1279 // layers with overlapped region
1280 // Disable Actionsafe for non HDMI displays.
1281 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1282 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001283 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001284 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001285 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001286
1287 char value[PROPERTY_VALUE_MAX];
1288 // Read action safe properties
1289 property_get("persist.sys.actionsafe.width", value, "0");
1290 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1291 property_get("persist.sys.actionsafe.height", value, "0");
1292 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1293
1294 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1295 //No action safe ratio set, return
1296 return false;
1297 }
1298 return true;
1299}
1300
Naseer Ahmed522ce662013-03-18 20:14:05 -04001301int getBlending(int blending) {
1302 switch(blending) {
1303 case HWC_BLENDING_NONE:
1304 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1305 case HWC_BLENDING_PREMULT:
1306 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1307 case HWC_BLENDING_COVERAGE :
1308 default:
1309 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1310 }
1311}
1312
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001313//Crops source buffer against destination and FB boundaries
1314void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001315 const hwc_rect_t& scissor, int orient) {
1316
Saurabh Shah27c1d652012-08-14 19:30:28 -07001317 int& crop_l = crop.left;
1318 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001319 int& crop_r = crop.right;
1320 int& crop_b = crop.bottom;
1321 int crop_w = crop.right - crop.left;
1322 int crop_h = crop.bottom - crop.top;
1323
Saurabh Shah27c1d652012-08-14 19:30:28 -07001324 int& dst_l = dst.left;
1325 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001326 int& dst_r = dst.right;
1327 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001328 int dst_w = abs(dst.right - dst.left);
1329 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001330
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001331 const int& sci_l = scissor.left;
1332 const int& sci_t = scissor.top;
1333 const int& sci_r = scissor.right;
1334 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001335
Saurabh Shah68107422013-07-09 11:12:42 -07001336 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1337 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001338
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001339 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001340 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001341 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001342 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001343
1344 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001345 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001346 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001347 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001348
1349 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001350 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001351 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001352 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001353
1354 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001355 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001356 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001357 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001358
Saurabh Shah541b59d2012-10-11 11:08:12 -07001359 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301360 crop_l += (int)round((double)crop_w * leftCutRatio);
1361 crop_t += (int)round((double)crop_h * topCutRatio);
1362 crop_r -= (int)round((double)crop_w * rightCutRatio);
1363 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001364}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001365
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301366bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1367 const hwc_layer_1_t* layer2) {
1368 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1369 layer2->displayFrame);
1370 return isValidRect(irect);
1371}
1372
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001373bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1374{
1375 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1376 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1377}
1378
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001379bool isValidRect(const hwc_rect& rect)
1380{
1381 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301382}
1383
Ramakant Singh21cec722014-03-07 19:11:45 +05301384bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1385 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1386 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1387 return true ;
1388 return false;
1389}
1390
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001391hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1392{
1393 hwc_rect_t res;
1394
1395 if(!isValidRect(rect))
1396 return (hwc_rect_t){0, 0, 0, 0};
1397
1398 res.left = rect.left + x_off;
1399 res.top = rect.top + y_off;
1400 res.right = rect.right + x_off;
1401 res.bottom = rect.bottom + y_off;
1402
1403 return res;
1404}
1405
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001406/* computes the intersection of two rects */
1407hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1408{
1409 hwc_rect_t res;
1410
1411 if(!isValidRect(rect1) || !isValidRect(rect2)){
1412 return (hwc_rect_t){0, 0, 0, 0};
1413 }
1414
1415
1416 res.left = max(rect1.left, rect2.left);
1417 res.top = max(rect1.top, rect2.top);
1418 res.right = min(rect1.right, rect2.right);
1419 res.bottom = min(rect1.bottom, rect2.bottom);
1420
1421 if(!isValidRect(res))
1422 return (hwc_rect_t){0, 0, 0, 0};
1423
1424 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301425}
1426
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001427/* computes the union of two rects */
1428hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1429{
1430 hwc_rect_t res;
1431
1432 if(!isValidRect(rect1)){
1433 return rect2;
1434 }
1435
1436 if(!isValidRect(rect2)){
1437 return rect1;
1438 }
1439
1440 res.left = min(rect1.left, rect2.left);
1441 res.top = min(rect1.top, rect2.top);
1442 res.right = max(rect1.right, rect2.right);
1443 res.bottom = max(rect1.bottom, rect2.bottom);
1444
1445 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301446}
1447
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001448/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1449 * a single rect */
1450hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301451
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001452 hwc_rect_t res = rect1;
1453
1454 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1455 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1456 res.top = rect2.bottom;
1457 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1458 res.bottom = rect2.top;
1459 }
1460 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1461 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1462 res.left = rect2.right;
1463 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1464 res.right = rect2.left;
1465 }
1466 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301467}
1468
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001469void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301470 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301471 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301472 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001473 //If it is opaque see if we can substract this region from below
1474 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301475 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1476 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301477 int j= i-1;
1478 hwc_rect_t& topframe =
1479 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1480 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301481 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001482 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1483 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001484 hwc_rect_t bottomCrop =
1485 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001486 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1487 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001488
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001489 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1490 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001491 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001492 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001493 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001494 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001495 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001496 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301497 layer->sourceCropf.left =(float)bottomCrop.left;
1498 layer->sourceCropf.top = (float)bottomCrop.top;
1499 layer->sourceCropf.right = (float)bottomCrop.right;
1500 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001501#ifdef QCOM_BSP
1502 //Update layer dirtyRect
1503 layer->dirtyRect = getIntersection(bottomCrop,
1504 layer->dirtyRect);
1505#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001506 }
1507 }
1508 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301509 }
1510 }
1511 i--;
1512 }
1513}
1514
Naseer Ahmed64b81212013-02-14 10:29:47 -05001515void getNonWormholeRegion(hwc_display_contents_1_t* list,
1516 hwc_rect_t& nwr)
1517{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301518 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001519 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1520 //Initiliaze nwr to first frame
1521 nwr.left = list->hwLayers[0].displayFrame.left;
1522 nwr.top = list->hwLayers[0].displayFrame.top;
1523 nwr.right = list->hwLayers[0].displayFrame.right;
1524 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1525
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301526 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001527 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001528 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001529 }
1530
1531 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001532 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001533}
1534
Saurabh Shah747af1e2013-02-26 10:25:12 -08001535void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001536 if(LIKELY(list)) {
1537 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1538 //Close the acquireFenceFds
1539 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1540 if(list->hwLayers[i].acquireFenceFd >= 0) {
1541 close(list->hwLayers[i].acquireFenceFd);
1542 list->hwLayers[i].acquireFenceFd = -1;
1543 }
1544 }
1545 //Writeback
1546 if(list->outbufAcquireFenceFd >= 0) {
1547 close(list->outbufAcquireFenceFd);
1548 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001549 }
1550 }
1551}
1552
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001553int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001554 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001555 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001556 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001557 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001558 int count = 0;
1559 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001560 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001561 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001562 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001563
1564 struct mdp_buf_sync data;
1565 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001566 data.acq_fen_fd = acquireFd;
1567 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001568 data.retire_fen_fd = &retireFd;
1569 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001570
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001571 char property[PROPERTY_VALUE_MAX];
1572 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1573 if(atoi(property) == 0)
1574 swapzero = true;
1575 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001576
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001577 bool isExtAnimating = false;
1578 if(dpy)
1579 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001580
Saurabh Shah23a813c2013-03-20 16:58:12 -07001581 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001582 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001583 int rotFd = ctx->mRotMgr->getRotDevFd();
1584 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001585 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1586 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1587 if((currRot == NULL) || (currLayer == NULL)) {
1588 continue;
1589 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001590 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001591 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001592 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001593 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001594 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001595 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001596 if(currLayer->acquireFenceFd >= 0) {
1597 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1598 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001599 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301600 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301601 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1602
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001603 if(ret < 0) {
1604 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1605 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001606 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001607 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001608 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001609 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001610 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001611 dup(rotReleaseFd);
1612 //A buffer is free to be used by producer as soon as its copied to
1613 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001614 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001615 rotReleaseFd;
1616 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001617 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001618
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301619 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001620 if(list->outbufAcquireFenceFd >= 0) {
1621 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301622 if(LIKELY(!swapzero) )
1623 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001624 }
1625
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001626 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301627 if(((isAbcInUse(ctx)== true ) ||
1628 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001629 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301630 if(LIKELY(!swapzero) ) {
1631 // if ABC is enabled for more than one layer.
1632 // renderBufIndexforABC will work as FB.Hence
1633 // set the acquireFD from fd - which is coming from copybit
1634 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1635 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1636 acquireFd[count++] = fd;
1637 else
1638 continue;
1639 } else
1640 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1641 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001642 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001643 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301644 if(LIKELY(!swapzero) ) {
1645 if(fd >= 0) {
1646 //set the acquireFD from fd - which is coming from c2d
1647 acquireFd[count++] = fd;
1648 // Buffer sync IOCTL should be async when using c2d fence is
1649 // used
1650 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1651 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1652 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1653 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001654 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001655 }
1656
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001657 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001658 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301659 if(LIKELY(!swapzero) )
1660 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001661 }
1662
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001663 data.acq_fen_fd_cnt = count;
1664 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001665
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001666 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001667 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001668 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001669 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001670
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001671 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001672 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1673 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301674 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001675 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1676 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001677 close(releaseFd);
1678 releaseFd = -1;
1679 close(retireFd);
1680 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001681 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001682
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001683 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001684 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001685#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001686 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001687#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001688 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001689 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001690 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001691 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001692 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001693 // Release all the app layer fds immediately,
1694 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001695 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001696 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001697#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001698 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301699 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301700
1701 // if ABC is enabled for more than one layer
1702 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1703 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1704 list->hwLayers[i].releaseFenceFd = dup(fd);
1705 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1706 (isAbcInUse(ctx) == false)){
1707 //For Blit, the app layers should be released when the Blit
1708 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301709 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001710 } else
1711#endif
1712 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301713 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1714 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001715 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001716 }
1717 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001718
1719 if(fd >= 0) {
1720 close(fd);
1721 fd = -1;
1722 }
1723
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001724 if (ctx->mCopyBit[dpy]) {
1725 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001726 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1727 else
1728 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1729 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001730
Saurabh Shah23a813c2013-03-20 16:58:12 -07001731 //Signals when MDP finishes reading rotator buffers.
1732 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001733 close(releaseFd);
1734 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001735
Arun Kumar K.R51835182013-11-19 11:20:28 -08001736 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001737 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001738 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001739 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001740 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001741 return ret;
1742}
1743
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001744void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001745 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001746 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001747 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001748 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001749
1750 if(layer->blending == HWC_BLENDING_PREMULT) {
1751 ovutils::setMdpFlags(mdpFlags,
1752 ovutils::OV_MDP_BLEND_FG_PREMULT);
1753 }
1754
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001755 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1756 metadata->interlaced) {
1757 ovutils::setMdpFlags(mdpFlags,
1758 ovutils::OV_MDP_DEINTERLACE);
1759 }
1760
1761 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1762 if(isSecureBuffer(hnd)) {
1763 ovutils::setMdpFlags(mdpFlags,
1764 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301765 ovutils::setMdpFlags(mdpFlags,
1766 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1767 }
1768
1769 if(isProtectedBuffer(hnd)) {
1770 ovutils::setMdpFlags(mdpFlags,
1771 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001772 }
1773
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001774 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001775 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001776 ovutils::setMdpFlags(mdpFlags,
1777 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1778 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001779
1780 //Pre-rotation will be used using rotator.
1781 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1782 ovutils::setMdpFlags(mdpFlags,
1783 ovutils::OV_MDP_SOURCE_ROTATED_90);
1784 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001785 //No 90 component and no rot-downscale then flips done by MDP
1786 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001787 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1788 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001789 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1790 }
1791
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001792 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001793 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1794 }
1795 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001796
1797 if(metadata &&
1798 ((metadata->operation & PP_PARAM_HSIC)
1799 || (metadata->operation & PP_PARAM_IGC)
1800 || (metadata->operation & PP_PARAM_SHARP2))) {
1801 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1802 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001803}
1804
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301805int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001806 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001807 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001808
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301809 // Fix alignments for TILED format
1810 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1811 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1812 whf.w = utils::alignup(whf.w, 64);
1813 whf.h = utils::alignup(whf.h, 32);
1814 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001815 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001816
1817 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1818 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001819 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1820 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001821 rot->setCrop(rotCrop);
1822 }
1823
Saurabh Shahacf10202013-02-26 10:15:15 -08001824 rot->setFlags(mdpFlags);
1825 rot->setTransform(orient);
1826 rot->setDownscale(downscale);
1827 if(!rot->commit()) return -1;
1828 return 0;
1829}
1830
Saurabh Shahe2474082013-05-15 16:32:13 -07001831int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001832 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001833 const hwc_rect_t& pos, const MetaData_t *metadata,
1834 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001835 ov->setSource(parg, dest);
1836 ov->setTransform(orient, dest);
1837
1838 int crop_w = crop.right - crop.left;
1839 int crop_h = crop.bottom - crop.top;
1840 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1841 ov->setCrop(dcrop, dest);
1842
1843 int posW = pos.right - pos.left;
1844 int posH = pos.bottom - pos.top;
1845 Dim position(pos.left, pos.top, posW, posH);
1846 ov->setPosition(position, dest);
1847
Saurabh Shah5daeee52013-01-23 16:52:26 +08001848 if (metadata)
1849 ov->setVisualParams(*metadata, dest);
1850
Saurabh Shahacf10202013-02-26 10:15:15 -08001851 if (!ov->commit(dest)) {
1852 return -1;
1853 }
1854 return 0;
1855}
1856
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001857int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1858 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001859 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001860
1861 hwc_rect_t dst = layer->displayFrame;
1862 trimLayer(ctx, dpy, 0, dst, dst);
1863
1864 int w = ctx->dpyAttr[dpy].xres;
1865 int h = ctx->dpyAttr[dpy].yres;
1866 int dst_w = dst.right - dst.left;
1867 int dst_h = dst.bottom - dst.top;
1868 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001869 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001870
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001871 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001872 if (layer->blending == HWC_BLENDING_PREMULT)
1873 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1874
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001875 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001876 layer->planeAlpha,
1877 (ovutils::eBlending) getBlending(layer->blending));
1878
1879 // Configure MDP pipe for Color layer
1880 Dim pos(dst.left, dst.top, dst_w, dst_h);
1881 ctx->mOverlay->setSource(parg, dest);
1882 ctx->mOverlay->setColor(color, dest);
1883 ctx->mOverlay->setTransform(0, dest);
1884 ctx->mOverlay->setCrop(pos, dest);
1885 ctx->mOverlay->setPosition(pos, dest);
1886
1887 if (!ctx->mOverlay->commit(dest)) {
1888 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1889 return -1;
1890 }
1891 return 0;
1892}
1893
Saurabh Shahe2474082013-05-15 16:32:13 -07001894void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001895 hwc_rect_t& crop, Rotator *rot) {
1896 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001897 crop.right - crop.left,
1898 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001899 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1900 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001901 //B-family rotator internally could modify destination dimensions if
1902 //downscaling is supported
1903 whf = rot->getDstWhf();
1904 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001905 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001906 //A-family rotator rotates entire buffer irrespective of crop, forcing
1907 //us to recompute the crop based on transform
1908 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1909 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001910 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001911
1912 crop.left = transformedCrop.x;
1913 crop.top = transformedCrop.y;
1914 crop.right = transformedCrop.x + transformedCrop.w;
1915 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001916}
1917
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001918int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1919 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1920 return 0;
1921 }
1922
1923 int downscale = 0;
1924 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1925 hwc_rect_t dst = layer->displayFrame;
1926 private_handle_t *hnd = (private_handle_t *)layer->handle;
1927
1928 if(not hnd) {
1929 return 0;
1930 }
1931
1932 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1933 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1934 && metadata->interlaced;
1935 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001936 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001937
1938 if(isYuvBuffer(hnd)) {
1939 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1940 ctx->mMDP.version < qdutils::MDSS_V5) {
1941 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1942 crop.bottom - crop.top, dst.right - dst.left,
1943 dst.bottom - dst.top, format, isInterlaced);
1944 } else {
1945 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1946 crop.bottom - crop.top);
1947 Dim pos(dst.left, dst.top, dst.right - dst.left,
1948 dst.bottom - dst.top);
1949 if(transform & HAL_TRANSFORM_ROT_90) {
1950 swap(adjCrop.w, adjCrop.h);
1951 }
1952 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1953 pos.h, format, isInterlaced);
1954 }
1955 }
1956 return downscale;
1957}
1958
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001959bool isZoomModeEnabled(hwc_rect_t crop) {
1960 // This does not work for zooming in top left corner of the image
1961 return(crop.top > 0 || crop.left > 0);
1962}
1963
1964void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1965 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1966 crop.left, crop.top, crop.right, crop.bottom);
1967 if(isZoomModeEnabled(crop)) {
1968 Dim srcCrop(crop.left, crop.top,
1969 crop.right - crop.left,
1970 crop.bottom - crop.top);
1971 int extW = ctx->dpyAttr[dpy].xres;
1972 int extH = ctx->dpyAttr[dpy].yres;
1973 //Crop the original video in order to fit external display aspect ratio
1974 if(srcCrop.w * extH < extW * srcCrop.h) {
1975 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1976 crop.top += offset;
1977 crop.bottom -= offset;
1978 } else {
1979 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1980 crop.left += offset;
1981 crop.right -= offset;
1982 }
1983 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1984 " source crop [%d %d %d %d]", extW, extH, dpy,
1985 crop.left, crop.top, crop.right, crop.bottom);
1986 }
1987}
1988
1989void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1990 hwc_rect_t& dst, int dpy) {
1991 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1992 dst.left, dst.top, dst.right, dst.bottom);
1993 Dim srcCrop(crop.left, crop.top,
1994 crop.right - crop.left,
1995 crop.bottom - crop.top);
1996 int extW = ctx->dpyAttr[dpy].xres;
1997 int extH = ctx->dpyAttr[dpy].yres;
1998 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07001999 // when zoom in mode is enabled or the ratio between video aspect ratio
2000 // and external display aspect ratio is below the minimum tolerance level
2001 // and above maximum tolerance level
2002 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
2003 float extDisplayAspectRatio = ((float)extW / (float)extH);
2004 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
2005 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
2006 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002007 dst.left = 0;
2008 dst.top = 0;
2009 dst.right = extW;
2010 dst.bottom = extH;
2011 }
2012 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
2013 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
2014 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
2015 crop.left, crop.top, crop.right, crop.bottom);
2016}
2017
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002018void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002019 hwc_rect_t& dst, int dpy) {
2020 updateCropAIVVideoMode(ctx, crop, dpy);
2021 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2022}
2023
Saurabh Shah88e4d272013-09-03 13:31:29 -07002024int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002025 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002026 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002027
2028 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002029
Saurabh Shahacf10202013-02-26 10:15:15 -08002030 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002031 if (layer->flags & HWC_COLOR_FILL) {
2032 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002033 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002034 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002035 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2036 return -1;
2037 }
2038
Saurabh Shah5daeee52013-01-23 16:52:26 +08002039 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2040
Saurabh Shah62e1d732013-09-17 10:44:05 -07002041 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002042 hwc_rect_t dst = layer->displayFrame;
2043 int transform = layer->transform;
2044 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002045 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002046 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302047 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002048
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002049 // Handle R/B swap
2050 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2051 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2052 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2053 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2054 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2055 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002056 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002057 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2058 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002059 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002060 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002061 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002062 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002063
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002064 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002065 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002066 *rot = ctx->mRotMgr->getNext();
2067 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002068 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002069 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2070 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002071 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002072 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2073 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002074 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002075 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002076 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002077 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002078 }
2079
Saurabh Shah76fd6552013-03-14 14:45:38 -07002080 //For the mdp, since either we are pre-rotating or MDP does flips
2081 orient = OVERLAY_TRANSFORM_0;
2082 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002083 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002084 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2085 (ovutils::eBlending) getBlending(layer->blending));
2086
Saurabh Shah5daeee52013-01-23 16:52:26 +08002087 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002088 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2089 return -1;
2090 }
2091 return 0;
2092}
2093
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002094//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002095void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002096 private_handle_t *hnd) {
2097 if(cropL.right - cropL.left) {
2098 if(isYuvBuffer(hnd)) {
2099 //Always safe to even down left
2100 ovutils::even_floor(cropL.left);
2101 //If right is even, automatically width is even, since left is
2102 //already even
2103 ovutils::even_floor(cropL.right);
2104 }
2105 //Make sure there are no gaps between left and right splits if the layer
2106 //is spread across BOTH halves
2107 if(cropR.right - cropR.left) {
2108 cropR.left = cropL.right;
2109 }
2110 }
2111
2112 if(cropR.right - cropR.left) {
2113 if(isYuvBuffer(hnd)) {
2114 //Always safe to even down left
2115 ovutils::even_floor(cropR.left);
2116 //If right is even, automatically width is even, since left is
2117 //already even
2118 ovutils::even_floor(cropR.right);
2119 }
2120 }
2121}
2122
Saurabh Shah88e4d272013-09-03 13:31:29 -07002123int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002124 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002125 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002126 Rotator **rot) {
2127 private_handle_t *hnd = (private_handle_t *)layer->handle;
2128 if(!hnd) {
2129 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2130 return -1;
2131 }
2132
Saurabh Shah5daeee52013-01-23 16:52:26 +08002133 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2134
Saurabh Shahacf10202013-02-26 10:15:15 -08002135 int hw_w = ctx->dpyAttr[dpy].xres;
2136 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002137 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002138 hwc_rect_t dst = layer->displayFrame;
2139 int transform = layer->transform;
2140 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002141 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002142 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302143 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002144
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002145 // Handle R/B swap
2146 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2147 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2148 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2149 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2150 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2151 }
2152
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002153 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002154 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2155 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002156 }
2157
2158 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002159 ActionSafe, and extorientation features. */
2160 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002161 int downscale = getRotDownscale(ctx, layer);
2162 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002163
2164 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2165 //Enable overfetch
2166 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2167 }
2168
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002169 //Will do something only if feature enabled and conditions suitable
2170 //hollow call otherwise
2171 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2172 overlay::Writeback *wb = overlay::Writeback::getInstance();
2173 whf.format = wb->getOutputFormat();
2174 }
2175
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002176 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002177 (*rot) = ctx->mRotMgr->getNext();
2178 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002179 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002180 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002181 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2182 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002183 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002184 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002185 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002186 rotFlags |= ROT_PREROTATED;
2187 }
2188
2189 eMdpFlags mdpFlagsR = mdpFlagsL;
2190 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2191
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002192 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2193 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002194
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002195 const int lSplit = getLeftSplit(ctx, dpy);
2196
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002197 // Calculate Left rects
2198 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002199 tmp_cropL = crop;
2200 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002201 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002202 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002203 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2204 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002205
2206 // Calculate Right rects
2207 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002208 tmp_cropR = crop;
2209 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002210 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002211 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002212 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2213 }
2214
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002215 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2216
Saurabh Shah94d62362013-07-02 10:58:48 -07002217 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002218 //Not needed if the layer is confined to one half of the screen.
2219 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002220 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2221 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002222 hwc_rect_t new_cropR;
2223 new_cropR.left = tmp_cropL.left;
2224 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2225
2226 hwc_rect_t new_cropL;
2227 new_cropL.left = new_cropR.right;
2228 new_cropL.right = tmp_cropR.right;
2229
2230 tmp_cropL.left = new_cropL.left;
2231 tmp_cropL.right = new_cropL.right;
2232
2233 tmp_cropR.left = new_cropR.left;
2234 tmp_cropR.right = new_cropR.right;
2235
2236 }
2237
Saurabh Shah76fd6552013-03-14 14:45:38 -07002238 //For the mdp, since either we are pre-rotating or MDP does flips
2239 orient = OVERLAY_TRANSFORM_0;
2240 transform = 0;
2241
Saurabh Shahacf10202013-02-26 10:15:15 -08002242 //configure left mixer
2243 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002244 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002245 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2246 (ovutils::eBlending) getBlending(layer->blending));
2247
Saurabh Shahacf10202013-02-26 10:15:15 -08002248 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002249 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002250 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2251 return -1;
2252 }
2253 }
2254
2255 //configure right mixer
2256 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002257 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002258 static_cast<eRotFlags>(rotFlags),
2259 layer->planeAlpha,
2260 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002261 tmp_dstR.right = tmp_dstR.right - lSplit;
2262 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002263 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002264 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002265 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2266 return -1;
2267 }
2268 }
2269
2270 return 0;
2271}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002272
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002273int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2274 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2275 const eDest& lDest, const eDest& rDest,
2276 Rotator **rot) {
2277 private_handle_t *hnd = (private_handle_t *)layer->handle;
2278 if(!hnd) {
2279 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2280 return -1;
2281 }
2282 //Both pipes are configured to the same mixer
2283 eZorder lz = z;
2284 eZorder rz = (eZorder)(z + 1);
2285
2286 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2287
2288 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2289 hwc_rect_t dst = layer->displayFrame;
2290 int transform = layer->transform;
2291 eTransform orient = static_cast<eTransform>(transform);
2292 int rotFlags = ROT_FLAGS_NONE;
2293 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2294 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2295
2296 int downscale = getRotDownscale(ctx, layer);
2297 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2298
2299 //XXX: Check if rotation is supported and valid for 3D
2300 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2301 (*rot) = ctx->mRotMgr->getNext();
2302 if((*rot) == NULL) return -1;
2303 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2304 //Configure rotator for pre-rotation
2305 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2306 ALOGE("%s: configRotator failed!", __FUNCTION__);
2307 return -1;
2308 }
2309 updateSource(orient, whf, crop, *rot);
2310 rotFlags |= ROT_PREROTATED;
2311 }
2312
2313 eMdpFlags mdpFlagsR = mdpFlagsL;
2314
2315 hwc_rect_t cropL = crop, dstL = dst;
2316 hwc_rect_t cropR = crop, dstR = dst;
2317 int hw_w = ctx->dpyAttr[dpy].xres;
2318 int hw_h = ctx->dpyAttr[dpy].yres;
2319
2320 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2321 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2322 // Calculate Left rects
2323 // XXX: This assumes crop.right/2 is the center point of the video
2324 cropL.right = crop.right/2;
2325 dstL.left = dst.left/2;
2326 dstL.right = dst.right/2;
2327
2328 // Calculate Right rects
2329 cropR.left = crop.right/2;
2330 dstR.left = hw_w/2 + dst.left/2;
2331 dstR.right = hw_w/2 + dst.right/2;
2332 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2333 // Calculate Left rects
2334 cropL.bottom = crop.bottom/2;
2335 dstL.top = dst.top/2;
2336 dstL.bottom = dst.bottom/2;
2337
2338 // Calculate Right rects
2339 cropR.top = crop.bottom/2;
2340 dstR.top = hw_h/2 + dst.top/2;
2341 dstR.bottom = hw_h/2 + dst.bottom/2;
2342 } else {
2343 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2344 return -1;
2345 }
2346
2347 //For the mdp, since either we are pre-rotating or MDP does flips
2348 orient = OVERLAY_TRANSFORM_0;
2349 transform = 0;
2350
2351 //configure left pipe
2352 if(lDest != OV_INVALID) {
2353 PipeArgs pargL(mdpFlagsL, whf, lz,
2354 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2355 (ovutils::eBlending) getBlending(layer->blending));
2356
2357 if(configMdp(ctx->mOverlay, pargL, orient,
2358 cropL, dstL, metadata, lDest) < 0) {
2359 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2360 return -1;
2361 }
2362 }
2363
2364 //configure right pipe
2365 if(rDest != OV_INVALID) {
2366 PipeArgs pargR(mdpFlagsR, whf, rz,
2367 static_cast<eRotFlags>(rotFlags),
2368 layer->planeAlpha,
2369 (ovutils::eBlending) getBlending(layer->blending));
2370 if(configMdp(ctx->mOverlay, pargR, orient,
2371 cropR, dstR, metadata, rDest) < 0) {
2372 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2373 return -1;
2374 }
2375 }
2376
2377 return 0;
2378}
2379
radhakrishnac9a67412013-09-25 17:40:42 +05302380int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2381 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002382 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302383 Rotator **rot) {
2384 private_handle_t *hnd = (private_handle_t *)layer->handle;
2385 if(!hnd) {
2386 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2387 return -1;
2388 }
2389
2390 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2391
radhakrishnac9a67412013-09-25 17:40:42 +05302392 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2393 hwc_rect_t dst = layer->displayFrame;
2394 int transform = layer->transform;
2395 eTransform orient = static_cast<eTransform>(transform);
2396 const int downscale = 0;
2397 int rotFlags = ROT_FLAGS_NONE;
2398 //Splitting only YUV layer on primary panel needs different zorders
2399 //for both layers as both the layers are configured to single mixer
2400 eZorder lz = z;
2401 eZorder rz = (eZorder)(z + 1);
2402
2403 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302404 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302405
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002406 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002407 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2408 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002409 }
2410
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002411 /* Calculate the external display position based on MDP downscale,
2412 ActionSafe, and extorientation features. */
2413 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2414
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002415 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302416 trimLayer(ctx, dpy, transform, crop, dst);
2417
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002418 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302419 (*rot) = ctx->mRotMgr->getNext();
2420 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002421 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302422 //Configure rotator for pre-rotation
2423 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2424 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302425 return -1;
2426 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002427 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302428 rotFlags |= ROT_PREROTATED;
2429 }
2430
2431 eMdpFlags mdpFlagsR = mdpFlagsL;
2432 int lSplit = dst.left + (dst.right - dst.left)/2;
2433
2434 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2435 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2436
2437 if(lDest != OV_INVALID) {
2438 tmp_cropL = crop;
2439 tmp_dstL = dst;
2440 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2441 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2442 }
2443 if(rDest != OV_INVALID) {
2444 tmp_cropR = crop;
2445 tmp_dstR = dst;
2446 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2447 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2448 }
2449
2450 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2451
2452 //When buffer is H-flipped, contents of mixer config also needs to swapped
2453 //Not needed if the layer is confined to one half of the screen.
2454 //If rotator has been used then it has also done the flips, so ignore them.
2455 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2456 && rDest != OV_INVALID && (*rot) == NULL) {
2457 hwc_rect_t new_cropR;
2458 new_cropR.left = tmp_cropL.left;
2459 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2460
2461 hwc_rect_t new_cropL;
2462 new_cropL.left = new_cropR.right;
2463 new_cropL.right = tmp_cropR.right;
2464
2465 tmp_cropL.left = new_cropL.left;
2466 tmp_cropL.right = new_cropL.right;
2467
2468 tmp_cropR.left = new_cropR.left;
2469 tmp_cropR.right = new_cropR.right;
2470
2471 }
2472
2473 //For the mdp, since either we are pre-rotating or MDP does flips
2474 orient = OVERLAY_TRANSFORM_0;
2475 transform = 0;
2476
2477 //configure left half
2478 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002479 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302480 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2481 (ovutils::eBlending) getBlending(layer->blending));
2482
2483 if(configMdp(ctx->mOverlay, pargL, orient,
2484 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2485 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2486 return -1;
2487 }
2488 }
2489
2490 //configure right half
2491 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002492 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302493 static_cast<eRotFlags>(rotFlags),
2494 layer->planeAlpha,
2495 (ovutils::eBlending) getBlending(layer->blending));
2496 if(configMdp(ctx->mOverlay, pargR, orient,
2497 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2498 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2499 return -1;
2500 }
2501 }
2502
2503 return 0;
2504}
2505
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002506bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302507 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002508 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002509 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302510 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302511 * in LINE and BLOCK modes for writeback panels.
2512 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002513 if(dpy == HWC_DISPLAY_PRIMARY)
2514 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002515 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302516 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2517 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002518 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002519 return true;
2520}
2521
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002522int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2523 //Default even split for all displays with high res
2524 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2525 if(dpy == HWC_DISPLAY_PRIMARY &&
2526 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2527 //Override if split published by driver for primary
2528 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2529 }
2530 return lSplit;
2531}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002532
Saurabh Shah88e4d272013-09-03 13:31:29 -07002533bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302534 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002535 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002536 return true;
2537 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302538 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002539 return true;
2540 }
2541 return false;
2542}
2543
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002544//clear prev layer prop flags and realloc for current frame
2545void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2546 if(ctx->layerProp[dpy]) {
2547 delete[] ctx->layerProp[dpy];
2548 ctx->layerProp[dpy] = NULL;
2549 }
2550 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2551}
2552
Ramakant Singh0def28c2014-03-28 20:43:13 +05302553bool isAbcInUse(hwc_context_t *ctx){
2554 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2555}
2556
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002557void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2558 if (ohnd != NULL && ohnd->base) {
2559 char dumpFilename[PATH_MAX];
2560 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002561 int width = getWidth(ohnd);
2562 int height = getHeight(ohnd);
2563 int format = ohnd->format;
2564 //dummy aligned w & h.
2565 int alW = 0, alH = 0;
2566 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002567 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2568 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002569 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2570 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002571 FILE* fp = fopen(dumpFilename, "w+");
2572 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002573 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002574 fclose(fp);
2575 }
2576 ALOGD("Buffer[%s] Dump to %s: %s",
2577 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2578 }
2579}
2580
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002581bool isGLESComp(hwc_context_t *ctx,
2582 hwc_display_contents_1_t* list) {
2583 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2584 for(int index = 0; index < numAppLayers; index++) {
2585 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2586 if(layer->compositionType == HWC_FRAMEBUFFER)
2587 return true;
2588 }
2589 return false;
2590}
2591
2592void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2593 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002594 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002595 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002596
2597#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002598 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2599 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2600 hint to default if the previous composition is GPU or current GPU
2601 composition is due to idle fallback */
2602 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2603 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2604 if(!gpuHint->mEGLDisplay) {
2605 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2606 return;
2607 }
2608 gpuHint->mEGLContext = eglGetCurrentContext();
2609 if(!gpuHint->mEGLContext) {
2610 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2611 return;
2612 }
2613 }
2614 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002615 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2616 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002617 EGLint attr_list[] = {EGL_GPU_HINT_1,
2618 EGL_GPU_LEVEL_3,
2619 EGL_NONE };
2620 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2621 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2622 gpuHint->mEGLContext, attr_list)) {
2623 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2624 } else {
2625 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002626 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002627 }
2628 } else {
2629 EGLint attr_list[] = {EGL_GPU_HINT_1,
2630 EGL_GPU_LEVEL_0,
2631 EGL_NONE };
2632 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2633 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2634 gpuHint->mEGLContext, attr_list)) {
2635 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2636 } else {
2637 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2638 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002639 if(MDPComp::isIdleFallback()) {
2640 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2641 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002642 }
2643 } else {
2644 /* set the GPU hint flag to default for MDP composition */
2645 EGLint attr_list[] = {EGL_GPU_HINT_1,
2646 EGL_GPU_LEVEL_0,
2647 EGL_NONE };
2648 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2649 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2650 gpuHint->mEGLContext, attr_list)) {
2651 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2652 } else {
2653 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2654 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002655 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002656 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002657#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002658}
2659
Sushil Chauhandefd3522014-05-13 18:17:12 -07002660bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2661 // To be peripheral, 3 boundaries should match.
2662 uint8_t eqBounds = 0;
2663 if (rect1.left == rect2.left)
2664 eqBounds++;
2665 if (rect1.top == rect2.top)
2666 eqBounds++;
2667 if (rect1.right == rect2.right)
2668 eqBounds++;
2669 if (rect1.bottom == rect2.bottom)
2670 eqBounds++;
2671 return (eqBounds == 3);
2672}
2673
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302674void processBootAnimCompleted(hwc_context_t *ctx) {
2675 char value[PROPERTY_VALUE_MAX];
2676 int boot_finished = 0, ret = -1;
2677 int (*applyMode)(int) = NULL;
2678 void *modeHandle = NULL;
2679
2680 // Reading property set on boot finish in SF
2681 property_get("service.bootanim.exit", value, "0");
2682 boot_finished = atoi(value);
2683 if (!boot_finished)
2684 return;
2685
2686 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2687 if (modeHandle) {
2688 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2689 if (applyMode) {
2690 ret = applyMode(HWC_DISPLAY_PRIMARY);
2691 if (ret)
2692 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2693 } else {
2694 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2695 }
2696 dlclose(modeHandle);
2697 } else {
2698 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
2699 }
2700
2701 ctx->mBootAnimCompleted = true;
2702}
2703
Saurabh Shahcd018352014-11-11 13:54:19 -08002704void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2705 const private_handle_t *hnd,
2706 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002707 const int& transform,const int& downscale,
2708 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002709 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302710 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002711 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002712 return;
2713 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002714 //Disabled at runtime
2715 if(not ctx->mBWCEnabled) return;
2716 //BWC not supported with rot-downscale
2717 if(downscale) return;
2718 //Not enabled for secondary displays
2719 if(dpy) return;
2720 //Not enabled for non-video buffers
2721 if(not isYuvBuffer(hnd)) return;
2722
Saurabh Shahb6810df2014-06-17 16:00:22 -07002723 int src_w = crop.right - crop.left;
2724 int src_h = crop.bottom - crop.top;
2725 int dst_w = dst.right - dst.left;
2726 int dst_h = dst.bottom - dst.top;
2727 if(transform & HAL_TRANSFORM_ROT_90) {
2728 swap(src_w, src_h);
2729 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002730 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002731 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002732 return;
2733 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002734 //Decimation necessary, cannot use BWC. H/W requirement.
2735 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002736 uint8_t horzDeci = 0;
2737 uint8_t vertDeci = 0;
2738 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2739 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002740 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002741 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002742
2743 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2744}
2745
Saurabh Shah23a813c2013-03-20 16:58:12 -07002746void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302747 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002748 mLayer[mCount] = layer;
2749 mRot[mCount] = rot;
2750 mCount++;
2751}
2752
2753void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302754 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002755 mLayer[i] = 0;
2756 mRot[i] = 0;
2757 }
2758 mCount = 0;
2759}
2760
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002761void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002762 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002763 reset();
2764}
2765
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302766bool LayerRotMap::isRotCached(uint32_t index) const {
2767 overlay::Rotator* rot = getRot(index);
2768 hwc_layer_1_t* layer = getLayer(index);
2769
2770 if(rot and layer and layer->handle) {
2771 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2772 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2773 }
2774 return false;
2775}
2776
Saurabh Shah23a813c2013-03-20 16:58:12 -07002777void LayerRotMap::setReleaseFd(const int& fence) {
2778 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302779 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2780 /* Ensure that none of the above (Rotator-instance,
2781 * layer and layer-handle) are NULL*/
2782 if(isRotCached(i))
2783 mRot[i]->setPrevBufReleaseFd(dup(fence));
2784 else
2785 mRot[i]->setCurrBufReleaseFd(dup(fence));
2786 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002787 }
2788}
2789
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002790hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2791 int lRoiWidth = 0, rRoiWidth = 0;
2792 int half_frame_width = fullFrame.right/2;
2793
2794 hwc_rect lFrame = fullFrame;
2795 hwc_rect rFrame = fullFrame;
2796 lFrame.right = (lFrame.right - lFrame.left)/2;
2797 rFrame.left = lFrame.right;
2798
2799 hwc_rect lRoi = getIntersection(roi, lFrame);
2800 hwc_rect rRoi = getIntersection(roi, rFrame);
2801
2802 lRoiWidth = lRoi.right - lRoi.left;
2803 rRoiWidth = rRoi.right - rRoi.left;
2804
2805 if(lRoiWidth && rRoiWidth) {
2806 if(lRoiWidth < rRoiWidth)
2807 roi.left = half_frame_width - rRoiWidth;
2808 else
2809 roi.right = half_frame_width + lRoiWidth;
2810 }
2811 return roi;
2812}
2813
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002814void resetROI(hwc_context_t *ctx, const int dpy) {
2815 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2816 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
2817 if(isDisplaySplit(ctx, dpy)) {
2818 const int lSplit = getLeftSplit(ctx, dpy);
2819 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2820 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2821 } else {
2822 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2823 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2824 }
2825}
2826
2827hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002828{
2829 if(!isValidRect(roi))
2830 return roi;
2831
2832 struct hwc_rect t_roi = roi;
2833
2834 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2835 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2836 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2837 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2838 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002839 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002840
2841 /* Align to minimum width recommended by the panel */
2842 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2843 if((t_roi.left + MIN_WIDTH) > boundary.right)
2844 t_roi.left = t_roi.right - MIN_WIDTH;
2845 else
2846 t_roi.right = t_roi.left + MIN_WIDTH;
2847 }
2848
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002849 /* Align to minimum height recommended by the panel */
2850 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2851 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2852 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2853 else
2854 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2855 }
2856
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002857 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002858 if(LEFT_ALIGN)
2859 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2860
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002861 if(WIDTH_ALIGN) {
2862 int width = t_roi.right - t_roi.left;
2863 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2864 t_roi.right = t_roi.left + width;
2865
2866 if(t_roi.right > boundary.right) {
2867 t_roi.right = boundary.right;
2868 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002869
2870 if(LEFT_ALIGN)
2871 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002872 }
2873 }
2874
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002875
2876 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002877 if(TOP_ALIGN)
2878 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2879
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002880 if(HEIGHT_ALIGN) {
2881 int height = t_roi.bottom - t_roi.top;
2882 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2883 t_roi.bottom = t_roi.top + height;
2884
2885 if(t_roi.bottom > boundary.bottom) {
2886 t_roi.bottom = boundary.bottom;
2887 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002888
2889 if(TOP_ALIGN)
2890 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002891 }
2892 }
2893
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002894
2895 return t_roi;
2896}
2897
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002898void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002899 if(ctx->dpyAttr[dpy].connected) {
2900 ctx->mDrawLock.lock();
2901 ctx->dpyAttr[dpy].isActive = true;
2902 ctx->dpyAttr[dpy].isPause = true;
2903 ctx->mDrawLock.unlock();
2904 ctx->proc->invalidate(ctx->proc);
2905
2906 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2907 * 2 / 1000);
2908
2909 // At this point all the pipes used by External have been
2910 // marked as UNSET.
2911 ctx->mDrawLock.lock();
2912 // Perform commit to unstage the pipes.
2913 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2914 ALOGE("%s: display commit fail! for %d dpy",
2915 __FUNCTION__, dpy);
2916 }
2917 ctx->mDrawLock.unlock();
2918 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002919 }
2920 return;
2921}
2922
2923void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002924 if(ctx->dpyAttr[dpy].connected) {
2925 ctx->mDrawLock.lock();
2926 ctx->dpyAttr[dpy].isConfiguring = true;
2927 ctx->dpyAttr[dpy].isActive = true;
2928 ctx->mDrawLock.unlock();
2929 ctx->proc->invalidate(ctx->proc);
2930
2931 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2932 * 2 / 1000);
2933
2934 //At this point external has all the pipes it would need.
2935 ctx->mDrawLock.lock();
2936 ctx->dpyAttr[dpy].isPause = false;
2937 ctx->mDrawLock.unlock();
2938 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002939 }
2940 return;
2941}
2942
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002943void clearPipeResources(hwc_context_t* ctx, int dpy) {
2944 if(ctx->mOverlay) {
2945 ctx->mOverlay->configBegin();
2946 ctx->mOverlay->configDone();
2947 }
2948 if(ctx->mRotMgr) {
2949 ctx->mRotMgr->clear();
2950 }
2951 // Call a display commit to ensure that pipes and associated
2952 // fd's are cleaned up.
2953 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2954 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2955 }
2956}
2957
2958// Handles online events when HDMI is the primary display. In particular,
2959// online events for hdmi connected before AND after boot up and HWC init.
2960void handle_online(hwc_context_t* ctx, int dpy) {
2961 // Close the current fd if it was opened earlier on when HWC
2962 // was initialized.
2963 if (ctx->dpyAttr[dpy].fd >= 0) {
2964 close(ctx->dpyAttr[dpy].fd);
2965 ctx->dpyAttr[dpy].fd = -1;
2966 }
2967 // TODO: If HDMI is connected after the display has booted up,
2968 // and the best configuration is different from the default
2969 // then we need to deal with this appropriately.
2970 ctx->mHDMIDisplay->configure();
2971 updateDisplayInfo(ctx, dpy);
2972 initCompositionResources(ctx, dpy);
2973 ctx->dpyAttr[dpy].connected = true;
2974}
2975
2976// Handles offline events for HDMI. This can be used for offline events
2977// initiated by the HDMI driver and the CEC framework.
2978void handle_offline(hwc_context_t* ctx, int dpy) {
2979 destroyCompositionResources(ctx, dpy);
2980 // Clear all pipe resources and call a display commit to ensure
2981 // that all the fd's are closed. This will ensure that the HDMI
2982 // core turns off and that we receive an event the next time the
2983 // cable is connected.
2984 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
2985 clearPipeResources(ctx, dpy);
2986 }
2987 ctx->mHDMIDisplay->teardown();
2988 resetDisplayInfo(ctx, dpy);
2989 ctx->dpyAttr[dpy].connected = false;
2990 ctx->dpyAttr[dpy].isActive = false;
2991}
2992
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002993int convertS3DFormatToMode(int s3DFormat) {
2994 int ret;
2995 switch(s3DFormat) {
2996 case HAL_3D_SIDE_BY_SIDE_L_R:
2997 case HAL_3D_SIDE_BY_SIDE_R_L:
2998 ret = HDMI_S3D_SIDE_BY_SIDE;
2999 break;
3000 case HAL_3D_TOP_BOTTOM:
3001 ret = HDMI_S3D_TOP_AND_BOTTOM;
3002 break;
3003 default:
3004 ret = HDMI_S3D_NONE;
3005 }
3006 return ret;
3007}
3008
3009bool needs3DComposition(hwc_context_t* ctx, int dpy) {
3010 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
3011 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3012}
3013
3014void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3015 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3016 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3017 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3018 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3019 }
3020 }
3021}
3022
3023bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3024 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3025 ((dpy == HWC_DISPLAY_PRIMARY) &&
3026 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3027}
3028
3029
Saurabh Shahacf10202013-02-26 10:15:15 -08003030};//namespace qhwc