blob: 043d7c243a51489bc17da2f89ba874c7e7ad77ef [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Zohaib Alamc9d00cd2014-01-24 16:38:32 -05003 * Copyright (C) 2012-2014, The Linux Foundation All rights reserved.
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
Naseer Ahmed099a6932013-09-09 14:25:20 -040020#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080021#define HWC_UTILS_DEBUG 0
Saurabh Shahc5b96dc2013-06-05 13:19:52 -070022#include <math.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include <sys/ioctl.h>
Naseer Ahmed66e97882013-03-19 20:42:11 -040024#include <linux/fb.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080025#include <binder/IServiceManager.h>
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070026#include <EGL/egl.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070027#include <cutils/properties.h>
Naseer Ahmed099a6932013-09-09 14:25:20 -040028#include <utils/Trace.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070029#include <gralloc_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080031#include <overlayRotator.h>
Saurabh Shaha9da08f2013-07-03 13:27:53 -070032#include <overlayWriteback.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070033#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050034#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080035#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070036#include "hwc_ad.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070037#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "hwc_copybit.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070039#include "hwc_dump_layers.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070040#include "hdmi.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080041#include "hwc_qclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070042#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080043#include "comptype.h"
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -080044#include "hwc_virtual.h"
Tatenda Chipeperekwaa7dd23c2014-03-05 13:02:24 -080045#include "qd_utils.h"
Ramakant Singh98c533c2014-09-30 19:01:54 +053046#include <sys/sysinfo.h>
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +053047#include <dlfcn.h>
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050048#include <video/msm_hdmi_modes.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080049
50using namespace qClient;
51using namespace qService;
52using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080053using namespace overlay;
54using namespace overlay::utils;
55namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080056
Saurabh Shah74eff4d2014-03-28 16:33:13 -070057#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070058#ifdef __cplusplus
59extern "C" {
60#endif
61
62EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
63 EGLint *attrib_list);
64#define EGL_GPU_HINT_1 0x32D0
65#define EGL_GPU_HINT_2 0x32D1
66
67#define EGL_GPU_LEVEL_0 0x0
68#define EGL_GPU_LEVEL_1 0x1
69#define EGL_GPU_LEVEL_2 0x2
70#define EGL_GPU_LEVEL_3 0x3
71#define EGL_GPU_LEVEL_4 0x4
72#define EGL_GPU_LEVEL_5 0x5
73
74#ifdef __cplusplus
75}
76#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070077#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070078
Ramakant Singhbe390c72014-12-03 23:04:21 +053079#define PROP_DEFAULT_APPBUFFER "hw.sf.app_buff_count"
Ramakant Singh98c533c2014-09-30 19:01:54 +053080#define MAX_RAM_SIZE 512*1024*1024
81#define qHD_WIDTH 540
82
83
Naseer Ahmed29a26812012-06-14 00:56:20 -070084namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070085
Arun Kumar K.R053dc502014-11-13 11:13:43 -080086// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
87uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070088
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
Saurabh Shah90c55cf2015-02-10 15:37:39 -080096static void handleFbScaling(hwc_context_t *ctx, int xresPanel, int yresPanel,
97 int width, int height) {
98 const int dpy = HWC_DISPLAY_PRIMARY;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053099 //Store original display resolution.
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800100 ctx->dpyAttr[dpy].xresFB = xresPanel;
101 ctx->dpyAttr[dpy].yresFB = yresPanel;
102 ctx->dpyAttr[dpy].fbScaling = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530103 char property[PROPERTY_VALUE_MAX] = {'\0'};
104 char *yptr = NULL;
105 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
106 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530107 if(yptr) {
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800108 int xresFB = atoi(property);
109 int yresFB = atoi(yptr + 1);
110 if (isValidResolution(ctx, xresFB, yresFB) &&
111 xresFB != xresPanel && yresFB != yresPanel) {
112 ctx->dpyAttr[dpy].xresFB = xresFB;
113 ctx->dpyAttr[dpy].yresFB = yresFB;
114 ctx->dpyAttr[dpy].fbScaling = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530115
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800116 //Calculate DPI according to changed resolution.
117 float xdpi = ((float)xresFB * 25.4f) / (float)width;
118 float ydpi = ((float)yresFB * 25.4f) / (float)height;
119 ctx->dpyAttr[dpy].xdpi = xdpi;
120 ctx->dpyAttr[dpy].ydpi = ydpi;
Raj Kamal4a443082014-10-12 21:07:59 +0530121 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530122 }
123 }
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800124 ctx->dpyAttr[dpy].fbWidthScaleRatio = (float) ctx->dpyAttr[dpy].xres /
125 (float) ctx->dpyAttr[dpy].xresFB;
126 ctx->dpyAttr[dpy].fbHeightScaleRatio = (float) ctx->dpyAttr[dpy].yres /
127 (float) ctx->dpyAttr[dpy].yresFB;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530128}
129
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700130// Initialize hdmi display attributes based on
131// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700132void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700133 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
134 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
135 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
136 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
137 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700138 //FIXME: for now assume HDMI as secure
139 //Will need to read the HDCP status from the driver
140 //and update this accordingly
141 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700142 ctx->mViewFrame[dpy].left = 0;
143 ctx->mViewFrame[dpy].top = 0;
144 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
145 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
146}
147
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700148// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700149void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
150 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
151 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
152 // We reset the fd to -1 here but External display class is responsible
153 // for it when the display is disconnected. This is handled as part of
154 // EXTERNAL_OFFLINE event.
155 ctx->dpyAttr[dpy].fd = -1;
156}
157
158// Initialize composition resources
159void initCompositionResources(hwc_context_t* ctx, int dpy) {
160 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
161 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
162}
163
164void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
165 if(ctx->mFBUpdate[dpy]) {
166 delete ctx->mFBUpdate[dpy];
167 ctx->mFBUpdate[dpy] = NULL;
168 }
169 if(ctx->mMDPComp[dpy]) {
170 delete ctx->mMDPComp[dpy];
171 ctx->mMDPComp[dpy] = NULL;
172 }
173}
174
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800175static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700176{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800177 struct fb_fix_screeninfo finfo;
178 struct fb_var_screeninfo info;
179
180 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530181 if(fb_fd < 0) {
182 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800183 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530184 }
185
186 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
187 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
188 strerror(errno));
189 close(fb_fd);
190 return -errno;
191 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800192
193 if (int(info.width) <= 0 || int(info.height) <= 0) {
194 // the driver doesn't return that information
195 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530196 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
197 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700198 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800199
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530200 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
201 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800202
203#ifdef MSMFB_METADATA_GET
204 struct msmfb_metadata metadata;
205 memset(&metadata, 0 , sizeof(metadata));
206 metadata.op = metadata_op_frame_rate;
207
208 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530209 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
210 strerror(errno));
211 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800212 return -errno;
213 }
214
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530215 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800216#else
217 //XXX: Remove reserved field usage on all baselines
218 //The reserved[3] field is used to store FPS by the driver.
219 float fps = info.reserved[3] & 0xFF;
220#endif
221
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530222 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
223 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
224 strerror(errno));
225 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800226 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530227 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800228
229 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
230 //xres, yres may not be 32 aligned
231 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
232 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
233 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
234 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
235 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700236 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
237 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700238 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530239 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
240 (uint32_t)(1000000000l / fps);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800241
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800242 handleFbScaling(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530243
Naseer Ahmed22616d92013-05-15 17:20:26 -0400244 //Unblank primary on first boot
245 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
246 ALOGE("%s: Failed to unblank display", __FUNCTION__);
247 return -errno;
248 }
249 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
250
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800251 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700252}
253
Ramakant Singh98c533c2014-09-30 19:01:54 +0530254static void changeDefaultAppBufferCount() {
255 struct sysinfo info;
256 unsigned long int ramSize = 0;
257 if (!sysinfo(&info)) {
258 ramSize = info.totalram ;
259 }
260 int fb_fd = -1;
261 struct fb_var_screeninfo sInfo ={0};
262 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
263 if (fb_fd >=0) {
264 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
265 close(fb_fd);
266 }
267 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
268 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
269 property_set(PROP_DEFAULT_APPBUFFER, "2");
270 }
271}
272
Naseer Ahmed29a26812012-06-14 00:56:20 -0700273void initContext(hwc_context_t *ctx)
274{
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700275 overlay::Overlay::initOverlay();
276 ctx->mHDMIDisplay = new HDMIDisplay();
277 uint32_t priW = 0, priH = 0;
278 // 1. HDMI as Primary
279 // -If HDMI cable is connected, read display configs from edid data
280 // -If HDMI cable is not connected then use default data in vscreeninfo
281 // 2. HDMI as External
282 // -Initialize HDMI class for use with external display
283 // -Use vscreeninfo to populate display configs
284 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
285 int connected = ctx->mHDMIDisplay->getConnectedState();
286 if(connected == 1) {
287 ctx->mHDMIDisplay->configure();
288 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
289 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
290 } else {
291 openFramebufferDevice(ctx);
292 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
293 }
294 } else {
295 openFramebufferDevice(ctx);
296 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
297 // Send the primary resolution to the hdmi display class
298 // to be used for MDP scaling functionality
299 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
300 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
301 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
302 }
303
Raj kamal59fea562014-04-01 16:52:19 +0530304 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700305 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
306 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
307 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800308 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800309 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800310 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800311
Ramakant Singh98c533c2014-09-30 19:01:54 +0530312 //default_app_buffer for ferrum
313 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
314 changeDefaultAppBufferCount();
315 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700316 // Initialize composition objects for the primary display
317 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800318
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800319 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800320 // decide if we need to open the copybit module.
321 int compositionType =
322 qdutils::QCCompositionType::getInstance().getCompositionType();
323
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800324 // Only MDP copybit is used
325 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
326 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530327 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
328 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800329 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530330 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800331 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
332 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800333 }
334
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700335 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700336 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
337 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
338 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
339 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700340 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
341 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
342 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800343
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700344 //Initialize the primary display viewFrame info
345 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
346 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
347 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
348 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
349 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
350 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530351
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700352 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700353 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700354 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700355 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800356 ctx->dpyAttr[i].mActionSafePresent = false;
357 ctx->dpyAttr[i].mAsWidthRatio = 0;
358 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500359 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
360 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700361 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700362
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500363 //Make sure that the 3D mode is unset at bootup
364 //This makes sure that the state is accurate on framework reboots
365 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
366
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530367 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
368 ctx->mPrevHwLayerCount[i] = 0;
369 }
370
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500371 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700372 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700373
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400374 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500375 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700376 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530377 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800378
379 //Right now hwc starts the service but anybody could do it, or it could be
380 //independent process as well.
381 QService::init();
382 sp<IQClient> client = new QClient(ctx);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400383 sp<IQService> iqs = interface_cast<IQService>(
Saurabh Shah86c17292013-02-08 15:24:13 -0800384 defaultServiceManager()->getService(
Charles Bindab39382014-06-30 10:34:30 -0700385 String16("display.qservice")));
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400386 if (iqs.get()) {
387 iqs->connect(client);
388 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
Charles Bindab39382014-06-30 10:34:30 -0700389 } else {
390 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400391 return;
Charles Bindab39382014-06-30 10:34:30 -0700392 }
Saurabh Shah86c17292013-02-08 15:24:13 -0800393
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700394 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700395 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700396 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400397
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700398 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
399 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
400
Ramakant Singh0def28c2014-03-28 20:43:13 +0530401 ctx->enableABC = false;
402 property_get("debug.sf.hwc.canUseABC", value, "0");
403 ctx->enableABC = atoi(value) ? true : false;
404
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530405 // Initializing boot anim completed check to false
406 ctx->mBootAnimCompleted = false;
407
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700408 // Initialize gpu perfomance hint related parameters
409 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700410#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700411 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
412
413 ctx->mGPUHintInfo.mEGLDisplay = NULL;
414 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700415 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700416 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700417#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700418 // Read the system property to determine if windowboxing feature is enabled.
419 ctx->mWindowboxFeature = false;
420 if(property_get("sys.hwc.windowbox_feature", value, "false")
421 && !strcmp(value, "true")) {
422 ctx->mWindowboxFeature = true;
423 }
424
Raj Kamal0d53fc62014-11-25 17:36:36 +0530425 ctx->mUseMetaDataRefreshRate = true;
426 if(property_get("persist.metadata_dynfps.disable", value, "false")
427 && !strcmp(value, "true")) {
428 ctx->mUseMetaDataRefreshRate = false;
429 }
430
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700431 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800432 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700433 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700434 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700435}
436
437void closeContext(hwc_context_t *ctx)
438{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500439 if(ctx->mOverlay) {
440 delete ctx->mOverlay;
441 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700442 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700443
Saurabh Shahacf10202013-02-26 10:15:15 -0800444 if(ctx->mRotMgr) {
445 delete ctx->mRotMgr;
446 ctx->mRotMgr = NULL;
447 }
448
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700449 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800450 if(ctx->mCopyBit[i]) {
451 delete ctx->mCopyBit[i];
452 ctx->mCopyBit[i] = NULL;
453 }
454 }
455
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800456 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700457 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
458 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700459 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700460
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700461 if(ctx->mHDMIDisplay) {
462 delete ctx->mHDMIDisplay;
463 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700464 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400465
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700466 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700467 destroyCompositionResources(ctx, i);
468
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700469 if(ctx->mHwcDebug[i]) {
470 delete ctx->mHwcDebug[i];
471 ctx->mHwcDebug[i] = NULL;
472 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700473 if(ctx->mLayerRotMap[i]) {
474 delete ctx->mLayerRotMap[i];
475 ctx->mLayerRotMap[i] = NULL;
476 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800477 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800478 if(ctx->mHWCVirtual) {
479 delete ctx->mHWCVirtual;
480 ctx->mHWCVirtual = NULL;
481 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700482 if(ctx->mAD) {
483 delete ctx->mAD;
484 ctx->mAD = NULL;
485 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800486
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400487 if(ctx->mQService) {
488 delete ctx->mQService;
489 ctx->mQService = NULL;
490 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700491}
492
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700493//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530494uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700495 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
496 uint32_t rate = refreshRate;
497 for(int i=0; i< count; i++) {
498 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
499 // Most likely used for video, the fps can fluctuate
500 // Ex: b/w 29 and 30 for 30 fps clip
501 rate = stdRefreshRates[i];
502 break;
503 }
504 }
505 return rate;
506}
507
508//Helper func to set the dyn fps
509void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
510 //Update only if different
511 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
512 return;
513 const int fbNum = Overlay::getFbForDpy(dpy);
514 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
515 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800516 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700517
518 int fd = open(sysfsPath, O_WRONLY);
519 if(fd >= 0) {
520 char str[64];
521 snprintf(str, sizeof(str), "%d", refreshRate);
522 ssize_t ret = write(fd, str, strlen(str));
523 if(ret < 0) {
524 ALOGE("%s: Failed to write %d with error %s",
525 __FUNCTION__, refreshRate, strerror(errno));
526 } else {
527 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
528 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
529 __FUNCTION__, refreshRate);
530 }
531 close(fd);
532 } else {
533 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
534 strerror(errno));
535 }
536}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500537
538void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700539{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500540 va_list varargs;
541 va_start(varargs, fmt);
542 buf.appendFormatV(fmt, varargs);
543 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700544}
545
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700546int getExtOrientation(hwc_context_t* ctx) {
547 int extOrient = ctx->mExtOrientation;
548 if(ctx->mBufferMirrorMode)
549 extOrient = getMirrorModeOrientation(ctx);
550 return extOrient;
551}
552
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800553/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700554void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
555 // Position
556 int x = rect.left, y = rect.top;
557 int w = rect.right - rect.left;
558 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800559
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800560 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800561 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800562 // Read action safe properties
563 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
564 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700565
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800566 float wRatio = 1.0;
567 float hRatio = 1.0;
568 float xRatio = 1.0;
569 float yRatio = 1.0;
570
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700571 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
572 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700573 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
574 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700575 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700576 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700577 }
578
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800579
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700580 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700581 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700582
583 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700584 swap(fbWidth, fbHeight);
585
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800586 float asX = 0;
587 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530588 float asW = (float)fbWidth;
589 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800590
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800591 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530592 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
593 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
594 asX = ((float)fbWidth - asW) / 2;
595 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800596
597 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530598 xRatio = (float)x/(float)fbWidth;
599 yRatio = (float)y/(float)fbHeight;
600 wRatio = (float)w/(float)fbWidth;
601 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800602
603 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530604 x = int((xRatio * asW) + asX);
605 y = int((yRatio * asH) + asY);
606 w = int(wRatio * asW);
607 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800608
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700609 // Convert it back to hwc_rect_t
610 rect.left = x;
611 rect.top = y;
612 rect.right = w + rect.left;
613 rect.bottom = h + rect.top;
614
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800615 return;
616}
617
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700618// This function gets the destination position for Seconday display
619// based on the position and aspect ratio with orientation
620void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
621 hwc_rect_t& inRect, hwc_rect_t& outRect) {
622 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530623 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
624 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700625 //display position(x,y,w,h) in correct aspectratio after rotation
626 int xPos = 0;
627 int yPos = 0;
628 float width = fbWidth;
629 float height = fbHeight;
630 // Width/Height used for calculation, after rotation
631 float actualWidth = fbWidth;
632 float actualHeight = fbHeight;
633
634 float wRatio = 1.0;
635 float hRatio = 1.0;
636 float xRatio = 1.0;
637 float yRatio = 1.0;
638 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
639
640 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
641 inRect.bottom - inRect.top);
642 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
643 outRect.bottom - outRect.top);
644
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530645 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700646 eTransform extorient = static_cast<eTransform>(extOrientation);
647 // To calculate the destination co-ordinates in the new orientation
648 preRotateSource(extorient, whf, inPos);
649
650 if(extOrientation & HAL_TRANSFORM_ROT_90) {
651 // Swap width/height for input position
652 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700653 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
654 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700655 xPos = rect.left;
656 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530657 width = float(rect.right - rect.left);
658 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700659 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700660 xRatio = (float)((float)inPos.x/actualWidth);
661 yRatio = (float)((float)inPos.y/actualHeight);
662 wRatio = (float)((float)inPos.w/actualWidth);
663 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800664
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530665 //Calculate the pos9ition...
666 outPos.x = uint32_t((xRatio * width) + (float)xPos);
667 outPos.y = uint32_t((yRatio * height) + (float)yPos);
668 outPos.w = uint32_t(wRatio * width);
669 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700670 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
671 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
672 outPos.w, outPos.h);
673
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700674 // For sidesync, the dest fb will be in portrait orientation, and the crop
675 // will be updated to avoid the black side bands, and it will be upscaled
676 // to fit the dest RB, so recalculate
677 // the position based on the new width and height
678 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
679 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800680 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700681 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530682 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700683 // GetaspectRatio -- tricky to get the correct aspect ratio
684 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700685 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530686 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700687 xPos = r.left;
688 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530689 float tempHeight = float(r.bottom - r.top);
690 yRatio = (float)yPos/height;
691 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700692 hRatio = tempHeight/height;
693
694 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530695 outPos.x = uint32_t(xRatio * fbWidth);
696 outPos.y = uint32_t(yRatio * fbHeight);
697 outPos.w = uint32_t(wRatio * fbWidth);
698 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700699
700 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
701 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
702 outPos.x, outPos.y,
703 outPos.w, outPos.h);
704 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700705 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700706 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700707 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700708 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700709 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
710 extW = ctx->mHWCVirtual->getScalingWidth();
711 extH = ctx->mHWCVirtual->getScalingHeight();
712 }
713 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
714 __FUNCTION__, extW, extH);
715
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530716 fbWidth = (float)ctx->dpyAttr[dpy].xres;
717 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700718 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530719 xRatio = (float)outPos.x/fbWidth;
720 yRatio = (float)outPos.y/fbHeight;
721 wRatio = (float)outPos.w/fbWidth;
722 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700723
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530724 outPos.x = uint32_t(xRatio * (float)extW);
725 outPos.y = uint32_t(yRatio * (float)extH);
726 outPos.w = uint32_t(wRatio * (float)extW);
727 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700728 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700729 // Convert Dim to hwc_rect_t
730 outRect.left = outPos.x;
731 outRect.top = outPos.y;
732 outRect.right = outPos.x + outPos.w;
733 outRect.bottom = outPos.y + outPos.h;
734
735 return;
736}
737
738bool isPrimaryPortrait(hwc_context_t *ctx) {
739 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
740 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
741 if(fbWidth < fbHeight) {
742 return true;
743 }
744 return false;
745}
746
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700747bool isOrientationPortrait(hwc_context_t *ctx) {
748 if(isPrimaryPortrait(ctx)) {
749 return !(ctx->deviceOrientation & 0x1);
750 }
751 return (ctx->deviceOrientation & 0x1);
752}
753
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700754void calcExtDisplayPosition(hwc_context_t *ctx,
755 private_handle_t *hnd,
756 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700757 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700758 hwc_rect_t& displayFrame,
759 int& transform,
760 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700761 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700762 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530763 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700764 if(!isYuvBuffer(hnd)) {
765 if(extOrient & HWC_TRANSFORM_ROT_90) {
766 int dstWidth = ctx->dpyAttr[dpy].xres;
767 int dstHeight = ctx->dpyAttr[dpy].yres;;
768 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
769 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
770 if(!isPrimaryPortrait(ctx)) {
771 swap(srcWidth, srcHeight);
772 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700773 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700774 srcHeight, displayFrame);
775 // Crop - this is needed, because for sidesync, the dest fb will
776 // be in portrait orientation, so update the crop to not show the
777 // black side bands.
778 if (isOrientationPortrait(ctx)) {
779 sourceCrop = displayFrame;
780 displayFrame.left = 0;
781 displayFrame.top = 0;
782 displayFrame.right = dstWidth;
783 displayFrame.bottom = dstHeight;
784 }
785 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700786 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700787 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700788 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700789 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530790 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
791 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700792 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700793 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700794 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700795 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
796 extW = ctx->mHWCVirtual->getScalingWidth();
797 extH = ctx->mHWCVirtual->getScalingHeight();
798 }
799 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
800 __FUNCTION__, extW, extH);
801
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700802 //Calculate the ratio...
803 float wRatio = ((float)extW)/fbWidth;
804 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700805
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700806 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530807 displayFrame.left = int(wRatio*(float)displayFrame.left);
808 displayFrame.top = int(hRatio*(float)displayFrame.top);
809 displayFrame.right = int(wRatio*(float)displayFrame.right);
810 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700811 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
812 " for MDPDownscale feature [%d %d %d %d]",
813 displayFrame.left, displayFrame.top,
814 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700815 }
816 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700817 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700818 getAspectRatioPosition(ctx, dpy, extOrient,
819 displayFrame, displayFrame);
820 }
821 }
822 // If there is a external orientation set, use that
823 if(extOrient) {
824 transform = extOrient;
825 orient = static_cast<ovutils::eTransform >(extOrient);
826 }
827 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
828 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700829 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700830}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700831
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700832/* Returns the orientation which needs to be set on External for
833 * SideSync/Buffer Mirrormode
834 */
835int getMirrorModeOrientation(hwc_context_t *ctx) {
836 int extOrientation = 0;
837 int deviceOrientation = ctx->deviceOrientation;
838 if(!isPrimaryPortrait(ctx))
839 deviceOrientation = (deviceOrientation + 1) % 4;
840 if (deviceOrientation == 0)
841 extOrientation = HWC_TRANSFORM_ROT_270;
842 else if (deviceOrientation == 1)//90
843 extOrientation = 0;
844 else if (deviceOrientation == 2)//180
845 extOrientation = HWC_TRANSFORM_ROT_90;
846 else if (deviceOrientation == 3)//270
847 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
848
849 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700850}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700851
Raj kamal59fea562014-04-01 16:52:19 +0530852/* Get External State names */
853const char* getExternalDisplayState(uint32_t external_state) {
854 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
855 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
856 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
857 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
858 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
859
860 if(external_state >= EXTERNAL_MAXSTATES) {
861 return "EXTERNAL_INVALID";
862 }
863
864 return externalStates[external_state];
865}
866
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530867bool isDownscaleRequired(hwc_layer_1_t const* layer) {
868 hwc_rect_t displayFrame = layer->displayFrame;
869 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
870 int dst_w, dst_h, src_w, src_h;
871 dst_w = displayFrame.right - displayFrame.left;
872 dst_h = displayFrame.bottom - displayFrame.top;
873 src_w = sourceCrop.right - sourceCrop.left;
874 src_h = sourceCrop.bottom - sourceCrop.top;
875
876 if(((src_w > dst_w) || (src_h > dst_h)))
877 return true;
878
879 return false;
880}
881bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500882 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500883 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700884 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500885
886 dst_w = displayFrame.right - displayFrame.left;
887 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500888 src_w = sourceCrop.right - sourceCrop.left;
889 src_h = sourceCrop.bottom - sourceCrop.top;
890
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800891 if(layer->transform & HWC_TRANSFORM_ROT_90)
892 swap(src_w, src_h);
893
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800894 if(((src_w != dst_w) || (src_h != dst_h)))
895 return true;
896
897 return false;
898}
899
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700900// Checks if layer needs scaling with split
901bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
902 const int& dpy) {
903
904 int src_width_l, src_height_l;
905 int src_width_r, src_height_r;
906 int dst_width_l, dst_height_l;
907 int dst_width_r, dst_height_r;
908 int hw_w = ctx->dpyAttr[dpy].xres;
909 int hw_h = ctx->dpyAttr[dpy].yres;
910 hwc_rect_t cropL, dstL, cropR, dstR;
911 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700912 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700913 hwc_rect_t displayFrame = layer->displayFrame;
914 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700915
916 cropL = sourceCrop;
917 dstL = displayFrame;
918 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800919 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700920 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
921
922 cropR = sourceCrop;
923 dstR = displayFrame;
924 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800925 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700926 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
927
928 // Sanitize Crop to stitch
929 sanitizeSourceCrop(cropL, cropR, hnd);
930
931 // Calculate the left dst
932 dst_width_l = dstL.right - dstL.left;
933 dst_height_l = dstL.bottom - dstL.top;
934 src_width_l = cropL.right - cropL.left;
935 src_height_l = cropL.bottom - cropL.top;
936
937 // check if there is any scaling on the left
938 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
939 return true;
940
941 // Calculate the right dst
942 dst_width_r = dstR.right - dstR.left;
943 dst_height_r = dstR.bottom - dstR.top;
944 src_width_r = cropR.right - cropR.left;
945 src_height_r = cropR.bottom - cropR.top;
946
947 // check if there is any scaling on the right
948 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
949 return true;
950
951 return false;
952}
953
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530954bool isAlphaScaled(hwc_layer_1_t const* layer) {
955 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530956 return true;
957 }
958 return false;
959}
960
961bool isAlphaPresent(hwc_layer_1_t const* layer) {
962 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400963 if(hnd) {
964 int format = hnd->format;
965 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530966 case HAL_PIXEL_FORMAT_RGBA_8888:
967 case HAL_PIXEL_FORMAT_BGRA_8888:
968 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500969 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530970 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400971 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500972 }
973 return false;
974}
975
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700976static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
977 hwc_rect_t& crop, hwc_rect_t& dst) {
978 int hw_w = ctx->dpyAttr[dpy].xres;
979 int hw_h = ctx->dpyAttr[dpy].yres;
980 if(dst.left < 0 || dst.top < 0 ||
981 dst.right > hw_w || dst.bottom > hw_h) {
982 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800983 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700984 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
985 }
986}
987
988static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
989 const int& dpy) {
990 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
991 hwc_layer_1_t *layer = &list->hwLayers[i];
992 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700993 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
994 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700995 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700996 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700997 (hwc_rect_t&)crop,
998 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530999 layer->sourceCropf.left = (float)crop.left;
1000 layer->sourceCropf.right = (float)crop.right;
1001 layer->sourceCropf.top = (float)crop.top;
1002 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001003 }
1004}
1005
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001006void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001007 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001008 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1009 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301010 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1011 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001012 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301013 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001014 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001015 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001016 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001017 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001018 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301019 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001020 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301021 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001022 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001023 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1024 uint32_t refreshRate = 0;
1025 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001026 int s3dFormat = HAL_NO_3D;
1027 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001028
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001029 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001030 resetROI(ctx, dpy);
1031
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001032 trimList(ctx, list, dpy);
1033 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001034 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001035 hwc_layer_1_t const* layer = &list->hwLayers[i];
1036 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001037
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001038#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001039 // Window boxing feature is applicable obly for external display, So
1040 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001041 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001042 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001043 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001044 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1045 ctx->listStats[dpy].isDisplayAnimating = true;
1046 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001047 if(isSecureDisplayBuffer(hnd)) {
1048 ctx->listStats[dpy].secureUI = true;
1049 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001050#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001051 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1052 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001053 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001054
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001055 //reset yuv indices
1056 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301057 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001058
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001059 if (isSecureBuffer(hnd)) {
1060 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001061 if(not isYuvBuffer(hnd)) {
1062 // cache secureRGB layer parameters like we cache for YUV layers
1063 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1064 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1065 secureRGBCount++;
1066 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001067 }
1068
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001069 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001070 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001071 }
1072
1073 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001074 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301075 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001076 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001077
Raj Kamal389d6e32014-08-04 14:43:24 +05301078 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301079 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301080 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301081 yuv4k2kCount++;
1082 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001083
1084 // Gets set if one YUV layer is 3D
1085 if (displaySupports3D(ctx,dpy)) {
1086 s3dFormat = get3DFormat(hnd);
1087 if(s3dFormat != HAL_NO_3D)
1088 s3dLayerCount++;
1089 }
1090
Naseer Ahmed29a26812012-06-14 00:56:20 -07001091 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301092 if(layer->blending == HWC_BLENDING_PREMULT)
1093 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001094
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001095#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301096 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001097 //dyn fps: get refreshrate from metadata
1098 //Support multiple refresh rates if they are same
1099 //else set to default
1100 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1101 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1102 // Valid refreshRate in metadata and within the range
1103 uint32_t rate = roundOff(mdata->refreshrate);
1104 if((rate >= mdpHw.getMinFpsSupported() &&
1105 rate <= mdpHw.getMaxFpsSupported())) {
1106 if (!refreshRate) {
1107 refreshRate = rate;
1108 } else if(refreshRate != rate) {
1109 // multiple refreshrate requests, set to default
1110 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1111 }
1112 }
1113 }
1114 }
1115#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001116 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001117
1118 //Set the TV's 3D mode based on format if it was not forced
1119 //Only one 3D YUV layer is supported on external
1120 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1121 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1122 //XXX: Rapidly going in and out of 3D mode in some cases such
1123 // as rotation might cause flickers. The OEMs are recommended to disable
1124 // rotation on HDMI globally or in the app that plays 3D video
1125 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1126 }
1127
Ping Li9404e2a2013-04-24 16:36:03 -04001128 if(ctx->listStats[dpy].yuvCount > 0) {
1129 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1130 if (atoi(property) != 1) {
1131 property_set("hw.cabl.yuv", "1");
1132 }
1133 }
1134 } else {
1135 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1136 if (atoi(property) != 0) {
1137 property_set("hw.cabl.yuv", "0");
1138 }
1139 }
1140 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001141
1142 //The marking of video begin/end is useful on some targets where we need
1143 //to have a padding round to be able to shift pipes across mixers.
1144 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1145 ctx->mVideoTransFlag = true;
1146 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301147
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001148 if(dpy == HWC_DISPLAY_PRIMARY) {
1149 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001150 //Store the requested fresh rate
1151 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1152 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001153 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001154}
1155
Naseer Ahmed018e5452012-12-03 14:46:15 -05001156
Saurabh Shah68107422013-07-09 11:12:42 -07001157static void calc_cut(double& leftCutRatio, double& topCutRatio,
1158 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001159 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001160 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001161 }
1162 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001163 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001164 }
1165 if(orient & HAL_TRANSFORM_ROT_90) {
1166 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001167 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001168 leftCutRatio = topCutRatio;
1169 topCutRatio = rightCutRatio;
1170 rightCutRatio = bottomCutRatio;
1171 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001172 }
1173}
1174
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001175bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001176 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1177 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1178 ctx->mSecuring) {
1179 return true;
1180 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001181 if (isSecureModePolicy(ctx->mMDP.version)) {
1182 private_handle_t *hnd = (private_handle_t *)layer->handle;
1183 if(ctx->mSecureMode) {
1184 if (! isSecureBuffer(hnd)) {
1185 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1186 __FUNCTION__);
1187 return true;
1188 }
1189 } else {
1190 if (isSecureBuffer(hnd)) {
1191 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1192 __FUNCTION__);
1193 return true;
1194 }
1195 }
1196 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001197 return false;
1198}
1199
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001200bool isSecureModePolicy(int mdpVersion) {
1201 if (mdpVersion < qdutils::MDSS_V5)
1202 return true;
1203 else
1204 return false;
1205}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001206
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001207bool isRotatorSupportedFormat(private_handle_t *hnd) {
1208 // Following rotator src formats are supported by mdp driver
1209 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001210 if(hnd != NULL) {
1211 switch(hnd->format) {
1212 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001213 case HAL_PIXEL_FORMAT_RGBA_5551:
1214 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001215 case HAL_PIXEL_FORMAT_RGB_565:
1216 case HAL_PIXEL_FORMAT_RGB_888:
1217 case HAL_PIXEL_FORMAT_BGRA_8888:
1218 return true;
1219 default:
1220 return false;
1221 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001222 }
1223 return false;
1224}
1225
1226bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001227 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001228 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001229 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001230 !ctx->mMDP.version < qdutils::MDSS_V5)
1231 || isYuvBuffer(hnd)) {
1232 return true;
1233 }
1234 return false;
1235}
1236
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001237// returns true if Action safe dimensions are set and target supports Actionsafe
1238bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1239 // if external supports underscan, do nothing
1240 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001241 // Disable Action safe for 8974 due to HW limitation for downscaling
1242 // layers with overlapped region
1243 // Disable Actionsafe for non HDMI displays.
1244 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1245 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001246 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001247 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001248 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001249
1250 char value[PROPERTY_VALUE_MAX];
1251 // Read action safe properties
1252 property_get("persist.sys.actionsafe.width", value, "0");
1253 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1254 property_get("persist.sys.actionsafe.height", value, "0");
1255 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1256
1257 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1258 //No action safe ratio set, return
1259 return false;
1260 }
1261 return true;
1262}
1263
Naseer Ahmed522ce662013-03-18 20:14:05 -04001264int getBlending(int blending) {
1265 switch(blending) {
1266 case HWC_BLENDING_NONE:
1267 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1268 case HWC_BLENDING_PREMULT:
1269 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1270 case HWC_BLENDING_COVERAGE :
1271 default:
1272 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1273 }
1274}
1275
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001276//Crops source buffer against destination and FB boundaries
1277void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001278 const hwc_rect_t& scissor, int orient) {
1279
Saurabh Shah27c1d652012-08-14 19:30:28 -07001280 int& crop_l = crop.left;
1281 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001282 int& crop_r = crop.right;
1283 int& crop_b = crop.bottom;
1284 int crop_w = crop.right - crop.left;
1285 int crop_h = crop.bottom - crop.top;
1286
Saurabh Shah27c1d652012-08-14 19:30:28 -07001287 int& dst_l = dst.left;
1288 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001289 int& dst_r = dst.right;
1290 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001291 int dst_w = abs(dst.right - dst.left);
1292 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001293
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001294 const int& sci_l = scissor.left;
1295 const int& sci_t = scissor.top;
1296 const int& sci_r = scissor.right;
1297 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001298
Saurabh Shah68107422013-07-09 11:12:42 -07001299 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1300 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001301
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001302 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001303 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001304 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001305 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001306
1307 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001308 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001309 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001310 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001311
1312 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001313 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001314 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001315 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001316
1317 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001318 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001319 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001320 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001321
Saurabh Shah541b59d2012-10-11 11:08:12 -07001322 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301323 crop_l += (int)round((double)crop_w * leftCutRatio);
1324 crop_t += (int)round((double)crop_h * topCutRatio);
1325 crop_r -= (int)round((double)crop_w * rightCutRatio);
1326 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001327}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001328
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301329bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1330 const hwc_layer_1_t* layer2) {
1331 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1332 layer2->displayFrame);
1333 return isValidRect(irect);
1334}
1335
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001336bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1337{
1338 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1339 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1340}
1341
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001342bool isValidRect(const hwc_rect& rect)
1343{
1344 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301345}
1346
Ramakant Singh21cec722014-03-07 19:11:45 +05301347bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1348 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1349 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1350 return true ;
1351 return false;
1352}
1353
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001354hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1355{
1356 hwc_rect_t res;
1357
1358 if(!isValidRect(rect))
1359 return (hwc_rect_t){0, 0, 0, 0};
1360
1361 res.left = rect.left + x_off;
1362 res.top = rect.top + y_off;
1363 res.right = rect.right + x_off;
1364 res.bottom = rect.bottom + y_off;
1365
1366 return res;
1367}
1368
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001369/* computes the intersection of two rects */
1370hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1371{
1372 hwc_rect_t res;
1373
1374 if(!isValidRect(rect1) || !isValidRect(rect2)){
1375 return (hwc_rect_t){0, 0, 0, 0};
1376 }
1377
1378
1379 res.left = max(rect1.left, rect2.left);
1380 res.top = max(rect1.top, rect2.top);
1381 res.right = min(rect1.right, rect2.right);
1382 res.bottom = min(rect1.bottom, rect2.bottom);
1383
1384 if(!isValidRect(res))
1385 return (hwc_rect_t){0, 0, 0, 0};
1386
1387 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301388}
1389
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001390/* computes the union of two rects */
1391hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1392{
1393 hwc_rect_t res;
1394
1395 if(!isValidRect(rect1)){
1396 return rect2;
1397 }
1398
1399 if(!isValidRect(rect2)){
1400 return rect1;
1401 }
1402
1403 res.left = min(rect1.left, rect2.left);
1404 res.top = min(rect1.top, rect2.top);
1405 res.right = max(rect1.right, rect2.right);
1406 res.bottom = max(rect1.bottom, rect2.bottom);
1407
1408 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301409}
1410
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001411/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1412 * a single rect */
1413hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301414
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001415 hwc_rect_t res = rect1;
1416
1417 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1418 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1419 res.top = rect2.bottom;
1420 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1421 res.bottom = rect2.top;
1422 }
1423 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1424 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1425 res.left = rect2.right;
1426 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1427 res.right = rect2.left;
1428 }
1429 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301430}
1431
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001432void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301433 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301434 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301435 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001436 //If it is opaque see if we can substract this region from below
1437 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301438 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1439 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301440 int j= i-1;
1441 hwc_rect_t& topframe =
1442 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1443 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301444 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001445 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1446 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001447 hwc_rect_t bottomCrop =
1448 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001449 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1450 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001451
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001452 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1453 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001454 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001455 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001456 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001457 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001458 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001459 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301460 layer->sourceCropf.left =(float)bottomCrop.left;
1461 layer->sourceCropf.top = (float)bottomCrop.top;
1462 layer->sourceCropf.right = (float)bottomCrop.right;
1463 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001464#ifdef QCOM_BSP
1465 //Update layer dirtyRect
1466 layer->dirtyRect = getIntersection(bottomCrop,
1467 layer->dirtyRect);
1468#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001469 }
1470 }
1471 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301472 }
1473 }
1474 i--;
1475 }
1476}
1477
Naseer Ahmed64b81212013-02-14 10:29:47 -05001478void getNonWormholeRegion(hwc_display_contents_1_t* list,
1479 hwc_rect_t& nwr)
1480{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301481 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001482 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1483 //Initiliaze nwr to first frame
1484 nwr.left = list->hwLayers[0].displayFrame.left;
1485 nwr.top = list->hwLayers[0].displayFrame.top;
1486 nwr.right = list->hwLayers[0].displayFrame.right;
1487 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1488
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301489 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001490 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001491 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001492 }
1493
1494 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001495 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001496}
1497
Saurabh Shah747af1e2013-02-26 10:25:12 -08001498void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001499 if(LIKELY(list)) {
1500 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1501 //Close the acquireFenceFds
1502 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1503 if(list->hwLayers[i].acquireFenceFd >= 0) {
1504 close(list->hwLayers[i].acquireFenceFd);
1505 list->hwLayers[i].acquireFenceFd = -1;
1506 }
1507 }
1508 //Writeback
1509 if(list->outbufAcquireFenceFd >= 0) {
1510 close(list->outbufAcquireFenceFd);
1511 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001512 }
1513 }
1514}
1515
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001516int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001517 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001518 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001519 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001520 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001521 int count = 0;
1522 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001523 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001524 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001525 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001526
1527 struct mdp_buf_sync data;
1528 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001529 data.acq_fen_fd = acquireFd;
1530 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001531 data.retire_fen_fd = &retireFd;
1532 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001533
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001534 char property[PROPERTY_VALUE_MAX];
1535 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1536 if(atoi(property) == 0)
1537 swapzero = true;
1538 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001539
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001540 bool isExtAnimating = false;
1541 if(dpy)
1542 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001543
Saurabh Shah23a813c2013-03-20 16:58:12 -07001544 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001545 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001546 int rotFd = ctx->mRotMgr->getRotDevFd();
1547 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001548 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1549 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1550 if((currRot == NULL) || (currLayer == NULL)) {
1551 continue;
1552 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001553 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001554 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001555 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001556 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001557 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001558 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001559 if(currLayer->acquireFenceFd >= 0) {
1560 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1561 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001562 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301563 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301564 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1565
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001566 if(ret < 0) {
1567 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1568 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001569 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001570 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001571 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001572 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001573 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001574 dup(rotReleaseFd);
1575 //A buffer is free to be used by producer as soon as its copied to
1576 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001577 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001578 rotReleaseFd;
1579 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001580 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001581
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301582 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001583 if(list->outbufAcquireFenceFd >= 0) {
1584 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301585 if(LIKELY(!swapzero) )
1586 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001587 }
1588
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001589 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301590 if(((isAbcInUse(ctx)== true ) ||
1591 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001592 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301593 if(LIKELY(!swapzero) ) {
1594 // if ABC is enabled for more than one layer.
1595 // renderBufIndexforABC will work as FB.Hence
1596 // set the acquireFD from fd - which is coming from copybit
1597 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1598 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1599 acquireFd[count++] = fd;
1600 else
1601 continue;
1602 } else
1603 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1604 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001605 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001606 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301607 if(LIKELY(!swapzero) ) {
1608 if(fd >= 0) {
1609 //set the acquireFD from fd - which is coming from c2d
1610 acquireFd[count++] = fd;
1611 // Buffer sync IOCTL should be async when using c2d fence is
1612 // used
1613 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1614 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1615 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1616 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001617 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001618 }
1619
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001620 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001621 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301622 if(LIKELY(!swapzero) )
1623 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001624 }
1625
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001626 data.acq_fen_fd_cnt = count;
1627 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001628
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001629 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001630 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001631 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001632 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001633
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001634 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001635 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1636 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301637 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001638 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1639 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001640 close(releaseFd);
1641 releaseFd = -1;
1642 close(retireFd);
1643 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001644 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001645
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001646 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001647 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001648#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001649 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001650#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001651 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001652 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001653 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001654 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001655 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001656 // Release all the app layer fds immediately,
1657 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001658 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001659 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001660#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001661 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301662 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301663
1664 // if ABC is enabled for more than one layer
1665 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1666 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1667 list->hwLayers[i].releaseFenceFd = dup(fd);
1668 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1669 (isAbcInUse(ctx) == false)){
1670 //For Blit, the app layers should be released when the Blit
1671 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301672 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001673 } else
1674#endif
1675 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301676 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1677 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001678 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001679 }
1680 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001681
1682 if(fd >= 0) {
1683 close(fd);
1684 fd = -1;
1685 }
1686
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001687 if (ctx->mCopyBit[dpy]) {
1688 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001689 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1690 else
1691 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1692 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001693
Saurabh Shah23a813c2013-03-20 16:58:12 -07001694 //Signals when MDP finishes reading rotator buffers.
1695 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001696 close(releaseFd);
1697 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001698
Arun Kumar K.R51835182013-11-19 11:20:28 -08001699 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001700 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001701 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001702 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001703 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001704 return ret;
1705}
1706
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001707void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001708 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001709 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001710 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001711 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001712
1713 if(layer->blending == HWC_BLENDING_PREMULT) {
1714 ovutils::setMdpFlags(mdpFlags,
1715 ovutils::OV_MDP_BLEND_FG_PREMULT);
1716 }
1717
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001718 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1719 metadata->interlaced) {
1720 ovutils::setMdpFlags(mdpFlags,
1721 ovutils::OV_MDP_DEINTERLACE);
1722 }
1723
1724 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1725 if(isSecureBuffer(hnd)) {
1726 ovutils::setMdpFlags(mdpFlags,
1727 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301728 ovutils::setMdpFlags(mdpFlags,
1729 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1730 }
1731
1732 if(isProtectedBuffer(hnd)) {
1733 ovutils::setMdpFlags(mdpFlags,
1734 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001735 }
1736
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001737 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001738 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001739 ovutils::setMdpFlags(mdpFlags,
1740 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1741 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001742
1743 //Pre-rotation will be used using rotator.
1744 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1745 ovutils::setMdpFlags(mdpFlags,
1746 ovutils::OV_MDP_SOURCE_ROTATED_90);
1747 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001748 //No 90 component and no rot-downscale then flips done by MDP
1749 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001750 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1751 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001752 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1753 }
1754
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001755 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001756 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1757 }
1758 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001759
1760 if(metadata &&
1761 ((metadata->operation & PP_PARAM_HSIC)
1762 || (metadata->operation & PP_PARAM_IGC)
1763 || (metadata->operation & PP_PARAM_SHARP2))) {
1764 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1765 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001766}
1767
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301768int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001769 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001770 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001771
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301772 // Fix alignments for TILED format
1773 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1774 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1775 whf.w = utils::alignup(whf.w, 64);
1776 whf.h = utils::alignup(whf.h, 32);
1777 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001778 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001779
1780 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1781 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001782 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1783 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001784 rot->setCrop(rotCrop);
1785 }
1786
Saurabh Shahacf10202013-02-26 10:15:15 -08001787 rot->setFlags(mdpFlags);
1788 rot->setTransform(orient);
1789 rot->setDownscale(downscale);
1790 if(!rot->commit()) return -1;
1791 return 0;
1792}
1793
Saurabh Shahe2474082013-05-15 16:32:13 -07001794int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001795 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001796 const hwc_rect_t& pos, const MetaData_t *metadata,
1797 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001798 ov->setSource(parg, dest);
1799 ov->setTransform(orient, dest);
1800
1801 int crop_w = crop.right - crop.left;
1802 int crop_h = crop.bottom - crop.top;
1803 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1804 ov->setCrop(dcrop, dest);
1805
1806 int posW = pos.right - pos.left;
1807 int posH = pos.bottom - pos.top;
1808 Dim position(pos.left, pos.top, posW, posH);
1809 ov->setPosition(position, dest);
1810
Saurabh Shah5daeee52013-01-23 16:52:26 +08001811 if (metadata)
1812 ov->setVisualParams(*metadata, dest);
1813
Saurabh Shahacf10202013-02-26 10:15:15 -08001814 if (!ov->commit(dest)) {
1815 return -1;
1816 }
1817 return 0;
1818}
1819
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001820int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1821 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001822 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001823
1824 hwc_rect_t dst = layer->displayFrame;
1825 trimLayer(ctx, dpy, 0, dst, dst);
1826
1827 int w = ctx->dpyAttr[dpy].xres;
1828 int h = ctx->dpyAttr[dpy].yres;
1829 int dst_w = dst.right - dst.left;
1830 int dst_h = dst.bottom - dst.top;
1831 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001832 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001833
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001834 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001835 if (layer->blending == HWC_BLENDING_PREMULT)
1836 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1837
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001838 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001839 layer->planeAlpha,
1840 (ovutils::eBlending) getBlending(layer->blending));
1841
1842 // Configure MDP pipe for Color layer
1843 Dim pos(dst.left, dst.top, dst_w, dst_h);
1844 ctx->mOverlay->setSource(parg, dest);
1845 ctx->mOverlay->setColor(color, dest);
1846 ctx->mOverlay->setTransform(0, dest);
1847 ctx->mOverlay->setCrop(pos, dest);
1848 ctx->mOverlay->setPosition(pos, dest);
1849
1850 if (!ctx->mOverlay->commit(dest)) {
1851 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1852 return -1;
1853 }
1854 return 0;
1855}
1856
Saurabh Shahe2474082013-05-15 16:32:13 -07001857void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001858 hwc_rect_t& crop, Rotator *rot) {
1859 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001860 crop.right - crop.left,
1861 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001862 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1863 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001864 //B-family rotator internally could modify destination dimensions if
1865 //downscaling is supported
1866 whf = rot->getDstWhf();
1867 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001868 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001869 //A-family rotator rotates entire buffer irrespective of crop, forcing
1870 //us to recompute the crop based on transform
1871 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1872 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001873 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001874
1875 crop.left = transformedCrop.x;
1876 crop.top = transformedCrop.y;
1877 crop.right = transformedCrop.x + transformedCrop.w;
1878 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001879}
1880
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001881int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1882 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1883 return 0;
1884 }
1885
1886 int downscale = 0;
1887 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1888 hwc_rect_t dst = layer->displayFrame;
1889 private_handle_t *hnd = (private_handle_t *)layer->handle;
1890
1891 if(not hnd) {
1892 return 0;
1893 }
1894
1895 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1896 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1897 && metadata->interlaced;
1898 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001899 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001900
1901 if(isYuvBuffer(hnd)) {
1902 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1903 ctx->mMDP.version < qdutils::MDSS_V5) {
1904 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1905 crop.bottom - crop.top, dst.right - dst.left,
1906 dst.bottom - dst.top, format, isInterlaced);
1907 } else {
1908 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1909 crop.bottom - crop.top);
1910 Dim pos(dst.left, dst.top, dst.right - dst.left,
1911 dst.bottom - dst.top);
1912 if(transform & HAL_TRANSFORM_ROT_90) {
1913 swap(adjCrop.w, adjCrop.h);
1914 }
1915 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1916 pos.h, format, isInterlaced);
1917 }
1918 }
1919 return downscale;
1920}
1921
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001922bool isZoomModeEnabled(hwc_rect_t crop) {
1923 // This does not work for zooming in top left corner of the image
1924 return(crop.top > 0 || crop.left > 0);
1925}
1926
1927void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1928 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1929 crop.left, crop.top, crop.right, crop.bottom);
1930 if(isZoomModeEnabled(crop)) {
1931 Dim srcCrop(crop.left, crop.top,
1932 crop.right - crop.left,
1933 crop.bottom - crop.top);
1934 int extW = ctx->dpyAttr[dpy].xres;
1935 int extH = ctx->dpyAttr[dpy].yres;
1936 //Crop the original video in order to fit external display aspect ratio
1937 if(srcCrop.w * extH < extW * srcCrop.h) {
1938 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1939 crop.top += offset;
1940 crop.bottom -= offset;
1941 } else {
1942 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1943 crop.left += offset;
1944 crop.right -= offset;
1945 }
1946 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1947 " source crop [%d %d %d %d]", extW, extH, dpy,
1948 crop.left, crop.top, crop.right, crop.bottom);
1949 }
1950}
1951
1952void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1953 hwc_rect_t& dst, int dpy) {
1954 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1955 dst.left, dst.top, dst.right, dst.bottom);
1956 Dim srcCrop(crop.left, crop.top,
1957 crop.right - crop.left,
1958 crop.bottom - crop.top);
1959 int extW = ctx->dpyAttr[dpy].xres;
1960 int extH = ctx->dpyAttr[dpy].yres;
1961 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07001962 // when zoom in mode is enabled or the ratio between video aspect ratio
1963 // and external display aspect ratio is below the minimum tolerance level
1964 // and above maximum tolerance level
1965 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
1966 float extDisplayAspectRatio = ((float)extW / (float)extH);
1967 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
1968 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
1969 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001970 dst.left = 0;
1971 dst.top = 0;
1972 dst.right = extW;
1973 dst.bottom = extH;
1974 }
1975 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1976 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
1977 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
1978 crop.left, crop.top, crop.right, crop.bottom);
1979}
1980
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001981void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001982 hwc_rect_t& dst, int dpy) {
1983 updateCropAIVVideoMode(ctx, crop, dpy);
1984 updateDestAIVVideoMode(ctx, crop, dst, dpy);
1985}
1986
Saurabh Shah88e4d272013-09-03 13:31:29 -07001987int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001988 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001989 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001990
1991 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001992
Saurabh Shahacf10202013-02-26 10:15:15 -08001993 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001994 if (layer->flags & HWC_COLOR_FILL) {
1995 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001996 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001997 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001998 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1999 return -1;
2000 }
2001
Saurabh Shah5daeee52013-01-23 16:52:26 +08002002 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2003
Saurabh Shah62e1d732013-09-17 10:44:05 -07002004 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002005 hwc_rect_t dst = layer->displayFrame;
2006 int transform = layer->transform;
2007 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002008 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002009 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302010 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002011
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002012 // Handle R/B swap
2013 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2014 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2015 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2016 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2017 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2018 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002019 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002020 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2021 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002022 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002023 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002024 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002025 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002026
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002027 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002028 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002029 *rot = ctx->mRotMgr->getNext();
2030 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002031 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002032 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2033 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002034 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002035 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2036 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002037 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002038 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002039 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002040 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002041 }
2042
Saurabh Shah76fd6552013-03-14 14:45:38 -07002043 //For the mdp, since either we are pre-rotating or MDP does flips
2044 orient = OVERLAY_TRANSFORM_0;
2045 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002046 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002047 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2048 (ovutils::eBlending) getBlending(layer->blending));
2049
Saurabh Shah5daeee52013-01-23 16:52:26 +08002050 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002051 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2052 return -1;
2053 }
2054 return 0;
2055}
2056
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002057//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002058void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002059 private_handle_t *hnd) {
2060 if(cropL.right - cropL.left) {
2061 if(isYuvBuffer(hnd)) {
2062 //Always safe to even down left
2063 ovutils::even_floor(cropL.left);
2064 //If right is even, automatically width is even, since left is
2065 //already even
2066 ovutils::even_floor(cropL.right);
2067 }
2068 //Make sure there are no gaps between left and right splits if the layer
2069 //is spread across BOTH halves
2070 if(cropR.right - cropR.left) {
2071 cropR.left = cropL.right;
2072 }
2073 }
2074
2075 if(cropR.right - cropR.left) {
2076 if(isYuvBuffer(hnd)) {
2077 //Always safe to even down left
2078 ovutils::even_floor(cropR.left);
2079 //If right is even, automatically width is even, since left is
2080 //already even
2081 ovutils::even_floor(cropR.right);
2082 }
2083 }
2084}
2085
Saurabh Shah88e4d272013-09-03 13:31:29 -07002086int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002087 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002088 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002089 Rotator **rot) {
2090 private_handle_t *hnd = (private_handle_t *)layer->handle;
2091 if(!hnd) {
2092 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2093 return -1;
2094 }
2095
Saurabh Shah5daeee52013-01-23 16:52:26 +08002096 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2097
Saurabh Shahacf10202013-02-26 10:15:15 -08002098 int hw_w = ctx->dpyAttr[dpy].xres;
2099 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002100 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002101 hwc_rect_t dst = layer->displayFrame;
2102 int transform = layer->transform;
2103 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002104 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002105 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302106 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002107
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002108 // Handle R/B swap
2109 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2110 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2111 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2112 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2113 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2114 }
2115
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002116 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002117 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2118 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002119 }
2120
2121 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002122 ActionSafe, and extorientation features. */
2123 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002124 int downscale = getRotDownscale(ctx, layer);
2125 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002126
2127 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2128 //Enable overfetch
2129 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2130 }
2131
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002132 //Will do something only if feature enabled and conditions suitable
2133 //hollow call otherwise
2134 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2135 overlay::Writeback *wb = overlay::Writeback::getInstance();
2136 whf.format = wb->getOutputFormat();
2137 }
2138
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002139 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002140 (*rot) = ctx->mRotMgr->getNext();
2141 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002142 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002143 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002144 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2145 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002146 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002147 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002148 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002149 rotFlags |= ROT_PREROTATED;
2150 }
2151
2152 eMdpFlags mdpFlagsR = mdpFlagsL;
2153 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2154
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002155 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2156 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002157
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002158 const int lSplit = getLeftSplit(ctx, dpy);
2159
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002160 // Calculate Left rects
2161 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002162 tmp_cropL = crop;
2163 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002164 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002165 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002166 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2167 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002168
2169 // Calculate Right rects
2170 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002171 tmp_cropR = crop;
2172 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002173 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002174 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002175 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2176 }
2177
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002178 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2179
Saurabh Shah94d62362013-07-02 10:58:48 -07002180 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002181 //Not needed if the layer is confined to one half of the screen.
2182 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002183 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2184 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002185 hwc_rect_t new_cropR;
2186 new_cropR.left = tmp_cropL.left;
2187 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2188
2189 hwc_rect_t new_cropL;
2190 new_cropL.left = new_cropR.right;
2191 new_cropL.right = tmp_cropR.right;
2192
2193 tmp_cropL.left = new_cropL.left;
2194 tmp_cropL.right = new_cropL.right;
2195
2196 tmp_cropR.left = new_cropR.left;
2197 tmp_cropR.right = new_cropR.right;
2198
2199 }
2200
Saurabh Shah76fd6552013-03-14 14:45:38 -07002201 //For the mdp, since either we are pre-rotating or MDP does flips
2202 orient = OVERLAY_TRANSFORM_0;
2203 transform = 0;
2204
Saurabh Shahacf10202013-02-26 10:15:15 -08002205 //configure left mixer
2206 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002207 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002208 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2209 (ovutils::eBlending) getBlending(layer->blending));
2210
Saurabh Shahacf10202013-02-26 10:15:15 -08002211 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002212 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002213 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2214 return -1;
2215 }
2216 }
2217
2218 //configure right mixer
2219 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002220 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002221 static_cast<eRotFlags>(rotFlags),
2222 layer->planeAlpha,
2223 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002224 tmp_dstR.right = tmp_dstR.right - lSplit;
2225 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002226 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002227 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002228 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2229 return -1;
2230 }
2231 }
2232
2233 return 0;
2234}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002235
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002236int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2237 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2238 const eDest& lDest, const eDest& rDest,
2239 Rotator **rot) {
2240 private_handle_t *hnd = (private_handle_t *)layer->handle;
2241 if(!hnd) {
2242 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2243 return -1;
2244 }
2245 //Both pipes are configured to the same mixer
2246 eZorder lz = z;
2247 eZorder rz = (eZorder)(z + 1);
2248
2249 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2250
2251 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2252 hwc_rect_t dst = layer->displayFrame;
2253 int transform = layer->transform;
2254 eTransform orient = static_cast<eTransform>(transform);
2255 int rotFlags = ROT_FLAGS_NONE;
2256 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2257 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2258
2259 int downscale = getRotDownscale(ctx, layer);
2260 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2261
2262 //XXX: Check if rotation is supported and valid for 3D
2263 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2264 (*rot) = ctx->mRotMgr->getNext();
2265 if((*rot) == NULL) return -1;
2266 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2267 //Configure rotator for pre-rotation
2268 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2269 ALOGE("%s: configRotator failed!", __FUNCTION__);
2270 return -1;
2271 }
2272 updateSource(orient, whf, crop, *rot);
2273 rotFlags |= ROT_PREROTATED;
2274 }
2275
2276 eMdpFlags mdpFlagsR = mdpFlagsL;
2277
2278 hwc_rect_t cropL = crop, dstL = dst;
2279 hwc_rect_t cropR = crop, dstR = dst;
2280 int hw_w = ctx->dpyAttr[dpy].xres;
2281 int hw_h = ctx->dpyAttr[dpy].yres;
2282
2283 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2284 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2285 // Calculate Left rects
2286 // XXX: This assumes crop.right/2 is the center point of the video
2287 cropL.right = crop.right/2;
2288 dstL.left = dst.left/2;
2289 dstL.right = dst.right/2;
2290
2291 // Calculate Right rects
2292 cropR.left = crop.right/2;
2293 dstR.left = hw_w/2 + dst.left/2;
2294 dstR.right = hw_w/2 + dst.right/2;
2295 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2296 // Calculate Left rects
2297 cropL.bottom = crop.bottom/2;
2298 dstL.top = dst.top/2;
2299 dstL.bottom = dst.bottom/2;
2300
2301 // Calculate Right rects
2302 cropR.top = crop.bottom/2;
2303 dstR.top = hw_h/2 + dst.top/2;
2304 dstR.bottom = hw_h/2 + dst.bottom/2;
2305 } else {
2306 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2307 return -1;
2308 }
2309
2310 //For the mdp, since either we are pre-rotating or MDP does flips
2311 orient = OVERLAY_TRANSFORM_0;
2312 transform = 0;
2313
2314 //configure left pipe
2315 if(lDest != OV_INVALID) {
2316 PipeArgs pargL(mdpFlagsL, whf, lz,
2317 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2318 (ovutils::eBlending) getBlending(layer->blending));
2319
2320 if(configMdp(ctx->mOverlay, pargL, orient,
2321 cropL, dstL, metadata, lDest) < 0) {
2322 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2323 return -1;
2324 }
2325 }
2326
2327 //configure right pipe
2328 if(rDest != OV_INVALID) {
2329 PipeArgs pargR(mdpFlagsR, whf, rz,
2330 static_cast<eRotFlags>(rotFlags),
2331 layer->planeAlpha,
2332 (ovutils::eBlending) getBlending(layer->blending));
2333 if(configMdp(ctx->mOverlay, pargR, orient,
2334 cropR, dstR, metadata, rDest) < 0) {
2335 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2336 return -1;
2337 }
2338 }
2339
2340 return 0;
2341}
2342
radhakrishnac9a67412013-09-25 17:40:42 +05302343int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2344 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002345 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302346 Rotator **rot) {
2347 private_handle_t *hnd = (private_handle_t *)layer->handle;
2348 if(!hnd) {
2349 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2350 return -1;
2351 }
2352
2353 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2354
radhakrishnac9a67412013-09-25 17:40:42 +05302355 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2356 hwc_rect_t dst = layer->displayFrame;
2357 int transform = layer->transform;
2358 eTransform orient = static_cast<eTransform>(transform);
2359 const int downscale = 0;
2360 int rotFlags = ROT_FLAGS_NONE;
2361 //Splitting only YUV layer on primary panel needs different zorders
2362 //for both layers as both the layers are configured to single mixer
2363 eZorder lz = z;
2364 eZorder rz = (eZorder)(z + 1);
2365
2366 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302367 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302368
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002369 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002370 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2371 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002372 }
2373
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002374 /* Calculate the external display position based on MDP downscale,
2375 ActionSafe, and extorientation features. */
2376 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2377
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002378 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302379 trimLayer(ctx, dpy, transform, crop, dst);
2380
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002381 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302382 (*rot) = ctx->mRotMgr->getNext();
2383 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002384 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302385 //Configure rotator for pre-rotation
2386 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2387 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302388 return -1;
2389 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002390 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302391 rotFlags |= ROT_PREROTATED;
2392 }
2393
2394 eMdpFlags mdpFlagsR = mdpFlagsL;
2395 int lSplit = dst.left + (dst.right - dst.left)/2;
2396
2397 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2398 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2399
2400 if(lDest != OV_INVALID) {
2401 tmp_cropL = crop;
2402 tmp_dstL = dst;
2403 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2404 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2405 }
2406 if(rDest != OV_INVALID) {
2407 tmp_cropR = crop;
2408 tmp_dstR = dst;
2409 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2410 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2411 }
2412
2413 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2414
2415 //When buffer is H-flipped, contents of mixer config also needs to swapped
2416 //Not needed if the layer is confined to one half of the screen.
2417 //If rotator has been used then it has also done the flips, so ignore them.
2418 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2419 && rDest != OV_INVALID && (*rot) == NULL) {
2420 hwc_rect_t new_cropR;
2421 new_cropR.left = tmp_cropL.left;
2422 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2423
2424 hwc_rect_t new_cropL;
2425 new_cropL.left = new_cropR.right;
2426 new_cropL.right = tmp_cropR.right;
2427
2428 tmp_cropL.left = new_cropL.left;
2429 tmp_cropL.right = new_cropL.right;
2430
2431 tmp_cropR.left = new_cropR.left;
2432 tmp_cropR.right = new_cropR.right;
2433
2434 }
2435
2436 //For the mdp, since either we are pre-rotating or MDP does flips
2437 orient = OVERLAY_TRANSFORM_0;
2438 transform = 0;
2439
2440 //configure left half
2441 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002442 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302443 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2444 (ovutils::eBlending) getBlending(layer->blending));
2445
2446 if(configMdp(ctx->mOverlay, pargL, orient,
2447 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2448 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2449 return -1;
2450 }
2451 }
2452
2453 //configure right half
2454 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002455 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302456 static_cast<eRotFlags>(rotFlags),
2457 layer->planeAlpha,
2458 (ovutils::eBlending) getBlending(layer->blending));
2459 if(configMdp(ctx->mOverlay, pargR, orient,
2460 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2461 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2462 return -1;
2463 }
2464 }
2465
2466 return 0;
2467}
2468
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002469bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302470 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002471 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002472 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302473 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302474 * in LINE and BLOCK modes for writeback panels.
2475 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002476 if(dpy == HWC_DISPLAY_PRIMARY)
2477 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002478 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302479 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2480 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002481 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002482 return true;
2483}
2484
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002485int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2486 //Default even split for all displays with high res
2487 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2488 if(dpy == HWC_DISPLAY_PRIMARY &&
2489 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2490 //Override if split published by driver for primary
2491 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2492 }
2493 return lSplit;
2494}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002495
Saurabh Shah88e4d272013-09-03 13:31:29 -07002496bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302497 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002498 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002499 return true;
2500 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302501 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002502 return true;
2503 }
2504 return false;
2505}
2506
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002507//clear prev layer prop flags and realloc for current frame
2508void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2509 if(ctx->layerProp[dpy]) {
2510 delete[] ctx->layerProp[dpy];
2511 ctx->layerProp[dpy] = NULL;
2512 }
2513 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2514}
2515
Ramakant Singh0def28c2014-03-28 20:43:13 +05302516bool isAbcInUse(hwc_context_t *ctx){
2517 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2518}
2519
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002520void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2521 if (ohnd != NULL && ohnd->base) {
2522 char dumpFilename[PATH_MAX];
2523 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002524 int width = getWidth(ohnd);
2525 int height = getHeight(ohnd);
2526 int format = ohnd->format;
2527 //dummy aligned w & h.
2528 int alW = 0, alH = 0;
2529 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002530 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2531 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002532 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2533 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002534 FILE* fp = fopen(dumpFilename, "w+");
2535 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002536 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002537 fclose(fp);
2538 }
2539 ALOGD("Buffer[%s] Dump to %s: %s",
2540 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2541 }
2542}
2543
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002544bool isGLESComp(hwc_context_t *ctx,
2545 hwc_display_contents_1_t* list) {
2546 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2547 for(int index = 0; index < numAppLayers; index++) {
2548 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2549 if(layer->compositionType == HWC_FRAMEBUFFER)
2550 return true;
2551 }
2552 return false;
2553}
2554
2555void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2556 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002557 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002558 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002559
2560#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002561 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2562 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2563 hint to default if the previous composition is GPU or current GPU
2564 composition is due to idle fallback */
2565 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2566 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2567 if(!gpuHint->mEGLDisplay) {
2568 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2569 return;
2570 }
2571 gpuHint->mEGLContext = eglGetCurrentContext();
2572 if(!gpuHint->mEGLContext) {
2573 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2574 return;
2575 }
2576 }
2577 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002578 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2579 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002580 EGLint attr_list[] = {EGL_GPU_HINT_1,
2581 EGL_GPU_LEVEL_3,
2582 EGL_NONE };
2583 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2584 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2585 gpuHint->mEGLContext, attr_list)) {
2586 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2587 } else {
2588 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002589 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002590 }
2591 } else {
2592 EGLint attr_list[] = {EGL_GPU_HINT_1,
2593 EGL_GPU_LEVEL_0,
2594 EGL_NONE };
2595 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2596 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2597 gpuHint->mEGLContext, attr_list)) {
2598 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2599 } else {
2600 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2601 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002602 if(MDPComp::isIdleFallback()) {
2603 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2604 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002605 }
2606 } else {
2607 /* set the GPU hint flag to default for MDP composition */
2608 EGLint attr_list[] = {EGL_GPU_HINT_1,
2609 EGL_GPU_LEVEL_0,
2610 EGL_NONE };
2611 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2612 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2613 gpuHint->mEGLContext, attr_list)) {
2614 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2615 } else {
2616 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2617 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002618 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002619 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002620#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002621}
2622
Sushil Chauhandefd3522014-05-13 18:17:12 -07002623bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2624 // To be peripheral, 3 boundaries should match.
2625 uint8_t eqBounds = 0;
2626 if (rect1.left == rect2.left)
2627 eqBounds++;
2628 if (rect1.top == rect2.top)
2629 eqBounds++;
2630 if (rect1.right == rect2.right)
2631 eqBounds++;
2632 if (rect1.bottom == rect2.bottom)
2633 eqBounds++;
2634 return (eqBounds == 3);
2635}
2636
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302637void processBootAnimCompleted(hwc_context_t *ctx) {
2638 char value[PROPERTY_VALUE_MAX];
2639 int boot_finished = 0, ret = -1;
2640 int (*applyMode)(int) = NULL;
2641 void *modeHandle = NULL;
2642
2643 // Reading property set on boot finish in SF
2644 property_get("service.bootanim.exit", value, "0");
2645 boot_finished = atoi(value);
2646 if (!boot_finished)
2647 return;
2648
2649 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2650 if (modeHandle) {
2651 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2652 if (applyMode) {
2653 ret = applyMode(HWC_DISPLAY_PRIMARY);
2654 if (ret)
2655 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2656 } else {
2657 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2658 }
2659 dlclose(modeHandle);
2660 } else {
2661 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
2662 }
2663
2664 ctx->mBootAnimCompleted = true;
2665}
2666
Saurabh Shahcd018352014-11-11 13:54:19 -08002667void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2668 const private_handle_t *hnd,
2669 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002670 const int& transform,const int& downscale,
2671 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002672 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302673 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002674 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002675 return;
2676 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002677 //Disabled at runtime
2678 if(not ctx->mBWCEnabled) return;
2679 //BWC not supported with rot-downscale
2680 if(downscale) return;
2681 //Not enabled for secondary displays
2682 if(dpy) return;
2683 //Not enabled for non-video buffers
2684 if(not isYuvBuffer(hnd)) return;
2685
Saurabh Shahb6810df2014-06-17 16:00:22 -07002686 int src_w = crop.right - crop.left;
2687 int src_h = crop.bottom - crop.top;
2688 int dst_w = dst.right - dst.left;
2689 int dst_h = dst.bottom - dst.top;
2690 if(transform & HAL_TRANSFORM_ROT_90) {
2691 swap(src_w, src_h);
2692 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002693 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002694 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002695 return;
2696 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002697 //Decimation necessary, cannot use BWC. H/W requirement.
2698 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002699 uint8_t horzDeci = 0;
2700 uint8_t vertDeci = 0;
2701 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2702 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002703 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002704 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002705
2706 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2707}
2708
Saurabh Shah23a813c2013-03-20 16:58:12 -07002709void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302710 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002711 mLayer[mCount] = layer;
2712 mRot[mCount] = rot;
2713 mCount++;
2714}
2715
2716void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302717 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002718 mLayer[i] = 0;
2719 mRot[i] = 0;
2720 }
2721 mCount = 0;
2722}
2723
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002724void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002725 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002726 reset();
2727}
2728
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302729bool LayerRotMap::isRotCached(uint32_t index) const {
2730 overlay::Rotator* rot = getRot(index);
2731 hwc_layer_1_t* layer = getLayer(index);
2732
2733 if(rot and layer and layer->handle) {
2734 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2735 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2736 }
2737 return false;
2738}
2739
Saurabh Shah23a813c2013-03-20 16:58:12 -07002740void LayerRotMap::setReleaseFd(const int& fence) {
2741 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302742 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2743 /* Ensure that none of the above (Rotator-instance,
2744 * layer and layer-handle) are NULL*/
2745 if(isRotCached(i))
2746 mRot[i]->setPrevBufReleaseFd(dup(fence));
2747 else
2748 mRot[i]->setCurrBufReleaseFd(dup(fence));
2749 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002750 }
2751}
2752
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002753hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2754 int lRoiWidth = 0, rRoiWidth = 0;
2755 int half_frame_width = fullFrame.right/2;
2756
2757 hwc_rect lFrame = fullFrame;
2758 hwc_rect rFrame = fullFrame;
2759 lFrame.right = (lFrame.right - lFrame.left)/2;
2760 rFrame.left = lFrame.right;
2761
2762 hwc_rect lRoi = getIntersection(roi, lFrame);
2763 hwc_rect rRoi = getIntersection(roi, rFrame);
2764
2765 lRoiWidth = lRoi.right - lRoi.left;
2766 rRoiWidth = rRoi.right - rRoi.left;
2767
2768 if(lRoiWidth && rRoiWidth) {
2769 if(lRoiWidth < rRoiWidth)
2770 roi.left = half_frame_width - rRoiWidth;
2771 else
2772 roi.right = half_frame_width + lRoiWidth;
2773 }
2774 return roi;
2775}
2776
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002777void resetROI(hwc_context_t *ctx, const int dpy) {
2778 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2779 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002780
2781 /* When source split is enabled, both the panels are calibrated
2782 * in a single coordinate system. So only one ROI is generated
2783 * for the whole panel extending equally from the midpoint and
2784 * populated for the left side. */
2785 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2786 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002787 const int lSplit = getLeftSplit(ctx, dpy);
2788 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2789 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2790 } else {
2791 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2792 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2793 }
2794}
2795
2796hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002797{
2798 if(!isValidRect(roi))
2799 return roi;
2800
2801 struct hwc_rect t_roi = roi;
2802
2803 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2804 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2805 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2806 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2807 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002808 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002809
2810 /* Align to minimum width recommended by the panel */
2811 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2812 if((t_roi.left + MIN_WIDTH) > boundary.right)
2813 t_roi.left = t_roi.right - MIN_WIDTH;
2814 else
2815 t_roi.right = t_roi.left + MIN_WIDTH;
2816 }
2817
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002818 /* Align to minimum height recommended by the panel */
2819 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2820 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2821 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2822 else
2823 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2824 }
2825
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002826 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002827 if(LEFT_ALIGN)
2828 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2829
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002830 if(WIDTH_ALIGN) {
2831 int width = t_roi.right - t_roi.left;
2832 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2833 t_roi.right = t_roi.left + width;
2834
2835 if(t_roi.right > boundary.right) {
2836 t_roi.right = boundary.right;
2837 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002838
2839 if(LEFT_ALIGN)
2840 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002841 }
2842 }
2843
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002844
2845 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002846 if(TOP_ALIGN)
2847 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2848
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002849 if(HEIGHT_ALIGN) {
2850 int height = t_roi.bottom - t_roi.top;
2851 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2852 t_roi.bottom = t_roi.top + height;
2853
2854 if(t_roi.bottom > boundary.bottom) {
2855 t_roi.bottom = boundary.bottom;
2856 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002857
2858 if(TOP_ALIGN)
2859 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002860 }
2861 }
2862
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002863
2864 return t_roi;
2865}
2866
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002867void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002868 if(ctx->dpyAttr[dpy].connected) {
2869 ctx->mDrawLock.lock();
2870 ctx->dpyAttr[dpy].isActive = true;
2871 ctx->dpyAttr[dpy].isPause = true;
2872 ctx->mDrawLock.unlock();
2873 ctx->proc->invalidate(ctx->proc);
2874
2875 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2876 * 2 / 1000);
2877
2878 // At this point all the pipes used by External have been
2879 // marked as UNSET.
2880 ctx->mDrawLock.lock();
2881 // Perform commit to unstage the pipes.
2882 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2883 ALOGE("%s: display commit fail! for %d dpy",
2884 __FUNCTION__, dpy);
2885 }
2886 ctx->mDrawLock.unlock();
2887 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002888 }
2889 return;
2890}
2891
2892void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002893 if(ctx->dpyAttr[dpy].connected) {
2894 ctx->mDrawLock.lock();
2895 ctx->dpyAttr[dpy].isConfiguring = true;
2896 ctx->dpyAttr[dpy].isActive = true;
2897 ctx->mDrawLock.unlock();
2898 ctx->proc->invalidate(ctx->proc);
2899
2900 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2901 * 2 / 1000);
2902
2903 //At this point external has all the pipes it would need.
2904 ctx->mDrawLock.lock();
2905 ctx->dpyAttr[dpy].isPause = false;
2906 ctx->mDrawLock.unlock();
2907 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002908 }
2909 return;
2910}
2911
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002912void clearPipeResources(hwc_context_t* ctx, int dpy) {
2913 if(ctx->mOverlay) {
2914 ctx->mOverlay->configBegin();
2915 ctx->mOverlay->configDone();
2916 }
2917 if(ctx->mRotMgr) {
2918 ctx->mRotMgr->clear();
2919 }
2920 // Call a display commit to ensure that pipes and associated
2921 // fd's are cleaned up.
2922 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2923 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2924 }
2925}
2926
2927// Handles online events when HDMI is the primary display. In particular,
2928// online events for hdmi connected before AND after boot up and HWC init.
2929void handle_online(hwc_context_t* ctx, int dpy) {
2930 // Close the current fd if it was opened earlier on when HWC
2931 // was initialized.
2932 if (ctx->dpyAttr[dpy].fd >= 0) {
2933 close(ctx->dpyAttr[dpy].fd);
2934 ctx->dpyAttr[dpy].fd = -1;
2935 }
2936 // TODO: If HDMI is connected after the display has booted up,
2937 // and the best configuration is different from the default
2938 // then we need to deal with this appropriately.
2939 ctx->mHDMIDisplay->configure();
2940 updateDisplayInfo(ctx, dpy);
2941 initCompositionResources(ctx, dpy);
2942 ctx->dpyAttr[dpy].connected = true;
2943}
2944
2945// Handles offline events for HDMI. This can be used for offline events
2946// initiated by the HDMI driver and the CEC framework.
2947void handle_offline(hwc_context_t* ctx, int dpy) {
2948 destroyCompositionResources(ctx, dpy);
2949 // Clear all pipe resources and call a display commit to ensure
2950 // that all the fd's are closed. This will ensure that the HDMI
2951 // core turns off and that we receive an event the next time the
2952 // cable is connected.
2953 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
2954 clearPipeResources(ctx, dpy);
2955 }
2956 ctx->mHDMIDisplay->teardown();
2957 resetDisplayInfo(ctx, dpy);
2958 ctx->dpyAttr[dpy].connected = false;
2959 ctx->dpyAttr[dpy].isActive = false;
2960}
2961
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002962int convertS3DFormatToMode(int s3DFormat) {
2963 int ret;
2964 switch(s3DFormat) {
2965 case HAL_3D_SIDE_BY_SIDE_L_R:
2966 case HAL_3D_SIDE_BY_SIDE_R_L:
2967 ret = HDMI_S3D_SIDE_BY_SIDE;
2968 break;
2969 case HAL_3D_TOP_BOTTOM:
2970 ret = HDMI_S3D_TOP_AND_BOTTOM;
2971 break;
2972 default:
2973 ret = HDMI_S3D_NONE;
2974 }
2975 return ret;
2976}
2977
2978bool needs3DComposition(hwc_context_t* ctx, int dpy) {
2979 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
2980 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
2981}
2982
2983void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
2984 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
2985 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
2986 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
2987 ctx->dpyAttr[dpy].s3dMode = s3dMode;
2988 }
2989 }
2990}
2991
2992bool displaySupports3D(hwc_context_t* ctx, int dpy) {
2993 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
2994 ((dpy == HWC_DISPLAY_PRIMARY) &&
2995 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
2996}
2997
2998
Saurabh Shahacf10202013-02-26 10:15:15 -08002999};//namespace qhwc