blob: 05ab5035d618029fb2f48622db0a4ed613f2be71 [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);
Charles Bindab39382014-06-30 10:34:30 -0700379 android::sp<qService::IQService> qservice_sp = interface_cast<IQService>(
Saurabh Shah86c17292013-02-08 15:24:13 -0800380 defaultServiceManager()->getService(
Charles Bindab39382014-06-30 10:34:30 -0700381 String16("display.qservice")));
382 if (qservice_sp.get()) {
383 qservice_sp->connect(client);
384 } else {
385 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
386 return ;
387 }
Saurabh Shah86c17292013-02-08 15:24:13 -0800388
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700389 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700390 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700391 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400392
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700393 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
394 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
395
Ramakant Singh0def28c2014-03-28 20:43:13 +0530396 ctx->enableABC = false;
397 property_get("debug.sf.hwc.canUseABC", value, "0");
398 ctx->enableABC = atoi(value) ? true : false;
399
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530400 // Initializing boot anim completed check to false
401 ctx->mBootAnimCompleted = false;
402
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700403 // Initialize gpu perfomance hint related parameters
404 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700405#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700406 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
407
408 ctx->mGPUHintInfo.mEGLDisplay = NULL;
409 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700410 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700411 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700412#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700413 // Read the system property to determine if windowboxing feature is enabled.
414 ctx->mWindowboxFeature = false;
415 if(property_get("sys.hwc.windowbox_feature", value, "false")
416 && !strcmp(value, "true")) {
417 ctx->mWindowboxFeature = true;
418 }
419
Raj Kamal0d53fc62014-11-25 17:36:36 +0530420 ctx->mUseMetaDataRefreshRate = true;
421 if(property_get("persist.metadata_dynfps.disable", value, "false")
422 && !strcmp(value, "true")) {
423 ctx->mUseMetaDataRefreshRate = false;
424 }
425
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700426 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800427 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700428 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700429 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700430}
431
432void closeContext(hwc_context_t *ctx)
433{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500434 if(ctx->mOverlay) {
435 delete ctx->mOverlay;
436 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700437 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700438
Saurabh Shahacf10202013-02-26 10:15:15 -0800439 if(ctx->mRotMgr) {
440 delete ctx->mRotMgr;
441 ctx->mRotMgr = NULL;
442 }
443
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700444 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800445 if(ctx->mCopyBit[i]) {
446 delete ctx->mCopyBit[i];
447 ctx->mCopyBit[i] = NULL;
448 }
449 }
450
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800451 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700452 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
453 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700454 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700455
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700456 if(ctx->mHDMIDisplay) {
457 delete ctx->mHDMIDisplay;
458 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700459 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400460
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700461 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700462 destroyCompositionResources(ctx, i);
463
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700464 if(ctx->mHwcDebug[i]) {
465 delete ctx->mHwcDebug[i];
466 ctx->mHwcDebug[i] = NULL;
467 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700468 if(ctx->mLayerRotMap[i]) {
469 delete ctx->mLayerRotMap[i];
470 ctx->mLayerRotMap[i] = NULL;
471 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800472 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800473 if(ctx->mHWCVirtual) {
474 delete ctx->mHWCVirtual;
475 ctx->mHWCVirtual = NULL;
476 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700477 if(ctx->mAD) {
478 delete ctx->mAD;
479 ctx->mAD = NULL;
480 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800481
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800482
Naseer Ahmed29a26812012-06-14 00:56:20 -0700483}
484
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700485//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530486uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700487 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
488 uint32_t rate = refreshRate;
489 for(int i=0; i< count; i++) {
490 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
491 // Most likely used for video, the fps can fluctuate
492 // Ex: b/w 29 and 30 for 30 fps clip
493 rate = stdRefreshRates[i];
494 break;
495 }
496 }
497 return rate;
498}
499
500//Helper func to set the dyn fps
501void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
502 //Update only if different
503 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
504 return;
505 const int fbNum = Overlay::getFbForDpy(dpy);
506 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
507 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800508 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700509
510 int fd = open(sysfsPath, O_WRONLY);
511 if(fd >= 0) {
512 char str[64];
513 snprintf(str, sizeof(str), "%d", refreshRate);
514 ssize_t ret = write(fd, str, strlen(str));
515 if(ret < 0) {
516 ALOGE("%s: Failed to write %d with error %s",
517 __FUNCTION__, refreshRate, strerror(errno));
518 } else {
519 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
520 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
521 __FUNCTION__, refreshRate);
522 }
523 close(fd);
524 } else {
525 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
526 strerror(errno));
527 }
528}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500529
530void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700531{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500532 va_list varargs;
533 va_start(varargs, fmt);
534 buf.appendFormatV(fmt, varargs);
535 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700536}
537
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700538int getExtOrientation(hwc_context_t* ctx) {
539 int extOrient = ctx->mExtOrientation;
540 if(ctx->mBufferMirrorMode)
541 extOrient = getMirrorModeOrientation(ctx);
542 return extOrient;
543}
544
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800545/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700546void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
547 // Position
548 int x = rect.left, y = rect.top;
549 int w = rect.right - rect.left;
550 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800551
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800552 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800553 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800554 // Read action safe properties
555 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
556 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700557
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800558 float wRatio = 1.0;
559 float hRatio = 1.0;
560 float xRatio = 1.0;
561 float yRatio = 1.0;
562
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700563 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
564 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700565 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
566 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700567 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700568 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700569 }
570
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800571
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700572 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700573 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700574
575 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700576 swap(fbWidth, fbHeight);
577
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800578 float asX = 0;
579 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530580 float asW = (float)fbWidth;
581 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800582
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800583 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530584 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
585 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
586 asX = ((float)fbWidth - asW) / 2;
587 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800588
589 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530590 xRatio = (float)x/(float)fbWidth;
591 yRatio = (float)y/(float)fbHeight;
592 wRatio = (float)w/(float)fbWidth;
593 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800594
595 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530596 x = int((xRatio * asW) + asX);
597 y = int((yRatio * asH) + asY);
598 w = int(wRatio * asW);
599 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800600
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700601 // Convert it back to hwc_rect_t
602 rect.left = x;
603 rect.top = y;
604 rect.right = w + rect.left;
605 rect.bottom = h + rect.top;
606
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800607 return;
608}
609
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700610// This function gets the destination position for Seconday display
611// based on the position and aspect ratio with orientation
612void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
613 hwc_rect_t& inRect, hwc_rect_t& outRect) {
614 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530615 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
616 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700617 //display position(x,y,w,h) in correct aspectratio after rotation
618 int xPos = 0;
619 int yPos = 0;
620 float width = fbWidth;
621 float height = fbHeight;
622 // Width/Height used for calculation, after rotation
623 float actualWidth = fbWidth;
624 float actualHeight = fbHeight;
625
626 float wRatio = 1.0;
627 float hRatio = 1.0;
628 float xRatio = 1.0;
629 float yRatio = 1.0;
630 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
631
632 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
633 inRect.bottom - inRect.top);
634 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
635 outRect.bottom - outRect.top);
636
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530637 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700638 eTransform extorient = static_cast<eTransform>(extOrientation);
639 // To calculate the destination co-ordinates in the new orientation
640 preRotateSource(extorient, whf, inPos);
641
642 if(extOrientation & HAL_TRANSFORM_ROT_90) {
643 // Swap width/height for input position
644 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700645 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
646 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700647 xPos = rect.left;
648 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530649 width = float(rect.right - rect.left);
650 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700651 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700652 xRatio = (float)((float)inPos.x/actualWidth);
653 yRatio = (float)((float)inPos.y/actualHeight);
654 wRatio = (float)((float)inPos.w/actualWidth);
655 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800656
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530657 //Calculate the pos9ition...
658 outPos.x = uint32_t((xRatio * width) + (float)xPos);
659 outPos.y = uint32_t((yRatio * height) + (float)yPos);
660 outPos.w = uint32_t(wRatio * width);
661 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700662 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
663 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
664 outPos.w, outPos.h);
665
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700666 // For sidesync, the dest fb will be in portrait orientation, and the crop
667 // will be updated to avoid the black side bands, and it will be upscaled
668 // to fit the dest RB, so recalculate
669 // the position based on the new width and height
670 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
671 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800672 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700673 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530674 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700675 // GetaspectRatio -- tricky to get the correct aspect ratio
676 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700677 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530678 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700679 xPos = r.left;
680 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530681 float tempHeight = float(r.bottom - r.top);
682 yRatio = (float)yPos/height;
683 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700684 hRatio = tempHeight/height;
685
686 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530687 outPos.x = uint32_t(xRatio * fbWidth);
688 outPos.y = uint32_t(yRatio * fbHeight);
689 outPos.w = uint32_t(wRatio * fbWidth);
690 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700691
692 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
693 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
694 outPos.x, outPos.y,
695 outPos.w, outPos.h);
696 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700697 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700698 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700699 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700700 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700701 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
702 extW = ctx->mHWCVirtual->getScalingWidth();
703 extH = ctx->mHWCVirtual->getScalingHeight();
704 }
705 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
706 __FUNCTION__, extW, extH);
707
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530708 fbWidth = (float)ctx->dpyAttr[dpy].xres;
709 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700710 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530711 xRatio = (float)outPos.x/fbWidth;
712 yRatio = (float)outPos.y/fbHeight;
713 wRatio = (float)outPos.w/fbWidth;
714 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700715
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530716 outPos.x = uint32_t(xRatio * (float)extW);
717 outPos.y = uint32_t(yRatio * (float)extH);
718 outPos.w = uint32_t(wRatio * (float)extW);
719 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700720 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700721 // Convert Dim to hwc_rect_t
722 outRect.left = outPos.x;
723 outRect.top = outPos.y;
724 outRect.right = outPos.x + outPos.w;
725 outRect.bottom = outPos.y + outPos.h;
726
727 return;
728}
729
730bool isPrimaryPortrait(hwc_context_t *ctx) {
731 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
732 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
733 if(fbWidth < fbHeight) {
734 return true;
735 }
736 return false;
737}
738
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700739bool isOrientationPortrait(hwc_context_t *ctx) {
740 if(isPrimaryPortrait(ctx)) {
741 return !(ctx->deviceOrientation & 0x1);
742 }
743 return (ctx->deviceOrientation & 0x1);
744}
745
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700746void calcExtDisplayPosition(hwc_context_t *ctx,
747 private_handle_t *hnd,
748 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700749 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700750 hwc_rect_t& displayFrame,
751 int& transform,
752 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700753 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700754 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530755 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700756 if(!isYuvBuffer(hnd)) {
757 if(extOrient & HWC_TRANSFORM_ROT_90) {
758 int dstWidth = ctx->dpyAttr[dpy].xres;
759 int dstHeight = ctx->dpyAttr[dpy].yres;;
760 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
761 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
762 if(!isPrimaryPortrait(ctx)) {
763 swap(srcWidth, srcHeight);
764 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700765 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700766 srcHeight, displayFrame);
767 // Crop - this is needed, because for sidesync, the dest fb will
768 // be in portrait orientation, so update the crop to not show the
769 // black side bands.
770 if (isOrientationPortrait(ctx)) {
771 sourceCrop = displayFrame;
772 displayFrame.left = 0;
773 displayFrame.top = 0;
774 displayFrame.right = dstWidth;
775 displayFrame.bottom = dstHeight;
776 }
777 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700778 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700779 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700780 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700781 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530782 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
783 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700784 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700785 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700786 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700787 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
788 extW = ctx->mHWCVirtual->getScalingWidth();
789 extH = ctx->mHWCVirtual->getScalingHeight();
790 }
791 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
792 __FUNCTION__, extW, extH);
793
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700794 //Calculate the ratio...
795 float wRatio = ((float)extW)/fbWidth;
796 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700797
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700798 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530799 displayFrame.left = int(wRatio*(float)displayFrame.left);
800 displayFrame.top = int(hRatio*(float)displayFrame.top);
801 displayFrame.right = int(wRatio*(float)displayFrame.right);
802 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700803 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
804 " for MDPDownscale feature [%d %d %d %d]",
805 displayFrame.left, displayFrame.top,
806 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700807 }
808 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700809 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700810 getAspectRatioPosition(ctx, dpy, extOrient,
811 displayFrame, displayFrame);
812 }
813 }
814 // If there is a external orientation set, use that
815 if(extOrient) {
816 transform = extOrient;
817 orient = static_cast<ovutils::eTransform >(extOrient);
818 }
819 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
820 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700821 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700822}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700823
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700824/* Returns the orientation which needs to be set on External for
825 * SideSync/Buffer Mirrormode
826 */
827int getMirrorModeOrientation(hwc_context_t *ctx) {
828 int extOrientation = 0;
829 int deviceOrientation = ctx->deviceOrientation;
830 if(!isPrimaryPortrait(ctx))
831 deviceOrientation = (deviceOrientation + 1) % 4;
832 if (deviceOrientation == 0)
833 extOrientation = HWC_TRANSFORM_ROT_270;
834 else if (deviceOrientation == 1)//90
835 extOrientation = 0;
836 else if (deviceOrientation == 2)//180
837 extOrientation = HWC_TRANSFORM_ROT_90;
838 else if (deviceOrientation == 3)//270
839 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
840
841 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700842}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700843
Raj kamal59fea562014-04-01 16:52:19 +0530844/* Get External State names */
845const char* getExternalDisplayState(uint32_t external_state) {
846 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
847 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
848 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
849 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
850 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
851
852 if(external_state >= EXTERNAL_MAXSTATES) {
853 return "EXTERNAL_INVALID";
854 }
855
856 return externalStates[external_state];
857}
858
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530859bool isDownscaleRequired(hwc_layer_1_t const* layer) {
860 hwc_rect_t displayFrame = layer->displayFrame;
861 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
862 int dst_w, dst_h, src_w, src_h;
863 dst_w = displayFrame.right - displayFrame.left;
864 dst_h = displayFrame.bottom - displayFrame.top;
865 src_w = sourceCrop.right - sourceCrop.left;
866 src_h = sourceCrop.bottom - sourceCrop.top;
867
868 if(((src_w > dst_w) || (src_h > dst_h)))
869 return true;
870
871 return false;
872}
873bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500874 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500875 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700876 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500877
878 dst_w = displayFrame.right - displayFrame.left;
879 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500880 src_w = sourceCrop.right - sourceCrop.left;
881 src_h = sourceCrop.bottom - sourceCrop.top;
882
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800883 if(layer->transform & HWC_TRANSFORM_ROT_90)
884 swap(src_w, src_h);
885
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800886 if(((src_w != dst_w) || (src_h != dst_h)))
887 return true;
888
889 return false;
890}
891
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700892// Checks if layer needs scaling with split
893bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
894 const int& dpy) {
895
896 int src_width_l, src_height_l;
897 int src_width_r, src_height_r;
898 int dst_width_l, dst_height_l;
899 int dst_width_r, dst_height_r;
900 int hw_w = ctx->dpyAttr[dpy].xres;
901 int hw_h = ctx->dpyAttr[dpy].yres;
902 hwc_rect_t cropL, dstL, cropR, dstR;
903 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700904 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700905 hwc_rect_t displayFrame = layer->displayFrame;
906 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700907
908 cropL = sourceCrop;
909 dstL = displayFrame;
910 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800911 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700912 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
913
914 cropR = sourceCrop;
915 dstR = displayFrame;
916 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800917 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700918 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
919
920 // Sanitize Crop to stitch
921 sanitizeSourceCrop(cropL, cropR, hnd);
922
923 // Calculate the left dst
924 dst_width_l = dstL.right - dstL.left;
925 dst_height_l = dstL.bottom - dstL.top;
926 src_width_l = cropL.right - cropL.left;
927 src_height_l = cropL.bottom - cropL.top;
928
929 // check if there is any scaling on the left
930 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
931 return true;
932
933 // Calculate the right dst
934 dst_width_r = dstR.right - dstR.left;
935 dst_height_r = dstR.bottom - dstR.top;
936 src_width_r = cropR.right - cropR.left;
937 src_height_r = cropR.bottom - cropR.top;
938
939 // check if there is any scaling on the right
940 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
941 return true;
942
943 return false;
944}
945
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530946bool isAlphaScaled(hwc_layer_1_t const* layer) {
947 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530948 return true;
949 }
950 return false;
951}
952
953bool isAlphaPresent(hwc_layer_1_t const* layer) {
954 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400955 if(hnd) {
956 int format = hnd->format;
957 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530958 case HAL_PIXEL_FORMAT_RGBA_8888:
959 case HAL_PIXEL_FORMAT_BGRA_8888:
960 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500961 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530962 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400963 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500964 }
965 return false;
966}
967
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700968static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
969 hwc_rect_t& crop, hwc_rect_t& dst) {
970 int hw_w = ctx->dpyAttr[dpy].xres;
971 int hw_h = ctx->dpyAttr[dpy].yres;
972 if(dst.left < 0 || dst.top < 0 ||
973 dst.right > hw_w || dst.bottom > hw_h) {
974 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800975 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700976 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
977 }
978}
979
980static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
981 const int& dpy) {
982 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
983 hwc_layer_1_t *layer = &list->hwLayers[i];
984 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700985 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
986 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700987 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700988 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700989 (hwc_rect_t&)crop,
990 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530991 layer->sourceCropf.left = (float)crop.left;
992 layer->sourceCropf.right = (float)crop.right;
993 layer->sourceCropf.top = (float)crop.top;
994 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700995 }
996}
997
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700998void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700999 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001000 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1001 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301002 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1003 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001004 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301005 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001006 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001007 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001008 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001009 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001010 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301011 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001012 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301013 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001014 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001015 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1016 uint32_t refreshRate = 0;
1017 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001018 int s3dFormat = HAL_NO_3D;
1019 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001020
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001021 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001022 resetROI(ctx, dpy);
1023
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001024 trimList(ctx, list, dpy);
1025 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001026 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001027 hwc_layer_1_t const* layer = &list->hwLayers[i];
1028 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001029
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001030#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001031 // Window boxing feature is applicable obly for external display, So
1032 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001033 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001034 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001035 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001036 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1037 ctx->listStats[dpy].isDisplayAnimating = true;
1038 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001039 if(isSecureDisplayBuffer(hnd)) {
1040 ctx->listStats[dpy].secureUI = true;
1041 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001042#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001043 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1044 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001045 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001046
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001047 //reset yuv indices
1048 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301049 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001050
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001051 if (isSecureBuffer(hnd)) {
1052 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001053 if(not isYuvBuffer(hnd)) {
1054 // cache secureRGB layer parameters like we cache for YUV layers
1055 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1056 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1057 secureRGBCount++;
1058 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001059 }
1060
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001061 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001062 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001063 }
1064
1065 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001066 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301067 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001068 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001069
Raj Kamal389d6e32014-08-04 14:43:24 +05301070 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301071 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301072 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301073 yuv4k2kCount++;
1074 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001075
1076 // Gets set if one YUV layer is 3D
1077 if (displaySupports3D(ctx,dpy)) {
1078 s3dFormat = get3DFormat(hnd);
1079 if(s3dFormat != HAL_NO_3D)
1080 s3dLayerCount++;
1081 }
1082
Naseer Ahmed29a26812012-06-14 00:56:20 -07001083 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301084 if(layer->blending == HWC_BLENDING_PREMULT)
1085 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001086
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001087#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301088 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001089 //dyn fps: get refreshrate from metadata
1090 //Support multiple refresh rates if they are same
1091 //else set to default
1092 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1093 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1094 // Valid refreshRate in metadata and within the range
1095 uint32_t rate = roundOff(mdata->refreshrate);
1096 if((rate >= mdpHw.getMinFpsSupported() &&
1097 rate <= mdpHw.getMaxFpsSupported())) {
1098 if (!refreshRate) {
1099 refreshRate = rate;
1100 } else if(refreshRate != rate) {
1101 // multiple refreshrate requests, set to default
1102 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1103 }
1104 }
1105 }
1106 }
1107#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001108 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001109
1110 //Set the TV's 3D mode based on format if it was not forced
1111 //Only one 3D YUV layer is supported on external
1112 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1113 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1114 //XXX: Rapidly going in and out of 3D mode in some cases such
1115 // as rotation might cause flickers. The OEMs are recommended to disable
1116 // rotation on HDMI globally or in the app that plays 3D video
1117 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1118 }
1119
Ping Li9404e2a2013-04-24 16:36:03 -04001120 if(ctx->listStats[dpy].yuvCount > 0) {
1121 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1122 if (atoi(property) != 1) {
1123 property_set("hw.cabl.yuv", "1");
1124 }
1125 }
1126 } else {
1127 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1128 if (atoi(property) != 0) {
1129 property_set("hw.cabl.yuv", "0");
1130 }
1131 }
1132 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001133
1134 //The marking of video begin/end is useful on some targets where we need
1135 //to have a padding round to be able to shift pipes across mixers.
1136 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1137 ctx->mVideoTransFlag = true;
1138 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301139
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001140 if(dpy == HWC_DISPLAY_PRIMARY) {
1141 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001142 //Store the requested fresh rate
1143 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1144 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001145 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001146}
1147
Naseer Ahmed018e5452012-12-03 14:46:15 -05001148
Saurabh Shah68107422013-07-09 11:12:42 -07001149static void calc_cut(double& leftCutRatio, double& topCutRatio,
1150 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001151 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001152 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001153 }
1154 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001155 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001156 }
1157 if(orient & HAL_TRANSFORM_ROT_90) {
1158 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001159 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001160 leftCutRatio = topCutRatio;
1161 topCutRatio = rightCutRatio;
1162 rightCutRatio = bottomCutRatio;
1163 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001164 }
1165}
1166
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001167bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001168 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1169 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1170 ctx->mSecuring) {
1171 return true;
1172 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001173 if (isSecureModePolicy(ctx->mMDP.version)) {
1174 private_handle_t *hnd = (private_handle_t *)layer->handle;
1175 if(ctx->mSecureMode) {
1176 if (! isSecureBuffer(hnd)) {
1177 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1178 __FUNCTION__);
1179 return true;
1180 }
1181 } else {
1182 if (isSecureBuffer(hnd)) {
1183 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1184 __FUNCTION__);
1185 return true;
1186 }
1187 }
1188 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001189 return false;
1190}
1191
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001192bool isSecureModePolicy(int mdpVersion) {
1193 if (mdpVersion < qdutils::MDSS_V5)
1194 return true;
1195 else
1196 return false;
1197}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001198
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001199bool isRotatorSupportedFormat(private_handle_t *hnd) {
1200 // Following rotator src formats are supported by mdp driver
1201 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001202 if(hnd != NULL) {
1203 switch(hnd->format) {
1204 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001205 case HAL_PIXEL_FORMAT_RGBA_5551:
1206 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001207 case HAL_PIXEL_FORMAT_RGB_565:
1208 case HAL_PIXEL_FORMAT_RGB_888:
1209 case HAL_PIXEL_FORMAT_BGRA_8888:
1210 return true;
1211 default:
1212 return false;
1213 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001214 }
1215 return false;
1216}
1217
1218bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001219 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001220 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001221 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001222 !ctx->mMDP.version < qdutils::MDSS_V5)
1223 || isYuvBuffer(hnd)) {
1224 return true;
1225 }
1226 return false;
1227}
1228
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001229// returns true if Action safe dimensions are set and target supports Actionsafe
1230bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1231 // if external supports underscan, do nothing
1232 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001233 // Disable Action safe for 8974 due to HW limitation for downscaling
1234 // layers with overlapped region
1235 // Disable Actionsafe for non HDMI displays.
1236 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1237 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001238 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001239 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001240 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001241
1242 char value[PROPERTY_VALUE_MAX];
1243 // Read action safe properties
1244 property_get("persist.sys.actionsafe.width", value, "0");
1245 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1246 property_get("persist.sys.actionsafe.height", value, "0");
1247 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1248
1249 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1250 //No action safe ratio set, return
1251 return false;
1252 }
1253 return true;
1254}
1255
Naseer Ahmed522ce662013-03-18 20:14:05 -04001256int getBlending(int blending) {
1257 switch(blending) {
1258 case HWC_BLENDING_NONE:
1259 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1260 case HWC_BLENDING_PREMULT:
1261 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1262 case HWC_BLENDING_COVERAGE :
1263 default:
1264 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1265 }
1266}
1267
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001268//Crops source buffer against destination and FB boundaries
1269void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001270 const hwc_rect_t& scissor, int orient) {
1271
Saurabh Shah27c1d652012-08-14 19:30:28 -07001272 int& crop_l = crop.left;
1273 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001274 int& crop_r = crop.right;
1275 int& crop_b = crop.bottom;
1276 int crop_w = crop.right - crop.left;
1277 int crop_h = crop.bottom - crop.top;
1278
Saurabh Shah27c1d652012-08-14 19:30:28 -07001279 int& dst_l = dst.left;
1280 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001281 int& dst_r = dst.right;
1282 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001283 int dst_w = abs(dst.right - dst.left);
1284 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001285
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001286 const int& sci_l = scissor.left;
1287 const int& sci_t = scissor.top;
1288 const int& sci_r = scissor.right;
1289 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001290
Saurabh Shah68107422013-07-09 11:12:42 -07001291 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1292 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001293
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001294 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001295 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001296 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001297 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001298
1299 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001300 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001301 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001302 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001303
1304 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001305 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001306 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001307 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001308
1309 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001310 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001311 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001312 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001313
Saurabh Shah541b59d2012-10-11 11:08:12 -07001314 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301315 crop_l += (int)round((double)crop_w * leftCutRatio);
1316 crop_t += (int)round((double)crop_h * topCutRatio);
1317 crop_r -= (int)round((double)crop_w * rightCutRatio);
1318 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001319}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001320
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301321bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1322 const hwc_layer_1_t* layer2) {
1323 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1324 layer2->displayFrame);
1325 return isValidRect(irect);
1326}
1327
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001328bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1329{
1330 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1331 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1332}
1333
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001334bool isValidRect(const hwc_rect& rect)
1335{
1336 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301337}
1338
Ramakant Singh21cec722014-03-07 19:11:45 +05301339bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1340 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1341 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1342 return true ;
1343 return false;
1344}
1345
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001346hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1347{
1348 hwc_rect_t res;
1349
1350 if(!isValidRect(rect))
1351 return (hwc_rect_t){0, 0, 0, 0};
1352
1353 res.left = rect.left + x_off;
1354 res.top = rect.top + y_off;
1355 res.right = rect.right + x_off;
1356 res.bottom = rect.bottom + y_off;
1357
1358 return res;
1359}
1360
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001361/* computes the intersection of two rects */
1362hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1363{
1364 hwc_rect_t res;
1365
1366 if(!isValidRect(rect1) || !isValidRect(rect2)){
1367 return (hwc_rect_t){0, 0, 0, 0};
1368 }
1369
1370
1371 res.left = max(rect1.left, rect2.left);
1372 res.top = max(rect1.top, rect2.top);
1373 res.right = min(rect1.right, rect2.right);
1374 res.bottom = min(rect1.bottom, rect2.bottom);
1375
1376 if(!isValidRect(res))
1377 return (hwc_rect_t){0, 0, 0, 0};
1378
1379 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301380}
1381
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001382/* computes the union of two rects */
1383hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1384{
1385 hwc_rect_t res;
1386
1387 if(!isValidRect(rect1)){
1388 return rect2;
1389 }
1390
1391 if(!isValidRect(rect2)){
1392 return rect1;
1393 }
1394
1395 res.left = min(rect1.left, rect2.left);
1396 res.top = min(rect1.top, rect2.top);
1397 res.right = max(rect1.right, rect2.right);
1398 res.bottom = max(rect1.bottom, rect2.bottom);
1399
1400 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301401}
1402
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001403/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1404 * a single rect */
1405hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301406
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001407 hwc_rect_t res = rect1;
1408
1409 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1410 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1411 res.top = rect2.bottom;
1412 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1413 res.bottom = rect2.top;
1414 }
1415 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1416 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1417 res.left = rect2.right;
1418 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1419 res.right = rect2.left;
1420 }
1421 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301422}
1423
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001424void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301425 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301426 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301427 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001428 //If it is opaque see if we can substract this region from below
1429 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301430 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1431 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301432 int j= i-1;
1433 hwc_rect_t& topframe =
1434 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1435 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301436 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001437 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1438 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001439 hwc_rect_t bottomCrop =
1440 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001441 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1442 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001443
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001444 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1445 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001446 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001447 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001448 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001449 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001450 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001451 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301452 layer->sourceCropf.left =(float)bottomCrop.left;
1453 layer->sourceCropf.top = (float)bottomCrop.top;
1454 layer->sourceCropf.right = (float)bottomCrop.right;
1455 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001456#ifdef QCOM_BSP
1457 //Update layer dirtyRect
1458 layer->dirtyRect = getIntersection(bottomCrop,
1459 layer->dirtyRect);
1460#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001461 }
1462 }
1463 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301464 }
1465 }
1466 i--;
1467 }
1468}
1469
Naseer Ahmed64b81212013-02-14 10:29:47 -05001470void getNonWormholeRegion(hwc_display_contents_1_t* list,
1471 hwc_rect_t& nwr)
1472{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301473 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001474 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1475 //Initiliaze nwr to first frame
1476 nwr.left = list->hwLayers[0].displayFrame.left;
1477 nwr.top = list->hwLayers[0].displayFrame.top;
1478 nwr.right = list->hwLayers[0].displayFrame.right;
1479 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1480
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301481 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001482 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001483 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001484 }
1485
1486 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001487 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001488}
1489
Saurabh Shah747af1e2013-02-26 10:25:12 -08001490void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001491 if(LIKELY(list)) {
1492 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1493 //Close the acquireFenceFds
1494 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1495 if(list->hwLayers[i].acquireFenceFd >= 0) {
1496 close(list->hwLayers[i].acquireFenceFd);
1497 list->hwLayers[i].acquireFenceFd = -1;
1498 }
1499 }
1500 //Writeback
1501 if(list->outbufAcquireFenceFd >= 0) {
1502 close(list->outbufAcquireFenceFd);
1503 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001504 }
1505 }
1506}
1507
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001508int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001509 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001510 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001511 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001512 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001513 int count = 0;
1514 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001515 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001516 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001517 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001518
1519 struct mdp_buf_sync data;
1520 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001521 data.acq_fen_fd = acquireFd;
1522 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001523 data.retire_fen_fd = &retireFd;
1524 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001525
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001526 char property[PROPERTY_VALUE_MAX];
1527 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1528 if(atoi(property) == 0)
1529 swapzero = true;
1530 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001531
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001532 bool isExtAnimating = false;
1533 if(dpy)
1534 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001535
Saurabh Shah23a813c2013-03-20 16:58:12 -07001536 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001537 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001538 int rotFd = ctx->mRotMgr->getRotDevFd();
1539 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001540 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1541 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1542 if((currRot == NULL) || (currLayer == NULL)) {
1543 continue;
1544 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001545 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001546 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001547 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001548 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001549 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001550 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001551 if(currLayer->acquireFenceFd >= 0) {
1552 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1553 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001554 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301555 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301556 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1557
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001558 if(ret < 0) {
1559 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1560 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001561 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001562 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001563 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001564 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001565 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001566 dup(rotReleaseFd);
1567 //A buffer is free to be used by producer as soon as its copied to
1568 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001569 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001570 rotReleaseFd;
1571 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001572 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001573
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301574 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001575 if(list->outbufAcquireFenceFd >= 0) {
1576 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301577 if(LIKELY(!swapzero) )
1578 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001579 }
1580
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001581 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301582 if(((isAbcInUse(ctx)== true ) ||
1583 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001584 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301585 if(LIKELY(!swapzero) ) {
1586 // if ABC is enabled for more than one layer.
1587 // renderBufIndexforABC will work as FB.Hence
1588 // set the acquireFD from fd - which is coming from copybit
1589 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1590 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1591 acquireFd[count++] = fd;
1592 else
1593 continue;
1594 } else
1595 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1596 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001597 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001598 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301599 if(LIKELY(!swapzero) ) {
1600 if(fd >= 0) {
1601 //set the acquireFD from fd - which is coming from c2d
1602 acquireFd[count++] = fd;
1603 // Buffer sync IOCTL should be async when using c2d fence is
1604 // used
1605 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1606 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1607 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1608 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001609 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001610 }
1611
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001612 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001613 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301614 if(LIKELY(!swapzero) )
1615 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001616 }
1617
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001618 data.acq_fen_fd_cnt = count;
1619 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001620
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001621 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001622 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001623 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001624 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001625
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001626 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001627 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1628 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301629 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001630 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1631 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001632 close(releaseFd);
1633 releaseFd = -1;
1634 close(retireFd);
1635 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001636 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001637
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001638 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001639 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001640#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001641 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001642#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001643 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001644 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001645 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001646 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001647 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001648 // Release all the app layer fds immediately,
1649 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001650 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001651 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001652#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001653 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301654 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301655
1656 // if ABC is enabled for more than one layer
1657 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1658 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1659 list->hwLayers[i].releaseFenceFd = dup(fd);
1660 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1661 (isAbcInUse(ctx) == false)){
1662 //For Blit, the app layers should be released when the Blit
1663 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301664 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001665 } else
1666#endif
1667 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301668 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1669 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001670 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001671 }
1672 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001673
1674 if(fd >= 0) {
1675 close(fd);
1676 fd = -1;
1677 }
1678
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001679 if (ctx->mCopyBit[dpy]) {
1680 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001681 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1682 else
1683 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1684 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001685
Saurabh Shah23a813c2013-03-20 16:58:12 -07001686 //Signals when MDP finishes reading rotator buffers.
1687 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001688 close(releaseFd);
1689 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001690
Arun Kumar K.R51835182013-11-19 11:20:28 -08001691 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001692 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001693 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001694 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001695 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001696 return ret;
1697}
1698
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001699void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001700 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001701 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001702 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001703 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001704
1705 if(layer->blending == HWC_BLENDING_PREMULT) {
1706 ovutils::setMdpFlags(mdpFlags,
1707 ovutils::OV_MDP_BLEND_FG_PREMULT);
1708 }
1709
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001710 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1711 metadata->interlaced) {
1712 ovutils::setMdpFlags(mdpFlags,
1713 ovutils::OV_MDP_DEINTERLACE);
1714 }
1715
1716 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1717 if(isSecureBuffer(hnd)) {
1718 ovutils::setMdpFlags(mdpFlags,
1719 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301720 ovutils::setMdpFlags(mdpFlags,
1721 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1722 }
1723
1724 if(isProtectedBuffer(hnd)) {
1725 ovutils::setMdpFlags(mdpFlags,
1726 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001727 }
1728
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001729 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001730 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001731 ovutils::setMdpFlags(mdpFlags,
1732 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1733 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001734
1735 //Pre-rotation will be used using rotator.
1736 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1737 ovutils::setMdpFlags(mdpFlags,
1738 ovutils::OV_MDP_SOURCE_ROTATED_90);
1739 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001740 //No 90 component and no rot-downscale then flips done by MDP
1741 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001742 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1743 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001744 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1745 }
1746
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001747 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001748 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1749 }
1750 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001751
1752 if(metadata &&
1753 ((metadata->operation & PP_PARAM_HSIC)
1754 || (metadata->operation & PP_PARAM_IGC)
1755 || (metadata->operation & PP_PARAM_SHARP2))) {
1756 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1757 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001758}
1759
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301760int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001761 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001762 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001763
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301764 // Fix alignments for TILED format
1765 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1766 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1767 whf.w = utils::alignup(whf.w, 64);
1768 whf.h = utils::alignup(whf.h, 32);
1769 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001770 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001771
1772 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1773 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001774 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1775 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001776 rot->setCrop(rotCrop);
1777 }
1778
Saurabh Shahacf10202013-02-26 10:15:15 -08001779 rot->setFlags(mdpFlags);
1780 rot->setTransform(orient);
1781 rot->setDownscale(downscale);
1782 if(!rot->commit()) return -1;
1783 return 0;
1784}
1785
Saurabh Shahe2474082013-05-15 16:32:13 -07001786int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001787 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001788 const hwc_rect_t& pos, const MetaData_t *metadata,
1789 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001790 ov->setSource(parg, dest);
1791 ov->setTransform(orient, dest);
1792
1793 int crop_w = crop.right - crop.left;
1794 int crop_h = crop.bottom - crop.top;
1795 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1796 ov->setCrop(dcrop, dest);
1797
1798 int posW = pos.right - pos.left;
1799 int posH = pos.bottom - pos.top;
1800 Dim position(pos.left, pos.top, posW, posH);
1801 ov->setPosition(position, dest);
1802
Saurabh Shah5daeee52013-01-23 16:52:26 +08001803 if (metadata)
1804 ov->setVisualParams(*metadata, dest);
1805
Saurabh Shahacf10202013-02-26 10:15:15 -08001806 if (!ov->commit(dest)) {
1807 return -1;
1808 }
1809 return 0;
1810}
1811
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001812int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1813 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001814 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001815
1816 hwc_rect_t dst = layer->displayFrame;
1817 trimLayer(ctx, dpy, 0, dst, dst);
1818
1819 int w = ctx->dpyAttr[dpy].xres;
1820 int h = ctx->dpyAttr[dpy].yres;
1821 int dst_w = dst.right - dst.left;
1822 int dst_h = dst.bottom - dst.top;
1823 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001824 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001825
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001826 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001827 if (layer->blending == HWC_BLENDING_PREMULT)
1828 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1829
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001830 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001831 layer->planeAlpha,
1832 (ovutils::eBlending) getBlending(layer->blending));
1833
1834 // Configure MDP pipe for Color layer
1835 Dim pos(dst.left, dst.top, dst_w, dst_h);
1836 ctx->mOverlay->setSource(parg, dest);
1837 ctx->mOverlay->setColor(color, dest);
1838 ctx->mOverlay->setTransform(0, dest);
1839 ctx->mOverlay->setCrop(pos, dest);
1840 ctx->mOverlay->setPosition(pos, dest);
1841
1842 if (!ctx->mOverlay->commit(dest)) {
1843 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1844 return -1;
1845 }
1846 return 0;
1847}
1848
Saurabh Shahe2474082013-05-15 16:32:13 -07001849void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001850 hwc_rect_t& crop, Rotator *rot) {
1851 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001852 crop.right - crop.left,
1853 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001854 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1855 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001856 //B-family rotator internally could modify destination dimensions if
1857 //downscaling is supported
1858 whf = rot->getDstWhf();
1859 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001860 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001861 //A-family rotator rotates entire buffer irrespective of crop, forcing
1862 //us to recompute the crop based on transform
1863 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1864 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001865 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001866
1867 crop.left = transformedCrop.x;
1868 crop.top = transformedCrop.y;
1869 crop.right = transformedCrop.x + transformedCrop.w;
1870 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001871}
1872
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001873int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1874 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1875 return 0;
1876 }
1877
1878 int downscale = 0;
1879 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1880 hwc_rect_t dst = layer->displayFrame;
1881 private_handle_t *hnd = (private_handle_t *)layer->handle;
1882
1883 if(not hnd) {
1884 return 0;
1885 }
1886
1887 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1888 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1889 && metadata->interlaced;
1890 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001891 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001892
1893 if(isYuvBuffer(hnd)) {
1894 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1895 ctx->mMDP.version < qdutils::MDSS_V5) {
1896 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1897 crop.bottom - crop.top, dst.right - dst.left,
1898 dst.bottom - dst.top, format, isInterlaced);
1899 } else {
1900 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1901 crop.bottom - crop.top);
1902 Dim pos(dst.left, dst.top, dst.right - dst.left,
1903 dst.bottom - dst.top);
1904 if(transform & HAL_TRANSFORM_ROT_90) {
1905 swap(adjCrop.w, adjCrop.h);
1906 }
1907 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1908 pos.h, format, isInterlaced);
1909 }
1910 }
1911 return downscale;
1912}
1913
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001914bool isZoomModeEnabled(hwc_rect_t crop) {
1915 // This does not work for zooming in top left corner of the image
1916 return(crop.top > 0 || crop.left > 0);
1917}
1918
1919void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1920 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1921 crop.left, crop.top, crop.right, crop.bottom);
1922 if(isZoomModeEnabled(crop)) {
1923 Dim srcCrop(crop.left, crop.top,
1924 crop.right - crop.left,
1925 crop.bottom - crop.top);
1926 int extW = ctx->dpyAttr[dpy].xres;
1927 int extH = ctx->dpyAttr[dpy].yres;
1928 //Crop the original video in order to fit external display aspect ratio
1929 if(srcCrop.w * extH < extW * srcCrop.h) {
1930 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1931 crop.top += offset;
1932 crop.bottom -= offset;
1933 } else {
1934 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1935 crop.left += offset;
1936 crop.right -= offset;
1937 }
1938 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1939 " source crop [%d %d %d %d]", extW, extH, dpy,
1940 crop.left, crop.top, crop.right, crop.bottom);
1941 }
1942}
1943
1944void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1945 hwc_rect_t& dst, int dpy) {
1946 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1947 dst.left, dst.top, dst.right, dst.bottom);
1948 Dim srcCrop(crop.left, crop.top,
1949 crop.right - crop.left,
1950 crop.bottom - crop.top);
1951 int extW = ctx->dpyAttr[dpy].xres;
1952 int extH = ctx->dpyAttr[dpy].yres;
1953 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07001954 // when zoom in mode is enabled or the ratio between video aspect ratio
1955 // and external display aspect ratio is below the minimum tolerance level
1956 // and above maximum tolerance level
1957 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
1958 float extDisplayAspectRatio = ((float)extW / (float)extH);
1959 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
1960 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
1961 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001962 dst.left = 0;
1963 dst.top = 0;
1964 dst.right = extW;
1965 dst.bottom = extH;
1966 }
1967 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1968 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
1969 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
1970 crop.left, crop.top, crop.right, crop.bottom);
1971}
1972
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001973void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001974 hwc_rect_t& dst, int dpy) {
1975 updateCropAIVVideoMode(ctx, crop, dpy);
1976 updateDestAIVVideoMode(ctx, crop, dst, dpy);
1977}
1978
Saurabh Shah88e4d272013-09-03 13:31:29 -07001979int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001980 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001981 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001982
1983 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001984
Saurabh Shahacf10202013-02-26 10:15:15 -08001985 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001986 if (layer->flags & HWC_COLOR_FILL) {
1987 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001988 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001989 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001990 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1991 return -1;
1992 }
1993
Saurabh Shah5daeee52013-01-23 16:52:26 +08001994 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1995
Saurabh Shah62e1d732013-09-17 10:44:05 -07001996 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001997 hwc_rect_t dst = layer->displayFrame;
1998 int transform = layer->transform;
1999 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002000 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002001 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302002 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002003
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002004 // Handle R/B swap
2005 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2006 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2007 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2008 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2009 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2010 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002011 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002012 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2013 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002014 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002015 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002016 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002017 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002018
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002019 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002020 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002021 *rot = ctx->mRotMgr->getNext();
2022 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002023 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002024 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2025 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002026 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002027 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2028 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002029 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002030 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002031 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002032 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002033 }
2034
Saurabh Shah76fd6552013-03-14 14:45:38 -07002035 //For the mdp, since either we are pre-rotating or MDP does flips
2036 orient = OVERLAY_TRANSFORM_0;
2037 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002038 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002039 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2040 (ovutils::eBlending) getBlending(layer->blending));
2041
Saurabh Shah5daeee52013-01-23 16:52:26 +08002042 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002043 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2044 return -1;
2045 }
2046 return 0;
2047}
2048
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002049//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002050void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002051 private_handle_t *hnd) {
2052 if(cropL.right - cropL.left) {
2053 if(isYuvBuffer(hnd)) {
2054 //Always safe to even down left
2055 ovutils::even_floor(cropL.left);
2056 //If right is even, automatically width is even, since left is
2057 //already even
2058 ovutils::even_floor(cropL.right);
2059 }
2060 //Make sure there are no gaps between left and right splits if the layer
2061 //is spread across BOTH halves
2062 if(cropR.right - cropR.left) {
2063 cropR.left = cropL.right;
2064 }
2065 }
2066
2067 if(cropR.right - cropR.left) {
2068 if(isYuvBuffer(hnd)) {
2069 //Always safe to even down left
2070 ovutils::even_floor(cropR.left);
2071 //If right is even, automatically width is even, since left is
2072 //already even
2073 ovutils::even_floor(cropR.right);
2074 }
2075 }
2076}
2077
Saurabh Shah88e4d272013-09-03 13:31:29 -07002078int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002079 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002080 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002081 Rotator **rot) {
2082 private_handle_t *hnd = (private_handle_t *)layer->handle;
2083 if(!hnd) {
2084 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2085 return -1;
2086 }
2087
Saurabh Shah5daeee52013-01-23 16:52:26 +08002088 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2089
Saurabh Shahacf10202013-02-26 10:15:15 -08002090 int hw_w = ctx->dpyAttr[dpy].xres;
2091 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002092 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002093 hwc_rect_t dst = layer->displayFrame;
2094 int transform = layer->transform;
2095 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002096 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002097 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302098 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002099
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002100 // Handle R/B swap
2101 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2102 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2103 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2104 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2105 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2106 }
2107
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002108 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002109 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2110 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002111 }
2112
2113 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002114 ActionSafe, and extorientation features. */
2115 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002116 int downscale = getRotDownscale(ctx, layer);
2117 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002118
2119 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2120 //Enable overfetch
2121 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2122 }
2123
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002124 //Will do something only if feature enabled and conditions suitable
2125 //hollow call otherwise
2126 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2127 overlay::Writeback *wb = overlay::Writeback::getInstance();
2128 whf.format = wb->getOutputFormat();
2129 }
2130
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002131 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002132 (*rot) = ctx->mRotMgr->getNext();
2133 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002134 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002135 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002136 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2137 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002138 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002139 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002140 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002141 rotFlags |= ROT_PREROTATED;
2142 }
2143
2144 eMdpFlags mdpFlagsR = mdpFlagsL;
2145 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2146
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002147 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2148 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002149
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002150 const int lSplit = getLeftSplit(ctx, dpy);
2151
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002152 // Calculate Left rects
2153 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002154 tmp_cropL = crop;
2155 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002156 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002157 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002158 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2159 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002160
2161 // Calculate Right rects
2162 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002163 tmp_cropR = crop;
2164 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002165 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002166 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002167 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2168 }
2169
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002170 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2171
Saurabh Shah94d62362013-07-02 10:58:48 -07002172 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002173 //Not needed if the layer is confined to one half of the screen.
2174 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002175 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2176 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002177 hwc_rect_t new_cropR;
2178 new_cropR.left = tmp_cropL.left;
2179 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2180
2181 hwc_rect_t new_cropL;
2182 new_cropL.left = new_cropR.right;
2183 new_cropL.right = tmp_cropR.right;
2184
2185 tmp_cropL.left = new_cropL.left;
2186 tmp_cropL.right = new_cropL.right;
2187
2188 tmp_cropR.left = new_cropR.left;
2189 tmp_cropR.right = new_cropR.right;
2190
2191 }
2192
Saurabh Shah76fd6552013-03-14 14:45:38 -07002193 //For the mdp, since either we are pre-rotating or MDP does flips
2194 orient = OVERLAY_TRANSFORM_0;
2195 transform = 0;
2196
Saurabh Shahacf10202013-02-26 10:15:15 -08002197 //configure left mixer
2198 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002199 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002200 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2201 (ovutils::eBlending) getBlending(layer->blending));
2202
Saurabh Shahacf10202013-02-26 10:15:15 -08002203 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002204 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002205 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2206 return -1;
2207 }
2208 }
2209
2210 //configure right mixer
2211 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002212 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002213 static_cast<eRotFlags>(rotFlags),
2214 layer->planeAlpha,
2215 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002216 tmp_dstR.right = tmp_dstR.right - lSplit;
2217 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002218 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002219 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002220 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2221 return -1;
2222 }
2223 }
2224
2225 return 0;
2226}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002227
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002228int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2229 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2230 const eDest& lDest, const eDest& rDest,
2231 Rotator **rot) {
2232 private_handle_t *hnd = (private_handle_t *)layer->handle;
2233 if(!hnd) {
2234 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2235 return -1;
2236 }
2237 //Both pipes are configured to the same mixer
2238 eZorder lz = z;
2239 eZorder rz = (eZorder)(z + 1);
2240
2241 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2242
2243 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2244 hwc_rect_t dst = layer->displayFrame;
2245 int transform = layer->transform;
2246 eTransform orient = static_cast<eTransform>(transform);
2247 int rotFlags = ROT_FLAGS_NONE;
2248 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2249 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2250
2251 int downscale = getRotDownscale(ctx, layer);
2252 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2253
2254 //XXX: Check if rotation is supported and valid for 3D
2255 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2256 (*rot) = ctx->mRotMgr->getNext();
2257 if((*rot) == NULL) return -1;
2258 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2259 //Configure rotator for pre-rotation
2260 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2261 ALOGE("%s: configRotator failed!", __FUNCTION__);
2262 return -1;
2263 }
2264 updateSource(orient, whf, crop, *rot);
2265 rotFlags |= ROT_PREROTATED;
2266 }
2267
2268 eMdpFlags mdpFlagsR = mdpFlagsL;
2269
2270 hwc_rect_t cropL = crop, dstL = dst;
2271 hwc_rect_t cropR = crop, dstR = dst;
2272 int hw_w = ctx->dpyAttr[dpy].xres;
2273 int hw_h = ctx->dpyAttr[dpy].yres;
2274
2275 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2276 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2277 // Calculate Left rects
2278 // XXX: This assumes crop.right/2 is the center point of the video
2279 cropL.right = crop.right/2;
2280 dstL.left = dst.left/2;
2281 dstL.right = dst.right/2;
2282
2283 // Calculate Right rects
2284 cropR.left = crop.right/2;
2285 dstR.left = hw_w/2 + dst.left/2;
2286 dstR.right = hw_w/2 + dst.right/2;
2287 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2288 // Calculate Left rects
2289 cropL.bottom = crop.bottom/2;
2290 dstL.top = dst.top/2;
2291 dstL.bottom = dst.bottom/2;
2292
2293 // Calculate Right rects
2294 cropR.top = crop.bottom/2;
2295 dstR.top = hw_h/2 + dst.top/2;
2296 dstR.bottom = hw_h/2 + dst.bottom/2;
2297 } else {
2298 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2299 return -1;
2300 }
2301
2302 //For the mdp, since either we are pre-rotating or MDP does flips
2303 orient = OVERLAY_TRANSFORM_0;
2304 transform = 0;
2305
2306 //configure left pipe
2307 if(lDest != OV_INVALID) {
2308 PipeArgs pargL(mdpFlagsL, whf, lz,
2309 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2310 (ovutils::eBlending) getBlending(layer->blending));
2311
2312 if(configMdp(ctx->mOverlay, pargL, orient,
2313 cropL, dstL, metadata, lDest) < 0) {
2314 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2315 return -1;
2316 }
2317 }
2318
2319 //configure right pipe
2320 if(rDest != OV_INVALID) {
2321 PipeArgs pargR(mdpFlagsR, whf, rz,
2322 static_cast<eRotFlags>(rotFlags),
2323 layer->planeAlpha,
2324 (ovutils::eBlending) getBlending(layer->blending));
2325 if(configMdp(ctx->mOverlay, pargR, orient,
2326 cropR, dstR, metadata, rDest) < 0) {
2327 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2328 return -1;
2329 }
2330 }
2331
2332 return 0;
2333}
2334
radhakrishnac9a67412013-09-25 17:40:42 +05302335int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2336 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002337 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302338 Rotator **rot) {
2339 private_handle_t *hnd = (private_handle_t *)layer->handle;
2340 if(!hnd) {
2341 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2342 return -1;
2343 }
2344
2345 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2346
radhakrishnac9a67412013-09-25 17:40:42 +05302347 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2348 hwc_rect_t dst = layer->displayFrame;
2349 int transform = layer->transform;
2350 eTransform orient = static_cast<eTransform>(transform);
2351 const int downscale = 0;
2352 int rotFlags = ROT_FLAGS_NONE;
2353 //Splitting only YUV layer on primary panel needs different zorders
2354 //for both layers as both the layers are configured to single mixer
2355 eZorder lz = z;
2356 eZorder rz = (eZorder)(z + 1);
2357
2358 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302359 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302360
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002361 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002362 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2363 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002364 }
2365
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002366 /* Calculate the external display position based on MDP downscale,
2367 ActionSafe, and extorientation features. */
2368 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2369
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002370 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302371 trimLayer(ctx, dpy, transform, crop, dst);
2372
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002373 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302374 (*rot) = ctx->mRotMgr->getNext();
2375 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002376 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302377 //Configure rotator for pre-rotation
2378 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2379 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302380 return -1;
2381 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002382 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302383 rotFlags |= ROT_PREROTATED;
2384 }
2385
2386 eMdpFlags mdpFlagsR = mdpFlagsL;
2387 int lSplit = dst.left + (dst.right - dst.left)/2;
2388
2389 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2390 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2391
2392 if(lDest != OV_INVALID) {
2393 tmp_cropL = crop;
2394 tmp_dstL = dst;
2395 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2396 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2397 }
2398 if(rDest != OV_INVALID) {
2399 tmp_cropR = crop;
2400 tmp_dstR = dst;
2401 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2402 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2403 }
2404
2405 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2406
2407 //When buffer is H-flipped, contents of mixer config also needs to swapped
2408 //Not needed if the layer is confined to one half of the screen.
2409 //If rotator has been used then it has also done the flips, so ignore them.
2410 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2411 && rDest != OV_INVALID && (*rot) == NULL) {
2412 hwc_rect_t new_cropR;
2413 new_cropR.left = tmp_cropL.left;
2414 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2415
2416 hwc_rect_t new_cropL;
2417 new_cropL.left = new_cropR.right;
2418 new_cropL.right = tmp_cropR.right;
2419
2420 tmp_cropL.left = new_cropL.left;
2421 tmp_cropL.right = new_cropL.right;
2422
2423 tmp_cropR.left = new_cropR.left;
2424 tmp_cropR.right = new_cropR.right;
2425
2426 }
2427
2428 //For the mdp, since either we are pre-rotating or MDP does flips
2429 orient = OVERLAY_TRANSFORM_0;
2430 transform = 0;
2431
2432 //configure left half
2433 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002434 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302435 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2436 (ovutils::eBlending) getBlending(layer->blending));
2437
2438 if(configMdp(ctx->mOverlay, pargL, orient,
2439 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2440 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2441 return -1;
2442 }
2443 }
2444
2445 //configure right half
2446 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002447 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302448 static_cast<eRotFlags>(rotFlags),
2449 layer->planeAlpha,
2450 (ovutils::eBlending) getBlending(layer->blending));
2451 if(configMdp(ctx->mOverlay, pargR, orient,
2452 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2453 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2454 return -1;
2455 }
2456 }
2457
2458 return 0;
2459}
2460
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002461bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302462 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002463 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002464 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302465 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302466 * in LINE and BLOCK modes for writeback panels.
2467 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002468 if(dpy == HWC_DISPLAY_PRIMARY)
2469 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002470 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302471 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2472 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002473 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002474 return true;
2475}
2476
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002477int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2478 //Default even split for all displays with high res
2479 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2480 if(dpy == HWC_DISPLAY_PRIMARY &&
2481 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2482 //Override if split published by driver for primary
2483 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2484 }
2485 return lSplit;
2486}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002487
Saurabh Shah88e4d272013-09-03 13:31:29 -07002488bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302489 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002490 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002491 return true;
2492 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302493 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002494 return true;
2495 }
2496 return false;
2497}
2498
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002499//clear prev layer prop flags and realloc for current frame
2500void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2501 if(ctx->layerProp[dpy]) {
2502 delete[] ctx->layerProp[dpy];
2503 ctx->layerProp[dpy] = NULL;
2504 }
2505 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2506}
2507
Ramakant Singh0def28c2014-03-28 20:43:13 +05302508bool isAbcInUse(hwc_context_t *ctx){
2509 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2510}
2511
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002512void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2513 if (ohnd != NULL && ohnd->base) {
2514 char dumpFilename[PATH_MAX];
2515 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002516 int width = getWidth(ohnd);
2517 int height = getHeight(ohnd);
2518 int format = ohnd->format;
2519 //dummy aligned w & h.
2520 int alW = 0, alH = 0;
2521 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002522 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2523 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002524 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2525 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002526 FILE* fp = fopen(dumpFilename, "w+");
2527 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002528 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002529 fclose(fp);
2530 }
2531 ALOGD("Buffer[%s] Dump to %s: %s",
2532 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2533 }
2534}
2535
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002536bool isGLESComp(hwc_context_t *ctx,
2537 hwc_display_contents_1_t* list) {
2538 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2539 for(int index = 0; index < numAppLayers; index++) {
2540 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2541 if(layer->compositionType == HWC_FRAMEBUFFER)
2542 return true;
2543 }
2544 return false;
2545}
2546
2547void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2548 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002549 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002550 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002551
2552#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002553 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2554 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2555 hint to default if the previous composition is GPU or current GPU
2556 composition is due to idle fallback */
2557 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2558 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2559 if(!gpuHint->mEGLDisplay) {
2560 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2561 return;
2562 }
2563 gpuHint->mEGLContext = eglGetCurrentContext();
2564 if(!gpuHint->mEGLContext) {
2565 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2566 return;
2567 }
2568 }
2569 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002570 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2571 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002572 EGLint attr_list[] = {EGL_GPU_HINT_1,
2573 EGL_GPU_LEVEL_3,
2574 EGL_NONE };
2575 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2576 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2577 gpuHint->mEGLContext, attr_list)) {
2578 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2579 } else {
2580 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002581 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002582 }
2583 } else {
2584 EGLint attr_list[] = {EGL_GPU_HINT_1,
2585 EGL_GPU_LEVEL_0,
2586 EGL_NONE };
2587 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2588 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2589 gpuHint->mEGLContext, attr_list)) {
2590 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2591 } else {
2592 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2593 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002594 if(MDPComp::isIdleFallback()) {
2595 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2596 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002597 }
2598 } else {
2599 /* set the GPU hint flag to default for MDP composition */
2600 EGLint attr_list[] = {EGL_GPU_HINT_1,
2601 EGL_GPU_LEVEL_0,
2602 EGL_NONE };
2603 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2604 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2605 gpuHint->mEGLContext, attr_list)) {
2606 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2607 } else {
2608 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2609 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002610 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002611 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002612#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002613}
2614
Sushil Chauhandefd3522014-05-13 18:17:12 -07002615bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2616 // To be peripheral, 3 boundaries should match.
2617 uint8_t eqBounds = 0;
2618 if (rect1.left == rect2.left)
2619 eqBounds++;
2620 if (rect1.top == rect2.top)
2621 eqBounds++;
2622 if (rect1.right == rect2.right)
2623 eqBounds++;
2624 if (rect1.bottom == rect2.bottom)
2625 eqBounds++;
2626 return (eqBounds == 3);
2627}
2628
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302629void processBootAnimCompleted(hwc_context_t *ctx) {
2630 char value[PROPERTY_VALUE_MAX];
2631 int boot_finished = 0, ret = -1;
2632 int (*applyMode)(int) = NULL;
2633 void *modeHandle = NULL;
2634
2635 // Reading property set on boot finish in SF
2636 property_get("service.bootanim.exit", value, "0");
2637 boot_finished = atoi(value);
2638 if (!boot_finished)
2639 return;
2640
2641 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2642 if (modeHandle) {
2643 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2644 if (applyMode) {
2645 ret = applyMode(HWC_DISPLAY_PRIMARY);
2646 if (ret)
2647 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2648 } else {
2649 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2650 }
2651 dlclose(modeHandle);
2652 } else {
2653 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
2654 }
2655
2656 ctx->mBootAnimCompleted = true;
2657}
2658
Saurabh Shahcd018352014-11-11 13:54:19 -08002659void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2660 const private_handle_t *hnd,
2661 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002662 const int& transform,const int& downscale,
2663 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002664 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302665 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002666 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002667 return;
2668 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002669 //Disabled at runtime
2670 if(not ctx->mBWCEnabled) return;
2671 //BWC not supported with rot-downscale
2672 if(downscale) return;
2673 //Not enabled for secondary displays
2674 if(dpy) return;
2675 //Not enabled for non-video buffers
2676 if(not isYuvBuffer(hnd)) return;
2677
Saurabh Shahb6810df2014-06-17 16:00:22 -07002678 int src_w = crop.right - crop.left;
2679 int src_h = crop.bottom - crop.top;
2680 int dst_w = dst.right - dst.left;
2681 int dst_h = dst.bottom - dst.top;
2682 if(transform & HAL_TRANSFORM_ROT_90) {
2683 swap(src_w, src_h);
2684 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002685 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002686 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002687 return;
2688 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002689 //Decimation necessary, cannot use BWC. H/W requirement.
2690 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002691 uint8_t horzDeci = 0;
2692 uint8_t vertDeci = 0;
2693 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2694 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002695 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002696 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002697
2698 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2699}
2700
Saurabh Shah23a813c2013-03-20 16:58:12 -07002701void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302702 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002703 mLayer[mCount] = layer;
2704 mRot[mCount] = rot;
2705 mCount++;
2706}
2707
2708void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302709 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002710 mLayer[i] = 0;
2711 mRot[i] = 0;
2712 }
2713 mCount = 0;
2714}
2715
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002716void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002717 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002718 reset();
2719}
2720
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302721bool LayerRotMap::isRotCached(uint32_t index) const {
2722 overlay::Rotator* rot = getRot(index);
2723 hwc_layer_1_t* layer = getLayer(index);
2724
2725 if(rot and layer and layer->handle) {
2726 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2727 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2728 }
2729 return false;
2730}
2731
Saurabh Shah23a813c2013-03-20 16:58:12 -07002732void LayerRotMap::setReleaseFd(const int& fence) {
2733 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302734 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2735 /* Ensure that none of the above (Rotator-instance,
2736 * layer and layer-handle) are NULL*/
2737 if(isRotCached(i))
2738 mRot[i]->setPrevBufReleaseFd(dup(fence));
2739 else
2740 mRot[i]->setCurrBufReleaseFd(dup(fence));
2741 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002742 }
2743}
2744
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002745hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2746 int lRoiWidth = 0, rRoiWidth = 0;
2747 int half_frame_width = fullFrame.right/2;
2748
2749 hwc_rect lFrame = fullFrame;
2750 hwc_rect rFrame = fullFrame;
2751 lFrame.right = (lFrame.right - lFrame.left)/2;
2752 rFrame.left = lFrame.right;
2753
2754 hwc_rect lRoi = getIntersection(roi, lFrame);
2755 hwc_rect rRoi = getIntersection(roi, rFrame);
2756
2757 lRoiWidth = lRoi.right - lRoi.left;
2758 rRoiWidth = rRoi.right - rRoi.left;
2759
2760 if(lRoiWidth && rRoiWidth) {
2761 if(lRoiWidth < rRoiWidth)
2762 roi.left = half_frame_width - rRoiWidth;
2763 else
2764 roi.right = half_frame_width + lRoiWidth;
2765 }
2766 return roi;
2767}
2768
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002769void resetROI(hwc_context_t *ctx, const int dpy) {
2770 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2771 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
2772 if(isDisplaySplit(ctx, dpy)) {
2773 const int lSplit = getLeftSplit(ctx, dpy);
2774 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2775 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2776 } else {
2777 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2778 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2779 }
2780}
2781
2782hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002783{
2784 if(!isValidRect(roi))
2785 return roi;
2786
2787 struct hwc_rect t_roi = roi;
2788
2789 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2790 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2791 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2792 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2793 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002794 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002795
2796 /* Align to minimum width recommended by the panel */
2797 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2798 if((t_roi.left + MIN_WIDTH) > boundary.right)
2799 t_roi.left = t_roi.right - MIN_WIDTH;
2800 else
2801 t_roi.right = t_roi.left + MIN_WIDTH;
2802 }
2803
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002804 /* Align to minimum height recommended by the panel */
2805 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2806 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2807 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2808 else
2809 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2810 }
2811
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002812 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002813 if(LEFT_ALIGN)
2814 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2815
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002816 if(WIDTH_ALIGN) {
2817 int width = t_roi.right - t_roi.left;
2818 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2819 t_roi.right = t_roi.left + width;
2820
2821 if(t_roi.right > boundary.right) {
2822 t_roi.right = boundary.right;
2823 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002824
2825 if(LEFT_ALIGN)
2826 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002827 }
2828 }
2829
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002830
2831 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002832 if(TOP_ALIGN)
2833 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2834
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002835 if(HEIGHT_ALIGN) {
2836 int height = t_roi.bottom - t_roi.top;
2837 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2838 t_roi.bottom = t_roi.top + height;
2839
2840 if(t_roi.bottom > boundary.bottom) {
2841 t_roi.bottom = boundary.bottom;
2842 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002843
2844 if(TOP_ALIGN)
2845 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002846 }
2847 }
2848
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002849
2850 return t_roi;
2851}
2852
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002853void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002854 if(ctx->dpyAttr[dpy].connected) {
2855 ctx->mDrawLock.lock();
2856 ctx->dpyAttr[dpy].isActive = true;
2857 ctx->dpyAttr[dpy].isPause = true;
2858 ctx->mDrawLock.unlock();
2859 ctx->proc->invalidate(ctx->proc);
2860
2861 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2862 * 2 / 1000);
2863
2864 // At this point all the pipes used by External have been
2865 // marked as UNSET.
2866 ctx->mDrawLock.lock();
2867 // Perform commit to unstage the pipes.
2868 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2869 ALOGE("%s: display commit fail! for %d dpy",
2870 __FUNCTION__, dpy);
2871 }
2872 ctx->mDrawLock.unlock();
2873 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002874 }
2875 return;
2876}
2877
2878void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002879 if(ctx->dpyAttr[dpy].connected) {
2880 ctx->mDrawLock.lock();
2881 ctx->dpyAttr[dpy].isConfiguring = true;
2882 ctx->dpyAttr[dpy].isActive = true;
2883 ctx->mDrawLock.unlock();
2884 ctx->proc->invalidate(ctx->proc);
2885
2886 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2887 * 2 / 1000);
2888
2889 //At this point external has all the pipes it would need.
2890 ctx->mDrawLock.lock();
2891 ctx->dpyAttr[dpy].isPause = false;
2892 ctx->mDrawLock.unlock();
2893 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002894 }
2895 return;
2896}
2897
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002898void clearPipeResources(hwc_context_t* ctx, int dpy) {
2899 if(ctx->mOverlay) {
2900 ctx->mOverlay->configBegin();
2901 ctx->mOverlay->configDone();
2902 }
2903 if(ctx->mRotMgr) {
2904 ctx->mRotMgr->clear();
2905 }
2906 // Call a display commit to ensure that pipes and associated
2907 // fd's are cleaned up.
2908 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2909 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2910 }
2911}
2912
2913// Handles online events when HDMI is the primary display. In particular,
2914// online events for hdmi connected before AND after boot up and HWC init.
2915void handle_online(hwc_context_t* ctx, int dpy) {
2916 // Close the current fd if it was opened earlier on when HWC
2917 // was initialized.
2918 if (ctx->dpyAttr[dpy].fd >= 0) {
2919 close(ctx->dpyAttr[dpy].fd);
2920 ctx->dpyAttr[dpy].fd = -1;
2921 }
2922 // TODO: If HDMI is connected after the display has booted up,
2923 // and the best configuration is different from the default
2924 // then we need to deal with this appropriately.
2925 ctx->mHDMIDisplay->configure();
2926 updateDisplayInfo(ctx, dpy);
2927 initCompositionResources(ctx, dpy);
2928 ctx->dpyAttr[dpy].connected = true;
2929}
2930
2931// Handles offline events for HDMI. This can be used for offline events
2932// initiated by the HDMI driver and the CEC framework.
2933void handle_offline(hwc_context_t* ctx, int dpy) {
2934 destroyCompositionResources(ctx, dpy);
2935 // Clear all pipe resources and call a display commit to ensure
2936 // that all the fd's are closed. This will ensure that the HDMI
2937 // core turns off and that we receive an event the next time the
2938 // cable is connected.
2939 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
2940 clearPipeResources(ctx, dpy);
2941 }
2942 ctx->mHDMIDisplay->teardown();
2943 resetDisplayInfo(ctx, dpy);
2944 ctx->dpyAttr[dpy].connected = false;
2945 ctx->dpyAttr[dpy].isActive = false;
2946}
2947
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002948int convertS3DFormatToMode(int s3DFormat) {
2949 int ret;
2950 switch(s3DFormat) {
2951 case HAL_3D_SIDE_BY_SIDE_L_R:
2952 case HAL_3D_SIDE_BY_SIDE_R_L:
2953 ret = HDMI_S3D_SIDE_BY_SIDE;
2954 break;
2955 case HAL_3D_TOP_BOTTOM:
2956 ret = HDMI_S3D_TOP_AND_BOTTOM;
2957 break;
2958 default:
2959 ret = HDMI_S3D_NONE;
2960 }
2961 return ret;
2962}
2963
2964bool needs3DComposition(hwc_context_t* ctx, int dpy) {
2965 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
2966 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
2967}
2968
2969void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
2970 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
2971 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
2972 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
2973 ctx->dpyAttr[dpy].s3dMode = s3dMode;
2974 }
2975 }
2976}
2977
2978bool displaySupports3D(hwc_context_t* ctx, int dpy) {
2979 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
2980 ((dpy == HWC_DISPLAY_PRIMARY) &&
2981 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
2982}
2983
2984
Saurabh Shahacf10202013-02-26 10:15:15 -08002985};//namespace qhwc