blob: d176cd37d276715343a173dd96d414d9fc5ed486 [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
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053089bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
90{
Jeykumar Sankaran39305802014-12-12 17:55:57 -080091 return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053092 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
93 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
94}
95
Praveena Pachipulusu49d62062014-06-06 19:22:23 +053096void changeResolution(hwc_context_t *ctx, int xres_orig, int yres_orig,
97 int width, int height) {
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053098 //Store original display resolution.
Dileep Kumar Reddie351d842014-03-25 10:39:21 +053099 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_orig;
100 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_orig;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530101 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530102 char property[PROPERTY_VALUE_MAX] = {'\0'};
103 char *yptr = NULL;
104 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
105 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530106 if(yptr) {
107 int xres_new = atoi(property);
108 int yres_new = atoi(yptr + 1);
109 if (isValidResolution(ctx,xres_new,yres_new) &&
110 xres_new != xres_orig && yres_new != yres_orig) {
111 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_new;
112 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_new;
113 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530114
Raj Kamal4a443082014-10-12 21:07:59 +0530115 //Caluculate DPI according to changed resolution.
116 float xdpi = ((float)xres_new * 25.4f) / (float)width;
117 float ydpi = ((float)yres_new * 25.4f) / (float)height;
118 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
119 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
120 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530121 }
122 }
123}
124
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700125// Initialize hdmi display attributes based on
126// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700127void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700128 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
129 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
130 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
131 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
132 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700133 //FIXME: for now assume HDMI as secure
134 //Will need to read the HDCP status from the driver
135 //and update this accordingly
136 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700137 ctx->mViewFrame[dpy].left = 0;
138 ctx->mViewFrame[dpy].top = 0;
139 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
140 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
141}
142
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700143// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700144void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
145 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
146 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
147 // We reset the fd to -1 here but External display class is responsible
148 // for it when the display is disconnected. This is handled as part of
149 // EXTERNAL_OFFLINE event.
150 ctx->dpyAttr[dpy].fd = -1;
151}
152
153// Initialize composition resources
154void initCompositionResources(hwc_context_t* ctx, int dpy) {
155 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
156 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
157}
158
159void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
160 if(ctx->mFBUpdate[dpy]) {
161 delete ctx->mFBUpdate[dpy];
162 ctx->mFBUpdate[dpy] = NULL;
163 }
164 if(ctx->mMDPComp[dpy]) {
165 delete ctx->mMDPComp[dpy];
166 ctx->mMDPComp[dpy] = NULL;
167 }
168}
169
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800170static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700171{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800172 struct fb_fix_screeninfo finfo;
173 struct fb_var_screeninfo info;
174
175 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530176 if(fb_fd < 0) {
177 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800178 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530179 }
180
181 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
182 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
183 strerror(errno));
184 close(fb_fd);
185 return -errno;
186 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800187
188 if (int(info.width) <= 0 || int(info.height) <= 0) {
189 // the driver doesn't return that information
190 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530191 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
192 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700193 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800194
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530195 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
196 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800197
198#ifdef MSMFB_METADATA_GET
199 struct msmfb_metadata metadata;
200 memset(&metadata, 0 , sizeof(metadata));
201 metadata.op = metadata_op_frame_rate;
202
203 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530204 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
205 strerror(errno));
206 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800207 return -errno;
208 }
209
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530210 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800211#else
212 //XXX: Remove reserved field usage on all baselines
213 //The reserved[3] field is used to store FPS by the driver.
214 float fps = info.reserved[3] & 0xFF;
215#endif
216
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530217 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
218 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
219 strerror(errno));
220 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800221 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530222 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800223
224 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
225 //xres, yres may not be 32 aligned
226 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
227 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
228 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
229 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
230 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700231 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
232 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700233 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530234 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
235 (uint32_t)(1000000000l / fps);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800236
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530237 //To change resolution of primary display
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530238 changeResolution(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530239
Naseer Ahmed22616d92013-05-15 17:20:26 -0400240 //Unblank primary on first boot
241 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
242 ALOGE("%s: Failed to unblank display", __FUNCTION__);
243 return -errno;
244 }
245 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
246
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800247 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700248}
249
Ramakant Singh98c533c2014-09-30 19:01:54 +0530250static void changeDefaultAppBufferCount() {
251 struct sysinfo info;
252 unsigned long int ramSize = 0;
253 if (!sysinfo(&info)) {
254 ramSize = info.totalram ;
255 }
256 int fb_fd = -1;
257 struct fb_var_screeninfo sInfo ={0};
258 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
259 if (fb_fd >=0) {
260 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
261 close(fb_fd);
262 }
263 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
264 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
265 property_set(PROP_DEFAULT_APPBUFFER, "2");
266 }
267}
268
Naseer Ahmed29a26812012-06-14 00:56:20 -0700269void initContext(hwc_context_t *ctx)
270{
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700271 overlay::Overlay::initOverlay();
272 ctx->mHDMIDisplay = new HDMIDisplay();
273 uint32_t priW = 0, priH = 0;
274 // 1. HDMI as Primary
275 // -If HDMI cable is connected, read display configs from edid data
276 // -If HDMI cable is not connected then use default data in vscreeninfo
277 // 2. HDMI as External
278 // -Initialize HDMI class for use with external display
279 // -Use vscreeninfo to populate display configs
280 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
281 int connected = ctx->mHDMIDisplay->getConnectedState();
282 if(connected == 1) {
283 ctx->mHDMIDisplay->configure();
284 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
285 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
286 } else {
287 openFramebufferDevice(ctx);
288 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
289 }
290 } else {
291 openFramebufferDevice(ctx);
292 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
293 // Send the primary resolution to the hdmi display class
294 // to be used for MDP scaling functionality
295 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
296 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
297 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
298 }
299
Raj kamal59fea562014-04-01 16:52:19 +0530300 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700301 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
302 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
303 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800304 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800305 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800306 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800307
Ramakant Singh98c533c2014-09-30 19:01:54 +0530308 //default_app_buffer for ferrum
309 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
310 changeDefaultAppBufferCount();
311 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700312 // Initialize composition objects for the primary display
313 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800314
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800315 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800316 // decide if we need to open the copybit module.
317 int compositionType =
318 qdutils::QCCompositionType::getInstance().getCompositionType();
319
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800320 // Only MDP copybit is used
321 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
322 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530323 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
324 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800325 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530326 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800327 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
328 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800329 }
330
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700331 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700332 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
333 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
334 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
335 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700336 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
337 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
338 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800339
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700340 //Initialize the primary display viewFrame info
341 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
342 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
343 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
344 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
345 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
346 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530347
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700348 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700349 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700350 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700351 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800352 ctx->dpyAttr[i].mActionSafePresent = false;
353 ctx->dpyAttr[i].mAsWidthRatio = 0;
354 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500355 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
356 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700357 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700358
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500359 //Make sure that the 3D mode is unset at bootup
360 //This makes sure that the state is accurate on framework reboots
361 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
362
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530363 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
364 ctx->mPrevHwLayerCount[i] = 0;
365 }
366
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500367 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700368 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700369
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400370 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500371 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700372 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530373 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800374
375 //Right now hwc starts the service but anybody could do it, or it could be
376 //independent process as well.
377 QService::init();
378 sp<IQClient> client = new QClient(ctx);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400379 sp<IQService> iqs = interface_cast<IQService>(
Saurabh Shah86c17292013-02-08 15:24:13 -0800380 defaultServiceManager()->getService(
Charles Bindab39382014-06-30 10:34:30 -0700381 String16("display.qservice")));
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400382 if (iqs.get()) {
383 iqs->connect(client);
384 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
Charles Bindab39382014-06-30 10:34:30 -0700385 } else {
386 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400387 return;
Charles Bindab39382014-06-30 10:34:30 -0700388 }
Saurabh Shah86c17292013-02-08 15:24:13 -0800389
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700390 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700391 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700392 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400393
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700394 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
395 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
396
Ramakant Singh0def28c2014-03-28 20:43:13 +0530397 ctx->enableABC = false;
398 property_get("debug.sf.hwc.canUseABC", value, "0");
399 ctx->enableABC = atoi(value) ? true : false;
400
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530401 // Initializing boot anim completed check to false
402 ctx->mBootAnimCompleted = false;
403
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700404 // Initialize gpu perfomance hint related parameters
405 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700406#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700407 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
408
409 ctx->mGPUHintInfo.mEGLDisplay = NULL;
410 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700411 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700412 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700413#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700414 // Read the system property to determine if windowboxing feature is enabled.
415 ctx->mWindowboxFeature = false;
416 if(property_get("sys.hwc.windowbox_feature", value, "false")
417 && !strcmp(value, "true")) {
418 ctx->mWindowboxFeature = true;
419 }
420
Raj Kamal0d53fc62014-11-25 17:36:36 +0530421 ctx->mUseMetaDataRefreshRate = true;
422 if(property_get("persist.metadata_dynfps.disable", value, "false")
423 && !strcmp(value, "true")) {
424 ctx->mUseMetaDataRefreshRate = false;
425 }
426
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700427 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800428 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700429 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700430 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700431}
432
433void closeContext(hwc_context_t *ctx)
434{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500435 if(ctx->mOverlay) {
436 delete ctx->mOverlay;
437 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700438 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700439
Saurabh Shahacf10202013-02-26 10:15:15 -0800440 if(ctx->mRotMgr) {
441 delete ctx->mRotMgr;
442 ctx->mRotMgr = NULL;
443 }
444
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700445 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800446 if(ctx->mCopyBit[i]) {
447 delete ctx->mCopyBit[i];
448 ctx->mCopyBit[i] = NULL;
449 }
450 }
451
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800452 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700453 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
454 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700455 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700456
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700457 if(ctx->mHDMIDisplay) {
458 delete ctx->mHDMIDisplay;
459 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700460 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400461
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700462 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700463 destroyCompositionResources(ctx, i);
464
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700465 if(ctx->mHwcDebug[i]) {
466 delete ctx->mHwcDebug[i];
467 ctx->mHwcDebug[i] = NULL;
468 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700469 if(ctx->mLayerRotMap[i]) {
470 delete ctx->mLayerRotMap[i];
471 ctx->mLayerRotMap[i] = NULL;
472 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800473 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800474 if(ctx->mHWCVirtual) {
475 delete ctx->mHWCVirtual;
476 ctx->mHWCVirtual = NULL;
477 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700478 if(ctx->mAD) {
479 delete ctx->mAD;
480 ctx->mAD = NULL;
481 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800482
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400483 if(ctx->mQService) {
484 delete ctx->mQService;
485 ctx->mQService = NULL;
486 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700487}
488
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700489//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530490uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700491 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
492 uint32_t rate = refreshRate;
493 for(int i=0; i< count; i++) {
494 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
495 // Most likely used for video, the fps can fluctuate
496 // Ex: b/w 29 and 30 for 30 fps clip
497 rate = stdRefreshRates[i];
498 break;
499 }
500 }
501 return rate;
502}
503
504//Helper func to set the dyn fps
505void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
506 //Update only if different
507 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
508 return;
509 const int fbNum = Overlay::getFbForDpy(dpy);
510 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
511 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800512 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700513
514 int fd = open(sysfsPath, O_WRONLY);
515 if(fd >= 0) {
516 char str[64];
517 snprintf(str, sizeof(str), "%d", refreshRate);
518 ssize_t ret = write(fd, str, strlen(str));
519 if(ret < 0) {
520 ALOGE("%s: Failed to write %d with error %s",
521 __FUNCTION__, refreshRate, strerror(errno));
522 } else {
523 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
524 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
525 __FUNCTION__, refreshRate);
526 }
527 close(fd);
528 } else {
529 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
530 strerror(errno));
531 }
532}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500533
534void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700535{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500536 va_list varargs;
537 va_start(varargs, fmt);
538 buf.appendFormatV(fmt, varargs);
539 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700540}
541
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700542int getExtOrientation(hwc_context_t* ctx) {
543 int extOrient = ctx->mExtOrientation;
544 if(ctx->mBufferMirrorMode)
545 extOrient = getMirrorModeOrientation(ctx);
546 return extOrient;
547}
548
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800549/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700550void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
551 // Position
552 int x = rect.left, y = rect.top;
553 int w = rect.right - rect.left;
554 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800555
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800556 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800557 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800558 // Read action safe properties
559 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
560 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700561
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800562 float wRatio = 1.0;
563 float hRatio = 1.0;
564 float xRatio = 1.0;
565 float yRatio = 1.0;
566
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700567 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
568 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700569 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
570 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700571 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700572 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700573 }
574
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800575
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700576 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700577 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700578
579 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700580 swap(fbWidth, fbHeight);
581
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800582 float asX = 0;
583 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530584 float asW = (float)fbWidth;
585 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800586
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800587 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530588 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
589 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
590 asX = ((float)fbWidth - asW) / 2;
591 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800592
593 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530594 xRatio = (float)x/(float)fbWidth;
595 yRatio = (float)y/(float)fbHeight;
596 wRatio = (float)w/(float)fbWidth;
597 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800598
599 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530600 x = int((xRatio * asW) + asX);
601 y = int((yRatio * asH) + asY);
602 w = int(wRatio * asW);
603 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800604
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700605 // Convert it back to hwc_rect_t
606 rect.left = x;
607 rect.top = y;
608 rect.right = w + rect.left;
609 rect.bottom = h + rect.top;
610
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800611 return;
612}
613
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700614// This function gets the destination position for Seconday display
615// based on the position and aspect ratio with orientation
616void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
617 hwc_rect_t& inRect, hwc_rect_t& outRect) {
618 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530619 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
620 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700621 //display position(x,y,w,h) in correct aspectratio after rotation
622 int xPos = 0;
623 int yPos = 0;
624 float width = fbWidth;
625 float height = fbHeight;
626 // Width/Height used for calculation, after rotation
627 float actualWidth = fbWidth;
628 float actualHeight = fbHeight;
629
630 float wRatio = 1.0;
631 float hRatio = 1.0;
632 float xRatio = 1.0;
633 float yRatio = 1.0;
634 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
635
636 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
637 inRect.bottom - inRect.top);
638 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
639 outRect.bottom - outRect.top);
640
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530641 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700642 eTransform extorient = static_cast<eTransform>(extOrientation);
643 // To calculate the destination co-ordinates in the new orientation
644 preRotateSource(extorient, whf, inPos);
645
646 if(extOrientation & HAL_TRANSFORM_ROT_90) {
647 // Swap width/height for input position
648 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700649 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
650 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700651 xPos = rect.left;
652 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530653 width = float(rect.right - rect.left);
654 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700655 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700656 xRatio = (float)((float)inPos.x/actualWidth);
657 yRatio = (float)((float)inPos.y/actualHeight);
658 wRatio = (float)((float)inPos.w/actualWidth);
659 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800660
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530661 //Calculate the pos9ition...
662 outPos.x = uint32_t((xRatio * width) + (float)xPos);
663 outPos.y = uint32_t((yRatio * height) + (float)yPos);
664 outPos.w = uint32_t(wRatio * width);
665 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700666 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
667 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
668 outPos.w, outPos.h);
669
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700670 // For sidesync, the dest fb will be in portrait orientation, and the crop
671 // will be updated to avoid the black side bands, and it will be upscaled
672 // to fit the dest RB, so recalculate
673 // the position based on the new width and height
674 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
675 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800676 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700677 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530678 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700679 // GetaspectRatio -- tricky to get the correct aspect ratio
680 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700681 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530682 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700683 xPos = r.left;
684 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530685 float tempHeight = float(r.bottom - r.top);
686 yRatio = (float)yPos/height;
687 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700688 hRatio = tempHeight/height;
689
690 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530691 outPos.x = uint32_t(xRatio * fbWidth);
692 outPos.y = uint32_t(yRatio * fbHeight);
693 outPos.w = uint32_t(wRatio * fbWidth);
694 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700695
696 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
697 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
698 outPos.x, outPos.y,
699 outPos.w, outPos.h);
700 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700701 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700702 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700703 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700704 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700705 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
706 extW = ctx->mHWCVirtual->getScalingWidth();
707 extH = ctx->mHWCVirtual->getScalingHeight();
708 }
709 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
710 __FUNCTION__, extW, extH);
711
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530712 fbWidth = (float)ctx->dpyAttr[dpy].xres;
713 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700714 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530715 xRatio = (float)outPos.x/fbWidth;
716 yRatio = (float)outPos.y/fbHeight;
717 wRatio = (float)outPos.w/fbWidth;
718 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700719
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530720 outPos.x = uint32_t(xRatio * (float)extW);
721 outPos.y = uint32_t(yRatio * (float)extH);
722 outPos.w = uint32_t(wRatio * (float)extW);
723 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700724 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700725 // Convert Dim to hwc_rect_t
726 outRect.left = outPos.x;
727 outRect.top = outPos.y;
728 outRect.right = outPos.x + outPos.w;
729 outRect.bottom = outPos.y + outPos.h;
730
731 return;
732}
733
734bool isPrimaryPortrait(hwc_context_t *ctx) {
735 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
736 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
737 if(fbWidth < fbHeight) {
738 return true;
739 }
740 return false;
741}
742
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700743bool isOrientationPortrait(hwc_context_t *ctx) {
744 if(isPrimaryPortrait(ctx)) {
745 return !(ctx->deviceOrientation & 0x1);
746 }
747 return (ctx->deviceOrientation & 0x1);
748}
749
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700750void calcExtDisplayPosition(hwc_context_t *ctx,
751 private_handle_t *hnd,
752 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700753 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700754 hwc_rect_t& displayFrame,
755 int& transform,
756 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700757 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700758 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530759 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700760 if(!isYuvBuffer(hnd)) {
761 if(extOrient & HWC_TRANSFORM_ROT_90) {
762 int dstWidth = ctx->dpyAttr[dpy].xres;
763 int dstHeight = ctx->dpyAttr[dpy].yres;;
764 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
765 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
766 if(!isPrimaryPortrait(ctx)) {
767 swap(srcWidth, srcHeight);
768 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700769 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700770 srcHeight, displayFrame);
771 // Crop - this is needed, because for sidesync, the dest fb will
772 // be in portrait orientation, so update the crop to not show the
773 // black side bands.
774 if (isOrientationPortrait(ctx)) {
775 sourceCrop = displayFrame;
776 displayFrame.left = 0;
777 displayFrame.top = 0;
778 displayFrame.right = dstWidth;
779 displayFrame.bottom = dstHeight;
780 }
781 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700782 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700783 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700784 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700785 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530786 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
787 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700788 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700789 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700790 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700791 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
792 extW = ctx->mHWCVirtual->getScalingWidth();
793 extH = ctx->mHWCVirtual->getScalingHeight();
794 }
795 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
796 __FUNCTION__, extW, extH);
797
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700798 //Calculate the ratio...
799 float wRatio = ((float)extW)/fbWidth;
800 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700801
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700802 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530803 displayFrame.left = int(wRatio*(float)displayFrame.left);
804 displayFrame.top = int(hRatio*(float)displayFrame.top);
805 displayFrame.right = int(wRatio*(float)displayFrame.right);
806 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700807 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
808 " for MDPDownscale feature [%d %d %d %d]",
809 displayFrame.left, displayFrame.top,
810 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700811 }
812 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700813 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700814 getAspectRatioPosition(ctx, dpy, extOrient,
815 displayFrame, displayFrame);
816 }
817 }
818 // If there is a external orientation set, use that
819 if(extOrient) {
820 transform = extOrient;
821 orient = static_cast<ovutils::eTransform >(extOrient);
822 }
823 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
824 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700825 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700826}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700827
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700828/* Returns the orientation which needs to be set on External for
829 * SideSync/Buffer Mirrormode
830 */
831int getMirrorModeOrientation(hwc_context_t *ctx) {
832 int extOrientation = 0;
833 int deviceOrientation = ctx->deviceOrientation;
834 if(!isPrimaryPortrait(ctx))
835 deviceOrientation = (deviceOrientation + 1) % 4;
836 if (deviceOrientation == 0)
837 extOrientation = HWC_TRANSFORM_ROT_270;
838 else if (deviceOrientation == 1)//90
839 extOrientation = 0;
840 else if (deviceOrientation == 2)//180
841 extOrientation = HWC_TRANSFORM_ROT_90;
842 else if (deviceOrientation == 3)//270
843 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
844
845 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700846}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700847
Raj kamal59fea562014-04-01 16:52:19 +0530848/* Get External State names */
849const char* getExternalDisplayState(uint32_t external_state) {
850 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
851 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
852 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
853 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
854 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
855
856 if(external_state >= EXTERNAL_MAXSTATES) {
857 return "EXTERNAL_INVALID";
858 }
859
860 return externalStates[external_state];
861}
862
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530863bool isDownscaleRequired(hwc_layer_1_t const* layer) {
864 hwc_rect_t displayFrame = layer->displayFrame;
865 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
866 int dst_w, dst_h, src_w, src_h;
867 dst_w = displayFrame.right - displayFrame.left;
868 dst_h = displayFrame.bottom - displayFrame.top;
869 src_w = sourceCrop.right - sourceCrop.left;
870 src_h = sourceCrop.bottom - sourceCrop.top;
871
872 if(((src_w > dst_w) || (src_h > dst_h)))
873 return true;
874
875 return false;
876}
877bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500878 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500879 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700880 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500881
882 dst_w = displayFrame.right - displayFrame.left;
883 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500884 src_w = sourceCrop.right - sourceCrop.left;
885 src_h = sourceCrop.bottom - sourceCrop.top;
886
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800887 if(layer->transform & HWC_TRANSFORM_ROT_90)
888 swap(src_w, src_h);
889
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800890 if(((src_w != dst_w) || (src_h != dst_h)))
891 return true;
892
893 return false;
894}
895
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700896// Checks if layer needs scaling with split
897bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
898 const int& dpy) {
899
900 int src_width_l, src_height_l;
901 int src_width_r, src_height_r;
902 int dst_width_l, dst_height_l;
903 int dst_width_r, dst_height_r;
904 int hw_w = ctx->dpyAttr[dpy].xres;
905 int hw_h = ctx->dpyAttr[dpy].yres;
906 hwc_rect_t cropL, dstL, cropR, dstR;
907 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700908 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700909 hwc_rect_t displayFrame = layer->displayFrame;
910 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700911
912 cropL = sourceCrop;
913 dstL = displayFrame;
914 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800915 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700916 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
917
918 cropR = sourceCrop;
919 dstR = displayFrame;
920 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800921 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700922 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
923
924 // Sanitize Crop to stitch
925 sanitizeSourceCrop(cropL, cropR, hnd);
926
927 // Calculate the left dst
928 dst_width_l = dstL.right - dstL.left;
929 dst_height_l = dstL.bottom - dstL.top;
930 src_width_l = cropL.right - cropL.left;
931 src_height_l = cropL.bottom - cropL.top;
932
933 // check if there is any scaling on the left
934 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
935 return true;
936
937 // Calculate the right dst
938 dst_width_r = dstR.right - dstR.left;
939 dst_height_r = dstR.bottom - dstR.top;
940 src_width_r = cropR.right - cropR.left;
941 src_height_r = cropR.bottom - cropR.top;
942
943 // check if there is any scaling on the right
944 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
945 return true;
946
947 return false;
948}
949
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530950bool isAlphaScaled(hwc_layer_1_t const* layer) {
951 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530952 return true;
953 }
954 return false;
955}
956
957bool isAlphaPresent(hwc_layer_1_t const* layer) {
958 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400959 if(hnd) {
960 int format = hnd->format;
961 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530962 case HAL_PIXEL_FORMAT_RGBA_8888:
963 case HAL_PIXEL_FORMAT_BGRA_8888:
964 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500965 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530966 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400967 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500968 }
969 return false;
970}
971
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700972static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
973 hwc_rect_t& crop, hwc_rect_t& dst) {
974 int hw_w = ctx->dpyAttr[dpy].xres;
975 int hw_h = ctx->dpyAttr[dpy].yres;
976 if(dst.left < 0 || dst.top < 0 ||
977 dst.right > hw_w || dst.bottom > hw_h) {
978 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800979 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700980 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
981 }
982}
983
984static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
985 const int& dpy) {
986 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
987 hwc_layer_1_t *layer = &list->hwLayers[i];
988 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700989 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
990 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700991 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700992 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700993 (hwc_rect_t&)crop,
994 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530995 layer->sourceCropf.left = (float)crop.left;
996 layer->sourceCropf.right = (float)crop.right;
997 layer->sourceCropf.top = (float)crop.top;
998 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700999 }
1000}
1001
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001002void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001003 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001004 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1005 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301006 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1007 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001008 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301009 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001010 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001011 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001012 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001013 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001014 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301015 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001016 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301017 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001018 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001019 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1020 uint32_t refreshRate = 0;
1021 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001022 int s3dFormat = HAL_NO_3D;
1023 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001024
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001025 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001026 resetROI(ctx, dpy);
1027
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001028 trimList(ctx, list, dpy);
1029 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001030 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001031 hwc_layer_1_t const* layer = &list->hwLayers[i];
1032 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001033
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001034#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001035 // Window boxing feature is applicable obly for external display, So
1036 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001037 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001038 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001039 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001040 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1041 ctx->listStats[dpy].isDisplayAnimating = true;
1042 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001043 if(isSecureDisplayBuffer(hnd)) {
1044 ctx->listStats[dpy].secureUI = true;
1045 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001046#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001047 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1048 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001049 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001050
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001051 //reset yuv indices
1052 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301053 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001054
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001055 if (isSecureBuffer(hnd)) {
1056 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001057 if(not isYuvBuffer(hnd)) {
1058 // cache secureRGB layer parameters like we cache for YUV layers
1059 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1060 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1061 secureRGBCount++;
1062 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001063 }
1064
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001065 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001066 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001067 }
1068
1069 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001070 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301071 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001072 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001073
Raj Kamal389d6e32014-08-04 14:43:24 +05301074 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301075 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301076 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301077 yuv4k2kCount++;
1078 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001079
1080 // Gets set if one YUV layer is 3D
1081 if (displaySupports3D(ctx,dpy)) {
1082 s3dFormat = get3DFormat(hnd);
1083 if(s3dFormat != HAL_NO_3D)
1084 s3dLayerCount++;
1085 }
1086
Naseer Ahmed29a26812012-06-14 00:56:20 -07001087 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301088 if(layer->blending == HWC_BLENDING_PREMULT)
1089 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001090
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001091#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301092 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001093 //dyn fps: get refreshrate from metadata
1094 //Support multiple refresh rates if they are same
1095 //else set to default
1096 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1097 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1098 // Valid refreshRate in metadata and within the range
1099 uint32_t rate = roundOff(mdata->refreshrate);
1100 if((rate >= mdpHw.getMinFpsSupported() &&
1101 rate <= mdpHw.getMaxFpsSupported())) {
1102 if (!refreshRate) {
1103 refreshRate = rate;
1104 } else if(refreshRate != rate) {
1105 // multiple refreshrate requests, set to default
1106 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1107 }
1108 }
1109 }
1110 }
1111#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001112 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001113
1114 //Set the TV's 3D mode based on format if it was not forced
1115 //Only one 3D YUV layer is supported on external
1116 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1117 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1118 //XXX: Rapidly going in and out of 3D mode in some cases such
1119 // as rotation might cause flickers. The OEMs are recommended to disable
1120 // rotation on HDMI globally or in the app that plays 3D video
1121 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1122 }
1123
Ping Li9404e2a2013-04-24 16:36:03 -04001124 if(ctx->listStats[dpy].yuvCount > 0) {
1125 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1126 if (atoi(property) != 1) {
1127 property_set("hw.cabl.yuv", "1");
1128 }
1129 }
1130 } else {
1131 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1132 if (atoi(property) != 0) {
1133 property_set("hw.cabl.yuv", "0");
1134 }
1135 }
1136 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001137
1138 //The marking of video begin/end is useful on some targets where we need
1139 //to have a padding round to be able to shift pipes across mixers.
1140 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1141 ctx->mVideoTransFlag = true;
1142 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301143
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001144 if(dpy == HWC_DISPLAY_PRIMARY) {
1145 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001146 //Store the requested fresh rate
1147 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1148 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001149 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001150}
1151
Naseer Ahmed018e5452012-12-03 14:46:15 -05001152
Saurabh Shah68107422013-07-09 11:12:42 -07001153static void calc_cut(double& leftCutRatio, double& topCutRatio,
1154 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001155 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001156 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001157 }
1158 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001159 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001160 }
1161 if(orient & HAL_TRANSFORM_ROT_90) {
1162 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001163 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001164 leftCutRatio = topCutRatio;
1165 topCutRatio = rightCutRatio;
1166 rightCutRatio = bottomCutRatio;
1167 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001168 }
1169}
1170
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001171bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001172 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1173 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1174 ctx->mSecuring) {
1175 return true;
1176 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001177 if (isSecureModePolicy(ctx->mMDP.version)) {
1178 private_handle_t *hnd = (private_handle_t *)layer->handle;
1179 if(ctx->mSecureMode) {
1180 if (! isSecureBuffer(hnd)) {
1181 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1182 __FUNCTION__);
1183 return true;
1184 }
1185 } else {
1186 if (isSecureBuffer(hnd)) {
1187 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1188 __FUNCTION__);
1189 return true;
1190 }
1191 }
1192 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001193 return false;
1194}
1195
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001196bool isSecureModePolicy(int mdpVersion) {
1197 if (mdpVersion < qdutils::MDSS_V5)
1198 return true;
1199 else
1200 return false;
1201}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001202
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001203bool isRotatorSupportedFormat(private_handle_t *hnd) {
1204 // Following rotator src formats are supported by mdp driver
1205 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001206 if(hnd != NULL) {
1207 switch(hnd->format) {
1208 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001209 case HAL_PIXEL_FORMAT_RGBA_5551:
1210 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001211 case HAL_PIXEL_FORMAT_RGB_565:
1212 case HAL_PIXEL_FORMAT_RGB_888:
1213 case HAL_PIXEL_FORMAT_BGRA_8888:
1214 return true;
1215 default:
1216 return false;
1217 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001218 }
1219 return false;
1220}
1221
1222bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001223 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001224 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001225 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001226 !ctx->mMDP.version < qdutils::MDSS_V5)
1227 || isYuvBuffer(hnd)) {
1228 return true;
1229 }
1230 return false;
1231}
1232
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001233// returns true if Action safe dimensions are set and target supports Actionsafe
1234bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1235 // if external supports underscan, do nothing
1236 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001237 // Disable Action safe for 8974 due to HW limitation for downscaling
1238 // layers with overlapped region
1239 // Disable Actionsafe for non HDMI displays.
1240 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1241 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001242 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001243 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001244 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001245
1246 char value[PROPERTY_VALUE_MAX];
1247 // Read action safe properties
1248 property_get("persist.sys.actionsafe.width", value, "0");
1249 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1250 property_get("persist.sys.actionsafe.height", value, "0");
1251 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1252
1253 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1254 //No action safe ratio set, return
1255 return false;
1256 }
1257 return true;
1258}
1259
Naseer Ahmed522ce662013-03-18 20:14:05 -04001260int getBlending(int blending) {
1261 switch(blending) {
1262 case HWC_BLENDING_NONE:
1263 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1264 case HWC_BLENDING_PREMULT:
1265 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1266 case HWC_BLENDING_COVERAGE :
1267 default:
1268 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1269 }
1270}
1271
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001272//Crops source buffer against destination and FB boundaries
1273void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001274 const hwc_rect_t& scissor, int orient) {
1275
Saurabh Shah27c1d652012-08-14 19:30:28 -07001276 int& crop_l = crop.left;
1277 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001278 int& crop_r = crop.right;
1279 int& crop_b = crop.bottom;
1280 int crop_w = crop.right - crop.left;
1281 int crop_h = crop.bottom - crop.top;
1282
Saurabh Shah27c1d652012-08-14 19:30:28 -07001283 int& dst_l = dst.left;
1284 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001285 int& dst_r = dst.right;
1286 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001287 int dst_w = abs(dst.right - dst.left);
1288 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001289
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001290 const int& sci_l = scissor.left;
1291 const int& sci_t = scissor.top;
1292 const int& sci_r = scissor.right;
1293 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001294
Saurabh Shah68107422013-07-09 11:12:42 -07001295 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1296 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001297
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001298 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001299 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001300 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001301 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001302
1303 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001304 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001305 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001306 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001307
1308 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001309 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001310 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001311 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001312
1313 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001314 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001315 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001316 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001317
Saurabh Shah541b59d2012-10-11 11:08:12 -07001318 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301319 crop_l += (int)round((double)crop_w * leftCutRatio);
1320 crop_t += (int)round((double)crop_h * topCutRatio);
1321 crop_r -= (int)round((double)crop_w * rightCutRatio);
1322 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001323}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001324
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301325bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1326 const hwc_layer_1_t* layer2) {
1327 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1328 layer2->displayFrame);
1329 return isValidRect(irect);
1330}
1331
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001332bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1333{
1334 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1335 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1336}
1337
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001338bool isValidRect(const hwc_rect& rect)
1339{
1340 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301341}
1342
Ramakant Singh21cec722014-03-07 19:11:45 +05301343bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1344 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1345 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1346 return true ;
1347 return false;
1348}
1349
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001350hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1351{
1352 hwc_rect_t res;
1353
1354 if(!isValidRect(rect))
1355 return (hwc_rect_t){0, 0, 0, 0};
1356
1357 res.left = rect.left + x_off;
1358 res.top = rect.top + y_off;
1359 res.right = rect.right + x_off;
1360 res.bottom = rect.bottom + y_off;
1361
1362 return res;
1363}
1364
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001365/* computes the intersection of two rects */
1366hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1367{
1368 hwc_rect_t res;
1369
1370 if(!isValidRect(rect1) || !isValidRect(rect2)){
1371 return (hwc_rect_t){0, 0, 0, 0};
1372 }
1373
1374
1375 res.left = max(rect1.left, rect2.left);
1376 res.top = max(rect1.top, rect2.top);
1377 res.right = min(rect1.right, rect2.right);
1378 res.bottom = min(rect1.bottom, rect2.bottom);
1379
1380 if(!isValidRect(res))
1381 return (hwc_rect_t){0, 0, 0, 0};
1382
1383 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301384}
1385
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001386/* computes the union of two rects */
1387hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1388{
1389 hwc_rect_t res;
1390
1391 if(!isValidRect(rect1)){
1392 return rect2;
1393 }
1394
1395 if(!isValidRect(rect2)){
1396 return rect1;
1397 }
1398
1399 res.left = min(rect1.left, rect2.left);
1400 res.top = min(rect1.top, rect2.top);
1401 res.right = max(rect1.right, rect2.right);
1402 res.bottom = max(rect1.bottom, rect2.bottom);
1403
1404 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301405}
1406
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001407/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1408 * a single rect */
1409hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301410
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001411 hwc_rect_t res = rect1;
1412
1413 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1414 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1415 res.top = rect2.bottom;
1416 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1417 res.bottom = rect2.top;
1418 }
1419 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1420 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1421 res.left = rect2.right;
1422 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1423 res.right = rect2.left;
1424 }
1425 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301426}
1427
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001428void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301429 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301430 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301431 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001432 //If it is opaque see if we can substract this region from below
1433 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301434 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1435 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301436 int j= i-1;
1437 hwc_rect_t& topframe =
1438 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1439 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301440 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001441 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1442 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001443 hwc_rect_t bottomCrop =
1444 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001445 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1446 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001447
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001448 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1449 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001450 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001451 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001452 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001453 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001454 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001455 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301456 layer->sourceCropf.left =(float)bottomCrop.left;
1457 layer->sourceCropf.top = (float)bottomCrop.top;
1458 layer->sourceCropf.right = (float)bottomCrop.right;
1459 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001460#ifdef QCOM_BSP
1461 //Update layer dirtyRect
1462 layer->dirtyRect = getIntersection(bottomCrop,
1463 layer->dirtyRect);
1464#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001465 }
1466 }
1467 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301468 }
1469 }
1470 i--;
1471 }
1472}
1473
Naseer Ahmed64b81212013-02-14 10:29:47 -05001474void getNonWormholeRegion(hwc_display_contents_1_t* list,
1475 hwc_rect_t& nwr)
1476{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301477 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001478 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1479 //Initiliaze nwr to first frame
1480 nwr.left = list->hwLayers[0].displayFrame.left;
1481 nwr.top = list->hwLayers[0].displayFrame.top;
1482 nwr.right = list->hwLayers[0].displayFrame.right;
1483 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1484
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301485 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001486 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001487 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001488 }
1489
1490 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001491 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001492}
1493
Saurabh Shah747af1e2013-02-26 10:25:12 -08001494void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001495 if(LIKELY(list)) {
1496 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1497 //Close the acquireFenceFds
1498 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1499 if(list->hwLayers[i].acquireFenceFd >= 0) {
1500 close(list->hwLayers[i].acquireFenceFd);
1501 list->hwLayers[i].acquireFenceFd = -1;
1502 }
1503 }
1504 //Writeback
1505 if(list->outbufAcquireFenceFd >= 0) {
1506 close(list->outbufAcquireFenceFd);
1507 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001508 }
1509 }
1510}
1511
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001512int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001513 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001514 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001515 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001516 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001517 int count = 0;
1518 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001519 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001520 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001521 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001522
1523 struct mdp_buf_sync data;
1524 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001525 data.acq_fen_fd = acquireFd;
1526 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001527 data.retire_fen_fd = &retireFd;
1528 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001529
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001530 char property[PROPERTY_VALUE_MAX];
1531 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1532 if(atoi(property) == 0)
1533 swapzero = true;
1534 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001535
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001536 bool isExtAnimating = false;
1537 if(dpy)
1538 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001539
Saurabh Shah23a813c2013-03-20 16:58:12 -07001540 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001541 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001542 int rotFd = ctx->mRotMgr->getRotDevFd();
1543 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001544 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1545 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1546 if((currRot == NULL) || (currLayer == NULL)) {
1547 continue;
1548 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001549 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001550 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001551 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001552 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001553 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001554 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001555 if(currLayer->acquireFenceFd >= 0) {
1556 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1557 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001558 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301559 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301560 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1561
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001562 if(ret < 0) {
1563 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1564 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001565 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001566 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001567 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001568 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001569 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001570 dup(rotReleaseFd);
1571 //A buffer is free to be used by producer as soon as its copied to
1572 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001573 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001574 rotReleaseFd;
1575 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001576 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001577
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301578 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001579 if(list->outbufAcquireFenceFd >= 0) {
1580 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301581 if(LIKELY(!swapzero) )
1582 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001583 }
1584
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001585 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301586 if(((isAbcInUse(ctx)== true ) ||
1587 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001588 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301589 if(LIKELY(!swapzero) ) {
1590 // if ABC is enabled for more than one layer.
1591 // renderBufIndexforABC will work as FB.Hence
1592 // set the acquireFD from fd - which is coming from copybit
1593 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1594 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1595 acquireFd[count++] = fd;
1596 else
1597 continue;
1598 } else
1599 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1600 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001601 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001602 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301603 if(LIKELY(!swapzero) ) {
1604 if(fd >= 0) {
1605 //set the acquireFD from fd - which is coming from c2d
1606 acquireFd[count++] = fd;
1607 // Buffer sync IOCTL should be async when using c2d fence is
1608 // used
1609 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1610 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1611 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1612 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001613 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001614 }
1615
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001616 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001617 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301618 if(LIKELY(!swapzero) )
1619 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001620 }
1621
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001622 data.acq_fen_fd_cnt = count;
1623 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001624
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001625 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001626 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001627 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001628 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001629
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001630 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001631 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1632 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301633 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001634 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1635 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001636 close(releaseFd);
1637 releaseFd = -1;
1638 close(retireFd);
1639 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001640 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001641
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001642 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001643 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001644#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001645 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001646#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001647 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001648 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001649 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001650 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001651 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001652 // Release all the app layer fds immediately,
1653 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001654 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001655 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001656#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001657 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301658 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301659
1660 // if ABC is enabled for more than one layer
1661 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1662 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1663 list->hwLayers[i].releaseFenceFd = dup(fd);
1664 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1665 (isAbcInUse(ctx) == false)){
1666 //For Blit, the app layers should be released when the Blit
1667 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301668 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001669 } else
1670#endif
1671 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301672 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1673 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001674 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001675 }
1676 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001677
1678 if(fd >= 0) {
1679 close(fd);
1680 fd = -1;
1681 }
1682
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001683 if (ctx->mCopyBit[dpy]) {
1684 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001685 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1686 else
1687 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1688 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001689
Saurabh Shah23a813c2013-03-20 16:58:12 -07001690 //Signals when MDP finishes reading rotator buffers.
1691 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001692 close(releaseFd);
1693 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001694
Arun Kumar K.R51835182013-11-19 11:20:28 -08001695 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001696 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001697 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001698 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001699 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001700 return ret;
1701}
1702
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001703void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001704 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001705 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001706 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001707 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001708
1709 if(layer->blending == HWC_BLENDING_PREMULT) {
1710 ovutils::setMdpFlags(mdpFlags,
1711 ovutils::OV_MDP_BLEND_FG_PREMULT);
1712 }
1713
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001714 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1715 metadata->interlaced) {
1716 ovutils::setMdpFlags(mdpFlags,
1717 ovutils::OV_MDP_DEINTERLACE);
1718 }
1719
1720 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1721 if(isSecureBuffer(hnd)) {
1722 ovutils::setMdpFlags(mdpFlags,
1723 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301724 ovutils::setMdpFlags(mdpFlags,
1725 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1726 }
1727
1728 if(isProtectedBuffer(hnd)) {
1729 ovutils::setMdpFlags(mdpFlags,
1730 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001731 }
1732
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001733 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001734 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001735 ovutils::setMdpFlags(mdpFlags,
1736 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1737 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001738
1739 //Pre-rotation will be used using rotator.
1740 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1741 ovutils::setMdpFlags(mdpFlags,
1742 ovutils::OV_MDP_SOURCE_ROTATED_90);
1743 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001744 //No 90 component and no rot-downscale then flips done by MDP
1745 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001746 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1747 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001748 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1749 }
1750
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001751 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001752 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1753 }
1754 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001755
1756 if(metadata &&
1757 ((metadata->operation & PP_PARAM_HSIC)
1758 || (metadata->operation & PP_PARAM_IGC)
1759 || (metadata->operation & PP_PARAM_SHARP2))) {
1760 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1761 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001762}
1763
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301764int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001765 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001766 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001767
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301768 // Fix alignments for TILED format
1769 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1770 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1771 whf.w = utils::alignup(whf.w, 64);
1772 whf.h = utils::alignup(whf.h, 32);
1773 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001774 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001775
1776 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1777 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001778 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1779 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001780 rot->setCrop(rotCrop);
1781 }
1782
Saurabh Shahacf10202013-02-26 10:15:15 -08001783 rot->setFlags(mdpFlags);
1784 rot->setTransform(orient);
1785 rot->setDownscale(downscale);
1786 if(!rot->commit()) return -1;
1787 return 0;
1788}
1789
Saurabh Shahe2474082013-05-15 16:32:13 -07001790int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001791 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001792 const hwc_rect_t& pos, const MetaData_t *metadata,
1793 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001794 ov->setSource(parg, dest);
1795 ov->setTransform(orient, dest);
1796
1797 int crop_w = crop.right - crop.left;
1798 int crop_h = crop.bottom - crop.top;
1799 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1800 ov->setCrop(dcrop, dest);
1801
1802 int posW = pos.right - pos.left;
1803 int posH = pos.bottom - pos.top;
1804 Dim position(pos.left, pos.top, posW, posH);
1805 ov->setPosition(position, dest);
1806
Saurabh Shah5daeee52013-01-23 16:52:26 +08001807 if (metadata)
1808 ov->setVisualParams(*metadata, dest);
1809
Saurabh Shahacf10202013-02-26 10:15:15 -08001810 if (!ov->commit(dest)) {
1811 return -1;
1812 }
1813 return 0;
1814}
1815
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001816int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1817 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001818 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001819
1820 hwc_rect_t dst = layer->displayFrame;
1821 trimLayer(ctx, dpy, 0, dst, dst);
1822
1823 int w = ctx->dpyAttr[dpy].xres;
1824 int h = ctx->dpyAttr[dpy].yres;
1825 int dst_w = dst.right - dst.left;
1826 int dst_h = dst.bottom - dst.top;
1827 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001828 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001829
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001830 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001831 if (layer->blending == HWC_BLENDING_PREMULT)
1832 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1833
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001834 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001835 layer->planeAlpha,
1836 (ovutils::eBlending) getBlending(layer->blending));
1837
1838 // Configure MDP pipe for Color layer
1839 Dim pos(dst.left, dst.top, dst_w, dst_h);
1840 ctx->mOverlay->setSource(parg, dest);
1841 ctx->mOverlay->setColor(color, dest);
1842 ctx->mOverlay->setTransform(0, dest);
1843 ctx->mOverlay->setCrop(pos, dest);
1844 ctx->mOverlay->setPosition(pos, dest);
1845
1846 if (!ctx->mOverlay->commit(dest)) {
1847 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1848 return -1;
1849 }
1850 return 0;
1851}
1852
Saurabh Shahe2474082013-05-15 16:32:13 -07001853void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001854 hwc_rect_t& crop, Rotator *rot) {
1855 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001856 crop.right - crop.left,
1857 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001858 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1859 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001860 //B-family rotator internally could modify destination dimensions if
1861 //downscaling is supported
1862 whf = rot->getDstWhf();
1863 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001864 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001865 //A-family rotator rotates entire buffer irrespective of crop, forcing
1866 //us to recompute the crop based on transform
1867 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1868 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001869 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001870
1871 crop.left = transformedCrop.x;
1872 crop.top = transformedCrop.y;
1873 crop.right = transformedCrop.x + transformedCrop.w;
1874 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001875}
1876
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001877int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1878 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1879 return 0;
1880 }
1881
1882 int downscale = 0;
1883 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1884 hwc_rect_t dst = layer->displayFrame;
1885 private_handle_t *hnd = (private_handle_t *)layer->handle;
1886
1887 if(not hnd) {
1888 return 0;
1889 }
1890
1891 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1892 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1893 && metadata->interlaced;
1894 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001895 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001896
1897 if(isYuvBuffer(hnd)) {
1898 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1899 ctx->mMDP.version < qdutils::MDSS_V5) {
1900 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1901 crop.bottom - crop.top, dst.right - dst.left,
1902 dst.bottom - dst.top, format, isInterlaced);
1903 } else {
1904 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1905 crop.bottom - crop.top);
1906 Dim pos(dst.left, dst.top, dst.right - dst.left,
1907 dst.bottom - dst.top);
1908 if(transform & HAL_TRANSFORM_ROT_90) {
1909 swap(adjCrop.w, adjCrop.h);
1910 }
1911 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1912 pos.h, format, isInterlaced);
1913 }
1914 }
1915 return downscale;
1916}
1917
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001918bool isZoomModeEnabled(hwc_rect_t crop) {
1919 // This does not work for zooming in top left corner of the image
1920 return(crop.top > 0 || crop.left > 0);
1921}
1922
1923void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1924 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1925 crop.left, crop.top, crop.right, crop.bottom);
1926 if(isZoomModeEnabled(crop)) {
1927 Dim srcCrop(crop.left, crop.top,
1928 crop.right - crop.left,
1929 crop.bottom - crop.top);
1930 int extW = ctx->dpyAttr[dpy].xres;
1931 int extH = ctx->dpyAttr[dpy].yres;
1932 //Crop the original video in order to fit external display aspect ratio
1933 if(srcCrop.w * extH < extW * srcCrop.h) {
1934 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1935 crop.top += offset;
1936 crop.bottom -= offset;
1937 } else {
1938 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1939 crop.left += offset;
1940 crop.right -= offset;
1941 }
1942 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1943 " source crop [%d %d %d %d]", extW, extH, dpy,
1944 crop.left, crop.top, crop.right, crop.bottom);
1945 }
1946}
1947
1948void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1949 hwc_rect_t& dst, int dpy) {
1950 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1951 dst.left, dst.top, dst.right, dst.bottom);
1952 Dim srcCrop(crop.left, crop.top,
1953 crop.right - crop.left,
1954 crop.bottom - crop.top);
1955 int extW = ctx->dpyAttr[dpy].xres;
1956 int extH = ctx->dpyAttr[dpy].yres;
1957 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07001958 // when zoom in mode is enabled or the ratio between video aspect ratio
1959 // and external display aspect ratio is below the minimum tolerance level
1960 // and above maximum tolerance level
1961 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
1962 float extDisplayAspectRatio = ((float)extW / (float)extH);
1963 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
1964 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
1965 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001966 dst.left = 0;
1967 dst.top = 0;
1968 dst.right = extW;
1969 dst.bottom = extH;
1970 }
1971 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1972 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
1973 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
1974 crop.left, crop.top, crop.right, crop.bottom);
1975}
1976
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001977void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001978 hwc_rect_t& dst, int dpy) {
1979 updateCropAIVVideoMode(ctx, crop, dpy);
1980 updateDestAIVVideoMode(ctx, crop, dst, dpy);
1981}
1982
Saurabh Shah88e4d272013-09-03 13:31:29 -07001983int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001984 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001985 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001986
1987 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001988
Saurabh Shahacf10202013-02-26 10:15:15 -08001989 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001990 if (layer->flags & HWC_COLOR_FILL) {
1991 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001992 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001993 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001994 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1995 return -1;
1996 }
1997
Saurabh Shah5daeee52013-01-23 16:52:26 +08001998 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1999
Saurabh Shah62e1d732013-09-17 10:44:05 -07002000 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002001 hwc_rect_t dst = layer->displayFrame;
2002 int transform = layer->transform;
2003 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002004 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002005 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302006 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002007
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002008 // Handle R/B swap
2009 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2010 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2011 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2012 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2013 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2014 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002015 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002016 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2017 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002018 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002019 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002020 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002021 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002022
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002023 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002024 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002025 *rot = ctx->mRotMgr->getNext();
2026 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002027 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002028 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2029 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002030 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002031 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2032 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002033 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002034 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002035 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002036 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002037 }
2038
Saurabh Shah76fd6552013-03-14 14:45:38 -07002039 //For the mdp, since either we are pre-rotating or MDP does flips
2040 orient = OVERLAY_TRANSFORM_0;
2041 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002042 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002043 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2044 (ovutils::eBlending) getBlending(layer->blending));
2045
Saurabh Shah5daeee52013-01-23 16:52:26 +08002046 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002047 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2048 return -1;
2049 }
2050 return 0;
2051}
2052
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002053//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002054void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002055 private_handle_t *hnd) {
2056 if(cropL.right - cropL.left) {
2057 if(isYuvBuffer(hnd)) {
2058 //Always safe to even down left
2059 ovutils::even_floor(cropL.left);
2060 //If right is even, automatically width is even, since left is
2061 //already even
2062 ovutils::even_floor(cropL.right);
2063 }
2064 //Make sure there are no gaps between left and right splits if the layer
2065 //is spread across BOTH halves
2066 if(cropR.right - cropR.left) {
2067 cropR.left = cropL.right;
2068 }
2069 }
2070
2071 if(cropR.right - cropR.left) {
2072 if(isYuvBuffer(hnd)) {
2073 //Always safe to even down left
2074 ovutils::even_floor(cropR.left);
2075 //If right is even, automatically width is even, since left is
2076 //already even
2077 ovutils::even_floor(cropR.right);
2078 }
2079 }
2080}
2081
Saurabh Shah88e4d272013-09-03 13:31:29 -07002082int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002083 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002084 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002085 Rotator **rot) {
2086 private_handle_t *hnd = (private_handle_t *)layer->handle;
2087 if(!hnd) {
2088 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2089 return -1;
2090 }
2091
Saurabh Shah5daeee52013-01-23 16:52:26 +08002092 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2093
Saurabh Shahacf10202013-02-26 10:15:15 -08002094 int hw_w = ctx->dpyAttr[dpy].xres;
2095 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002096 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002097 hwc_rect_t dst = layer->displayFrame;
2098 int transform = layer->transform;
2099 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002100 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002101 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302102 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002103
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002104 // Handle R/B swap
2105 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2106 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2107 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2108 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2109 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2110 }
2111
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002112 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002113 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2114 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002115 }
2116
2117 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002118 ActionSafe, and extorientation features. */
2119 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002120 int downscale = getRotDownscale(ctx, layer);
2121 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002122
2123 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2124 //Enable overfetch
2125 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2126 }
2127
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002128 //Will do something only if feature enabled and conditions suitable
2129 //hollow call otherwise
2130 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2131 overlay::Writeback *wb = overlay::Writeback::getInstance();
2132 whf.format = wb->getOutputFormat();
2133 }
2134
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002135 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002136 (*rot) = ctx->mRotMgr->getNext();
2137 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002138 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002139 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002140 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2141 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002142 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002143 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002144 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002145 rotFlags |= ROT_PREROTATED;
2146 }
2147
2148 eMdpFlags mdpFlagsR = mdpFlagsL;
2149 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2150
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002151 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2152 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002153
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002154 const int lSplit = getLeftSplit(ctx, dpy);
2155
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002156 // Calculate Left rects
2157 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002158 tmp_cropL = crop;
2159 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002160 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002161 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002162 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2163 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002164
2165 // Calculate Right rects
2166 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002167 tmp_cropR = crop;
2168 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002169 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002170 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002171 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2172 }
2173
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002174 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2175
Saurabh Shah94d62362013-07-02 10:58:48 -07002176 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002177 //Not needed if the layer is confined to one half of the screen.
2178 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002179 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2180 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002181 hwc_rect_t new_cropR;
2182 new_cropR.left = tmp_cropL.left;
2183 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2184
2185 hwc_rect_t new_cropL;
2186 new_cropL.left = new_cropR.right;
2187 new_cropL.right = tmp_cropR.right;
2188
2189 tmp_cropL.left = new_cropL.left;
2190 tmp_cropL.right = new_cropL.right;
2191
2192 tmp_cropR.left = new_cropR.left;
2193 tmp_cropR.right = new_cropR.right;
2194
2195 }
2196
Saurabh Shah76fd6552013-03-14 14:45:38 -07002197 //For the mdp, since either we are pre-rotating or MDP does flips
2198 orient = OVERLAY_TRANSFORM_0;
2199 transform = 0;
2200
Saurabh Shahacf10202013-02-26 10:15:15 -08002201 //configure left mixer
2202 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002203 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002204 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2205 (ovutils::eBlending) getBlending(layer->blending));
2206
Saurabh Shahacf10202013-02-26 10:15:15 -08002207 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002208 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002209 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2210 return -1;
2211 }
2212 }
2213
2214 //configure right mixer
2215 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002216 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002217 static_cast<eRotFlags>(rotFlags),
2218 layer->planeAlpha,
2219 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002220 tmp_dstR.right = tmp_dstR.right - lSplit;
2221 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002222 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002223 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002224 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2225 return -1;
2226 }
2227 }
2228
2229 return 0;
2230}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002231
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002232int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2233 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2234 const eDest& lDest, const eDest& rDest,
2235 Rotator **rot) {
2236 private_handle_t *hnd = (private_handle_t *)layer->handle;
2237 if(!hnd) {
2238 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2239 return -1;
2240 }
2241 //Both pipes are configured to the same mixer
2242 eZorder lz = z;
2243 eZorder rz = (eZorder)(z + 1);
2244
2245 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2246
2247 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2248 hwc_rect_t dst = layer->displayFrame;
2249 int transform = layer->transform;
2250 eTransform orient = static_cast<eTransform>(transform);
2251 int rotFlags = ROT_FLAGS_NONE;
2252 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2253 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2254
2255 int downscale = getRotDownscale(ctx, layer);
2256 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2257
2258 //XXX: Check if rotation is supported and valid for 3D
2259 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2260 (*rot) = ctx->mRotMgr->getNext();
2261 if((*rot) == NULL) return -1;
2262 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2263 //Configure rotator for pre-rotation
2264 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2265 ALOGE("%s: configRotator failed!", __FUNCTION__);
2266 return -1;
2267 }
2268 updateSource(orient, whf, crop, *rot);
2269 rotFlags |= ROT_PREROTATED;
2270 }
2271
2272 eMdpFlags mdpFlagsR = mdpFlagsL;
2273
2274 hwc_rect_t cropL = crop, dstL = dst;
2275 hwc_rect_t cropR = crop, dstR = dst;
2276 int hw_w = ctx->dpyAttr[dpy].xres;
2277 int hw_h = ctx->dpyAttr[dpy].yres;
2278
2279 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2280 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2281 // Calculate Left rects
2282 // XXX: This assumes crop.right/2 is the center point of the video
2283 cropL.right = crop.right/2;
2284 dstL.left = dst.left/2;
2285 dstL.right = dst.right/2;
2286
2287 // Calculate Right rects
2288 cropR.left = crop.right/2;
2289 dstR.left = hw_w/2 + dst.left/2;
2290 dstR.right = hw_w/2 + dst.right/2;
2291 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2292 // Calculate Left rects
2293 cropL.bottom = crop.bottom/2;
2294 dstL.top = dst.top/2;
2295 dstL.bottom = dst.bottom/2;
2296
2297 // Calculate Right rects
2298 cropR.top = crop.bottom/2;
2299 dstR.top = hw_h/2 + dst.top/2;
2300 dstR.bottom = hw_h/2 + dst.bottom/2;
2301 } else {
2302 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2303 return -1;
2304 }
2305
2306 //For the mdp, since either we are pre-rotating or MDP does flips
2307 orient = OVERLAY_TRANSFORM_0;
2308 transform = 0;
2309
2310 //configure left pipe
2311 if(lDest != OV_INVALID) {
2312 PipeArgs pargL(mdpFlagsL, whf, lz,
2313 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2314 (ovutils::eBlending) getBlending(layer->blending));
2315
2316 if(configMdp(ctx->mOverlay, pargL, orient,
2317 cropL, dstL, metadata, lDest) < 0) {
2318 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2319 return -1;
2320 }
2321 }
2322
2323 //configure right pipe
2324 if(rDest != OV_INVALID) {
2325 PipeArgs pargR(mdpFlagsR, whf, rz,
2326 static_cast<eRotFlags>(rotFlags),
2327 layer->planeAlpha,
2328 (ovutils::eBlending) getBlending(layer->blending));
2329 if(configMdp(ctx->mOverlay, pargR, orient,
2330 cropR, dstR, metadata, rDest) < 0) {
2331 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2332 return -1;
2333 }
2334 }
2335
2336 return 0;
2337}
2338
radhakrishnac9a67412013-09-25 17:40:42 +05302339int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2340 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002341 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302342 Rotator **rot) {
2343 private_handle_t *hnd = (private_handle_t *)layer->handle;
2344 if(!hnd) {
2345 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2346 return -1;
2347 }
2348
2349 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2350
radhakrishnac9a67412013-09-25 17:40:42 +05302351 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2352 hwc_rect_t dst = layer->displayFrame;
2353 int transform = layer->transform;
2354 eTransform orient = static_cast<eTransform>(transform);
2355 const int downscale = 0;
2356 int rotFlags = ROT_FLAGS_NONE;
2357 //Splitting only YUV layer on primary panel needs different zorders
2358 //for both layers as both the layers are configured to single mixer
2359 eZorder lz = z;
2360 eZorder rz = (eZorder)(z + 1);
2361
2362 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302363 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302364
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002365 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002366 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2367 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002368 }
2369
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002370 /* Calculate the external display position based on MDP downscale,
2371 ActionSafe, and extorientation features. */
2372 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2373
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002374 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302375 trimLayer(ctx, dpy, transform, crop, dst);
2376
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002377 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302378 (*rot) = ctx->mRotMgr->getNext();
2379 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002380 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302381 //Configure rotator for pre-rotation
2382 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2383 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302384 return -1;
2385 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002386 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302387 rotFlags |= ROT_PREROTATED;
2388 }
2389
2390 eMdpFlags mdpFlagsR = mdpFlagsL;
2391 int lSplit = dst.left + (dst.right - dst.left)/2;
2392
2393 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2394 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2395
2396 if(lDest != OV_INVALID) {
2397 tmp_cropL = crop;
2398 tmp_dstL = dst;
2399 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2400 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2401 }
2402 if(rDest != OV_INVALID) {
2403 tmp_cropR = crop;
2404 tmp_dstR = dst;
2405 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2406 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2407 }
2408
2409 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2410
2411 //When buffer is H-flipped, contents of mixer config also needs to swapped
2412 //Not needed if the layer is confined to one half of the screen.
2413 //If rotator has been used then it has also done the flips, so ignore them.
2414 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2415 && rDest != OV_INVALID && (*rot) == NULL) {
2416 hwc_rect_t new_cropR;
2417 new_cropR.left = tmp_cropL.left;
2418 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2419
2420 hwc_rect_t new_cropL;
2421 new_cropL.left = new_cropR.right;
2422 new_cropL.right = tmp_cropR.right;
2423
2424 tmp_cropL.left = new_cropL.left;
2425 tmp_cropL.right = new_cropL.right;
2426
2427 tmp_cropR.left = new_cropR.left;
2428 tmp_cropR.right = new_cropR.right;
2429
2430 }
2431
2432 //For the mdp, since either we are pre-rotating or MDP does flips
2433 orient = OVERLAY_TRANSFORM_0;
2434 transform = 0;
2435
2436 //configure left half
2437 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002438 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302439 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2440 (ovutils::eBlending) getBlending(layer->blending));
2441
2442 if(configMdp(ctx->mOverlay, pargL, orient,
2443 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2444 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2445 return -1;
2446 }
2447 }
2448
2449 //configure right half
2450 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002451 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302452 static_cast<eRotFlags>(rotFlags),
2453 layer->planeAlpha,
2454 (ovutils::eBlending) getBlending(layer->blending));
2455 if(configMdp(ctx->mOverlay, pargR, orient,
2456 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2457 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2458 return -1;
2459 }
2460 }
2461
2462 return 0;
2463}
2464
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002465bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302466 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002467 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002468 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302469 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302470 * in LINE and BLOCK modes for writeback panels.
2471 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002472 if(dpy == HWC_DISPLAY_PRIMARY)
2473 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002474 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302475 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2476 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002477 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002478 return true;
2479}
2480
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002481int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2482 //Default even split for all displays with high res
2483 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2484 if(dpy == HWC_DISPLAY_PRIMARY &&
2485 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2486 //Override if split published by driver for primary
2487 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2488 }
2489 return lSplit;
2490}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002491
Saurabh Shah88e4d272013-09-03 13:31:29 -07002492bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302493 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002494 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002495 return true;
2496 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302497 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002498 return true;
2499 }
2500 return false;
2501}
2502
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002503//clear prev layer prop flags and realloc for current frame
2504void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2505 if(ctx->layerProp[dpy]) {
2506 delete[] ctx->layerProp[dpy];
2507 ctx->layerProp[dpy] = NULL;
2508 }
2509 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2510}
2511
Ramakant Singh0def28c2014-03-28 20:43:13 +05302512bool isAbcInUse(hwc_context_t *ctx){
2513 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2514}
2515
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002516void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2517 if (ohnd != NULL && ohnd->base) {
2518 char dumpFilename[PATH_MAX];
2519 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002520 int width = getWidth(ohnd);
2521 int height = getHeight(ohnd);
2522 int format = ohnd->format;
2523 //dummy aligned w & h.
2524 int alW = 0, alH = 0;
2525 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002526 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2527 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002528 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2529 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002530 FILE* fp = fopen(dumpFilename, "w+");
2531 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002532 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002533 fclose(fp);
2534 }
2535 ALOGD("Buffer[%s] Dump to %s: %s",
2536 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2537 }
2538}
2539
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002540bool isGLESComp(hwc_context_t *ctx,
2541 hwc_display_contents_1_t* list) {
2542 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2543 for(int index = 0; index < numAppLayers; index++) {
2544 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2545 if(layer->compositionType == HWC_FRAMEBUFFER)
2546 return true;
2547 }
2548 return false;
2549}
2550
2551void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2552 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002553 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002554 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002555
2556#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002557 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2558 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2559 hint to default if the previous composition is GPU or current GPU
2560 composition is due to idle fallback */
2561 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2562 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2563 if(!gpuHint->mEGLDisplay) {
2564 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2565 return;
2566 }
2567 gpuHint->mEGLContext = eglGetCurrentContext();
2568 if(!gpuHint->mEGLContext) {
2569 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2570 return;
2571 }
2572 }
2573 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002574 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2575 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002576 EGLint attr_list[] = {EGL_GPU_HINT_1,
2577 EGL_GPU_LEVEL_3,
2578 EGL_NONE };
2579 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2580 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2581 gpuHint->mEGLContext, attr_list)) {
2582 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2583 } else {
2584 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002585 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002586 }
2587 } else {
2588 EGLint attr_list[] = {EGL_GPU_HINT_1,
2589 EGL_GPU_LEVEL_0,
2590 EGL_NONE };
2591 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2592 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2593 gpuHint->mEGLContext, attr_list)) {
2594 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2595 } else {
2596 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2597 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002598 if(MDPComp::isIdleFallback()) {
2599 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2600 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002601 }
2602 } else {
2603 /* set the GPU hint flag to default for MDP composition */
2604 EGLint attr_list[] = {EGL_GPU_HINT_1,
2605 EGL_GPU_LEVEL_0,
2606 EGL_NONE };
2607 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2608 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2609 gpuHint->mEGLContext, attr_list)) {
2610 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2611 } else {
2612 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2613 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002614 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002615 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002616#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002617}
2618
Sushil Chauhandefd3522014-05-13 18:17:12 -07002619bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2620 // To be peripheral, 3 boundaries should match.
2621 uint8_t eqBounds = 0;
2622 if (rect1.left == rect2.left)
2623 eqBounds++;
2624 if (rect1.top == rect2.top)
2625 eqBounds++;
2626 if (rect1.right == rect2.right)
2627 eqBounds++;
2628 if (rect1.bottom == rect2.bottom)
2629 eqBounds++;
2630 return (eqBounds == 3);
2631}
2632
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302633void processBootAnimCompleted(hwc_context_t *ctx) {
2634 char value[PROPERTY_VALUE_MAX];
2635 int boot_finished = 0, ret = -1;
2636 int (*applyMode)(int) = NULL;
2637 void *modeHandle = NULL;
2638
2639 // Reading property set on boot finish in SF
2640 property_get("service.bootanim.exit", value, "0");
2641 boot_finished = atoi(value);
2642 if (!boot_finished)
2643 return;
2644
2645 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2646 if (modeHandle) {
2647 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2648 if (applyMode) {
2649 ret = applyMode(HWC_DISPLAY_PRIMARY);
2650 if (ret)
2651 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2652 } else {
2653 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2654 }
2655 dlclose(modeHandle);
2656 } else {
2657 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
2658 }
2659
2660 ctx->mBootAnimCompleted = true;
2661}
2662
Saurabh Shahcd018352014-11-11 13:54:19 -08002663void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2664 const private_handle_t *hnd,
2665 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002666 const int& transform,const int& downscale,
2667 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002668 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302669 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002670 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002671 return;
2672 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002673 //Disabled at runtime
2674 if(not ctx->mBWCEnabled) return;
2675 //BWC not supported with rot-downscale
2676 if(downscale) return;
2677 //Not enabled for secondary displays
2678 if(dpy) return;
2679 //Not enabled for non-video buffers
2680 if(not isYuvBuffer(hnd)) return;
2681
Saurabh Shahb6810df2014-06-17 16:00:22 -07002682 int src_w = crop.right - crop.left;
2683 int src_h = crop.bottom - crop.top;
2684 int dst_w = dst.right - dst.left;
2685 int dst_h = dst.bottom - dst.top;
2686 if(transform & HAL_TRANSFORM_ROT_90) {
2687 swap(src_w, src_h);
2688 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002689 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002690 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002691 return;
2692 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002693 //Decimation necessary, cannot use BWC. H/W requirement.
2694 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002695 uint8_t horzDeci = 0;
2696 uint8_t vertDeci = 0;
2697 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2698 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002699 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002700 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002701
2702 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2703}
2704
Saurabh Shah23a813c2013-03-20 16:58:12 -07002705void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302706 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002707 mLayer[mCount] = layer;
2708 mRot[mCount] = rot;
2709 mCount++;
2710}
2711
2712void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302713 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002714 mLayer[i] = 0;
2715 mRot[i] = 0;
2716 }
2717 mCount = 0;
2718}
2719
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002720void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002721 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002722 reset();
2723}
2724
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302725bool LayerRotMap::isRotCached(uint32_t index) const {
2726 overlay::Rotator* rot = getRot(index);
2727 hwc_layer_1_t* layer = getLayer(index);
2728
2729 if(rot and layer and layer->handle) {
2730 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2731 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2732 }
2733 return false;
2734}
2735
Saurabh Shah23a813c2013-03-20 16:58:12 -07002736void LayerRotMap::setReleaseFd(const int& fence) {
2737 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302738 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2739 /* Ensure that none of the above (Rotator-instance,
2740 * layer and layer-handle) are NULL*/
2741 if(isRotCached(i))
2742 mRot[i]->setPrevBufReleaseFd(dup(fence));
2743 else
2744 mRot[i]->setCurrBufReleaseFd(dup(fence));
2745 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002746 }
2747}
2748
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002749hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2750 int lRoiWidth = 0, rRoiWidth = 0;
2751 int half_frame_width = fullFrame.right/2;
2752
2753 hwc_rect lFrame = fullFrame;
2754 hwc_rect rFrame = fullFrame;
2755 lFrame.right = (lFrame.right - lFrame.left)/2;
2756 rFrame.left = lFrame.right;
2757
2758 hwc_rect lRoi = getIntersection(roi, lFrame);
2759 hwc_rect rRoi = getIntersection(roi, rFrame);
2760
2761 lRoiWidth = lRoi.right - lRoi.left;
2762 rRoiWidth = rRoi.right - rRoi.left;
2763
2764 if(lRoiWidth && rRoiWidth) {
2765 if(lRoiWidth < rRoiWidth)
2766 roi.left = half_frame_width - rRoiWidth;
2767 else
2768 roi.right = half_frame_width + lRoiWidth;
2769 }
2770 return roi;
2771}
2772
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002773void resetROI(hwc_context_t *ctx, const int dpy) {
2774 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2775 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002776
2777 /* When source split is enabled, both the panels are calibrated
2778 * in a single coordinate system. So only one ROI is generated
2779 * for the whole panel extending equally from the midpoint and
2780 * populated for the left side. */
2781 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2782 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002783 const int lSplit = getLeftSplit(ctx, dpy);
2784 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2785 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2786 } else {
2787 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2788 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2789 }
2790}
2791
2792hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002793{
2794 if(!isValidRect(roi))
2795 return roi;
2796
2797 struct hwc_rect t_roi = roi;
2798
2799 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2800 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2801 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2802 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2803 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002804 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002805
2806 /* Align to minimum width recommended by the panel */
2807 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2808 if((t_roi.left + MIN_WIDTH) > boundary.right)
2809 t_roi.left = t_roi.right - MIN_WIDTH;
2810 else
2811 t_roi.right = t_roi.left + MIN_WIDTH;
2812 }
2813
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002814 /* Align to minimum height recommended by the panel */
2815 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2816 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2817 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2818 else
2819 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2820 }
2821
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002822 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002823 if(LEFT_ALIGN)
2824 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2825
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002826 if(WIDTH_ALIGN) {
2827 int width = t_roi.right - t_roi.left;
2828 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2829 t_roi.right = t_roi.left + width;
2830
2831 if(t_roi.right > boundary.right) {
2832 t_roi.right = boundary.right;
2833 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002834
2835 if(LEFT_ALIGN)
2836 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002837 }
2838 }
2839
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002840
2841 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002842 if(TOP_ALIGN)
2843 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2844
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002845 if(HEIGHT_ALIGN) {
2846 int height = t_roi.bottom - t_roi.top;
2847 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2848 t_roi.bottom = t_roi.top + height;
2849
2850 if(t_roi.bottom > boundary.bottom) {
2851 t_roi.bottom = boundary.bottom;
2852 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002853
2854 if(TOP_ALIGN)
2855 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002856 }
2857 }
2858
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002859
2860 return t_roi;
2861}
2862
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002863void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002864 if(ctx->dpyAttr[dpy].connected) {
2865 ctx->mDrawLock.lock();
2866 ctx->dpyAttr[dpy].isActive = true;
2867 ctx->dpyAttr[dpy].isPause = true;
2868 ctx->mDrawLock.unlock();
2869 ctx->proc->invalidate(ctx->proc);
2870
2871 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2872 * 2 / 1000);
2873
2874 // At this point all the pipes used by External have been
2875 // marked as UNSET.
2876 ctx->mDrawLock.lock();
2877 // Perform commit to unstage the pipes.
2878 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2879 ALOGE("%s: display commit fail! for %d dpy",
2880 __FUNCTION__, dpy);
2881 }
2882 ctx->mDrawLock.unlock();
2883 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002884 }
2885 return;
2886}
2887
2888void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002889 if(ctx->dpyAttr[dpy].connected) {
2890 ctx->mDrawLock.lock();
2891 ctx->dpyAttr[dpy].isConfiguring = true;
2892 ctx->dpyAttr[dpy].isActive = true;
2893 ctx->mDrawLock.unlock();
2894 ctx->proc->invalidate(ctx->proc);
2895
2896 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2897 * 2 / 1000);
2898
2899 //At this point external has all the pipes it would need.
2900 ctx->mDrawLock.lock();
2901 ctx->dpyAttr[dpy].isPause = false;
2902 ctx->mDrawLock.unlock();
2903 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002904 }
2905 return;
2906}
2907
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002908void clearPipeResources(hwc_context_t* ctx, int dpy) {
2909 if(ctx->mOverlay) {
2910 ctx->mOverlay->configBegin();
2911 ctx->mOverlay->configDone();
2912 }
2913 if(ctx->mRotMgr) {
2914 ctx->mRotMgr->clear();
2915 }
2916 // Call a display commit to ensure that pipes and associated
2917 // fd's are cleaned up.
2918 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2919 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2920 }
2921}
2922
2923// Handles online events when HDMI is the primary display. In particular,
2924// online events for hdmi connected before AND after boot up and HWC init.
2925void handle_online(hwc_context_t* ctx, int dpy) {
2926 // Close the current fd if it was opened earlier on when HWC
2927 // was initialized.
2928 if (ctx->dpyAttr[dpy].fd >= 0) {
2929 close(ctx->dpyAttr[dpy].fd);
2930 ctx->dpyAttr[dpy].fd = -1;
2931 }
2932 // TODO: If HDMI is connected after the display has booted up,
2933 // and the best configuration is different from the default
2934 // then we need to deal with this appropriately.
2935 ctx->mHDMIDisplay->configure();
2936 updateDisplayInfo(ctx, dpy);
2937 initCompositionResources(ctx, dpy);
2938 ctx->dpyAttr[dpy].connected = true;
2939}
2940
2941// Handles offline events for HDMI. This can be used for offline events
2942// initiated by the HDMI driver and the CEC framework.
2943void handle_offline(hwc_context_t* ctx, int dpy) {
2944 destroyCompositionResources(ctx, dpy);
2945 // Clear all pipe resources and call a display commit to ensure
2946 // that all the fd's are closed. This will ensure that the HDMI
2947 // core turns off and that we receive an event the next time the
2948 // cable is connected.
2949 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
2950 clearPipeResources(ctx, dpy);
2951 }
2952 ctx->mHDMIDisplay->teardown();
2953 resetDisplayInfo(ctx, dpy);
2954 ctx->dpyAttr[dpy].connected = false;
2955 ctx->dpyAttr[dpy].isActive = false;
2956}
2957
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002958int convertS3DFormatToMode(int s3DFormat) {
2959 int ret;
2960 switch(s3DFormat) {
2961 case HAL_3D_SIDE_BY_SIDE_L_R:
2962 case HAL_3D_SIDE_BY_SIDE_R_L:
2963 ret = HDMI_S3D_SIDE_BY_SIDE;
2964 break;
2965 case HAL_3D_TOP_BOTTOM:
2966 ret = HDMI_S3D_TOP_AND_BOTTOM;
2967 break;
2968 default:
2969 ret = HDMI_S3D_NONE;
2970 }
2971 return ret;
2972}
2973
2974bool needs3DComposition(hwc_context_t* ctx, int dpy) {
2975 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
2976 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
2977}
2978
2979void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
2980 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
2981 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
2982 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
2983 ctx->dpyAttr[dpy].s3dMode = s3dMode;
2984 }
2985 }
2986}
2987
2988bool displaySupports3D(hwc_context_t* ctx, int dpy) {
2989 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
2990 ((dpy == HWC_DISPLAY_PRIMARY) &&
2991 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
2992}
2993
2994
Saurabh Shahacf10202013-02-26 10:15:15 -08002995};//namespace qhwc