blob: 8a60f65afe7414fdce5862cf1d75efccce27ea4a [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Zohaib Alamc9d00cd2014-01-24 16:38:32 -05003 * Copyright (C) 2012-2014, The Linux Foundation All rights reserved.
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
Naseer Ahmed099a6932013-09-09 14:25:20 -040020#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080021#define HWC_UTILS_DEBUG 0
Saurabh Shahc5b96dc2013-06-05 13:19:52 -070022#include <math.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include <sys/ioctl.h>
Naseer Ahmed66e97882013-03-19 20:42:11 -040024#include <linux/fb.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080025#include <binder/IServiceManager.h>
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070026#include <EGL/egl.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070027#include <cutils/properties.h>
Naseer Ahmed099a6932013-09-09 14:25:20 -040028#include <utils/Trace.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070029#include <gralloc_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080031#include <overlayRotator.h>
Saurabh Shaha9da08f2013-07-03 13:27:53 -070032#include <overlayWriteback.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070033#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050034#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080035#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070036#include "hwc_ad.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070037#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "hwc_copybit.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070039#include "hwc_dump_layers.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070040#include "hdmi.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080041#include "hwc_qclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070042#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080043#include "comptype.h"
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -080044#include "hwc_virtual.h"
Tatenda Chipeperekwaa7dd23c2014-03-05 13:02:24 -080045#include "qd_utils.h"
Ramakant Singh98c533c2014-09-30 19:01:54 +053046#include <sys/sysinfo.h>
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +053047#include <dlfcn.h>
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050048#include <video/msm_hdmi_modes.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080049
50using namespace qClient;
51using namespace qService;
52using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080053using namespace overlay;
54using namespace overlay::utils;
55namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080056
Saurabh Shah74eff4d2014-03-28 16:33:13 -070057#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070058#ifdef __cplusplus
59extern "C" {
60#endif
61
62EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
63 EGLint *attrib_list);
64#define EGL_GPU_HINT_1 0x32D0
65#define EGL_GPU_HINT_2 0x32D1
66
67#define EGL_GPU_LEVEL_0 0x0
68#define EGL_GPU_LEVEL_1 0x1
69#define EGL_GPU_LEVEL_2 0x2
70#define EGL_GPU_LEVEL_3 0x3
71#define EGL_GPU_LEVEL_4 0x4
72#define EGL_GPU_LEVEL_5 0x5
73
74#ifdef __cplusplus
75}
76#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070077#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070078
Ramakant Singhb8369bf2014-10-29 18:42:43 +053079#define PROP_DEFAULT_APPBUFFER "sf.default.app_buffer_count"
Ramakant Singh98c533c2014-09-30 19:01:54 +053080#define MAX_RAM_SIZE 512*1024*1024
81#define qHD_WIDTH 540
82
83
Naseer Ahmed29a26812012-06-14 00:56:20 -070084namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070085
Arun Kumar K.R053dc502014-11-13 11:13:43 -080086// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
87uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070088
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053089bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
90{
Jeykumar Sankaran39305802014-12-12 17:55:57 -080091 return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053092 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
93 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
94}
95
Praveena Pachipulusu49d62062014-06-06 19:22:23 +053096void changeResolution(hwc_context_t *ctx, int xres_orig, int yres_orig,
97 int width, int height) {
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053098 //Store original display resolution.
Dileep Kumar Reddie351d842014-03-25 10:39:21 +053099 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_orig;
100 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_orig;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530101 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530102 char property[PROPERTY_VALUE_MAX] = {'\0'};
103 char *yptr = NULL;
104 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
105 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530106 if(yptr) {
107 int xres_new = atoi(property);
108 int yres_new = atoi(yptr + 1);
109 if (isValidResolution(ctx,xres_new,yres_new) &&
110 xres_new != xres_orig && yres_new != yres_orig) {
111 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_new;
112 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_new;
113 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530114
Raj Kamal4a443082014-10-12 21:07:59 +0530115 //Caluculate DPI according to changed resolution.
116 float xdpi = ((float)xres_new * 25.4f) / (float)width;
117 float ydpi = ((float)yres_new * 25.4f) / (float)height;
118 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
119 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
120 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530121 }
122 }
123}
124
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700125// Initialize hdmi display attributes based on
126// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700127void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700128 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
129 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
130 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
131 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
132 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700133 //FIXME: for now assume HDMI as secure
134 //Will need to read the HDCP status from the driver
135 //and update this accordingly
136 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700137 ctx->mViewFrame[dpy].left = 0;
138 ctx->mViewFrame[dpy].top = 0;
139 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
140 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
141}
142
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700143// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700144void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
145 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
146 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
147 // We reset the fd to -1 here but External display class is responsible
148 // for it when the display is disconnected. This is handled as part of
149 // EXTERNAL_OFFLINE event.
150 ctx->dpyAttr[dpy].fd = -1;
151}
152
153// Initialize composition resources
154void initCompositionResources(hwc_context_t* ctx, int dpy) {
155 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
156 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
157}
158
159void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
160 if(ctx->mFBUpdate[dpy]) {
161 delete ctx->mFBUpdate[dpy];
162 ctx->mFBUpdate[dpy] = NULL;
163 }
164 if(ctx->mMDPComp[dpy]) {
165 delete ctx->mMDPComp[dpy];
166 ctx->mMDPComp[dpy] = NULL;
167 }
168}
169
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800170static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700171{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800172 struct fb_fix_screeninfo finfo;
173 struct fb_var_screeninfo info;
174
175 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530176 if(fb_fd < 0) {
177 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800178 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530179 }
180
181 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
182 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
183 strerror(errno));
184 close(fb_fd);
185 return -errno;
186 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800187
188 if (int(info.width) <= 0 || int(info.height) <= 0) {
189 // the driver doesn't return that information
190 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530191 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
192 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700193 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800194
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530195 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
196 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800197
198#ifdef MSMFB_METADATA_GET
199 struct msmfb_metadata metadata;
200 memset(&metadata, 0 , sizeof(metadata));
201 metadata.op = metadata_op_frame_rate;
202
203 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530204 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
205 strerror(errno));
206 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800207 return -errno;
208 }
209
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530210 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800211#else
212 //XXX: Remove reserved field usage on all baselines
213 //The reserved[3] field is used to store FPS by the driver.
214 float fps = info.reserved[3] & 0xFF;
215#endif
216
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530217 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
218 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
219 strerror(errno));
220 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800221 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530222 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800223
224 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
225 //xres, yres may not be 32 aligned
226 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
227 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
228 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
229 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
230 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700231 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
232 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700233 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530234 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
235 (uint32_t)(1000000000l / fps);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800236
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530237 //To change resolution of primary display
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530238 changeResolution(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530239
Naseer Ahmed22616d92013-05-15 17:20:26 -0400240 //Unblank primary on first boot
241 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
242 ALOGE("%s: Failed to unblank display", __FUNCTION__);
243 return -errno;
244 }
245 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
246
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800247 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700248}
249
Ramakant Singh98c533c2014-09-30 19:01:54 +0530250static void changeDefaultAppBufferCount() {
251 struct sysinfo info;
252 unsigned long int ramSize = 0;
253 if (!sysinfo(&info)) {
254 ramSize = info.totalram ;
255 }
256 int fb_fd = -1;
257 struct fb_var_screeninfo sInfo ={0};
258 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
259 if (fb_fd >=0) {
260 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
261 close(fb_fd);
262 }
263 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
264 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
265 property_set(PROP_DEFAULT_APPBUFFER, "2");
266 }
267}
268
Arun Kumar K.R205df772015-02-20 18:45:58 -0800269int initContext(hwc_context_t *ctx)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700270{
Arun Kumar K.R205df772015-02-20 18:45:58 -0800271 int error = -1;
272 int compositionType = 0;
273
274 //Right now hwc starts the service but anybody could do it, or it could be
275 //independent process as well.
276 QService::init();
277 sp<IQClient> client = new QClient(ctx);
278 sp<IQService> iqs = interface_cast<IQService>(
279 defaultServiceManager()->getService(
280 String16("display.qservice")));
281 if (iqs.get()) {
282 iqs->connect(client);
283 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
284 } else {
285 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
286 return error;
287 }
288
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700289 overlay::Overlay::initOverlay();
290 ctx->mHDMIDisplay = new HDMIDisplay();
291 uint32_t priW = 0, priH = 0;
292 // 1. HDMI as Primary
293 // -If HDMI cable is connected, read display configs from edid data
294 // -If HDMI cable is not connected then use default data in vscreeninfo
295 // 2. HDMI as External
296 // -Initialize HDMI class for use with external display
297 // -Use vscreeninfo to populate display configs
298 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
299 int connected = ctx->mHDMIDisplay->getConnectedState();
300 if(connected == 1) {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800301 error = ctx->mHDMIDisplay->configure();
302 if (error < 0) {
303 goto OpenFBError;
304 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700305 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
306 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
307 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800308 error = openFramebufferDevice(ctx);
309 if(error < 0) {
310 goto OpenFBError;
311 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700312 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
313 }
314 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800315 error = openFramebufferDevice(ctx);
316 if(error < 0) {
317 goto OpenFBError;
318 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700319 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
320 // Send the primary resolution to the hdmi display class
321 // to be used for MDP scaling functionality
322 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
323 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
324 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
325 }
326
Raj kamal59fea562014-04-01 16:52:19 +0530327 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700328 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
329 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
330 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800331 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800332 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800333 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800334
Ramakant Singh98c533c2014-09-30 19:01:54 +0530335 //default_app_buffer for ferrum
336 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
337 changeDefaultAppBufferCount();
338 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700339 // Initialize composition objects for the primary display
340 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800341
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800342 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800343 // decide if we need to open the copybit module.
Arun Kumar K.R205df772015-02-20 18:45:58 -0800344 compositionType =
345 qdutils::QCCompositionType::getInstance().getCompositionType();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800346
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800347 // Only MDP copybit is used
348 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
349 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530350 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
351 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800352 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530353 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800354 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
355 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800356 }
357
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700358 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700359 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
360 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
361 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
362 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700363 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
364 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
365 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800366
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700367 //Initialize the primary display viewFrame info
368 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
369 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
370 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
371 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
372 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
373 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530374
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700375 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700376 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700377 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700378 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800379 ctx->dpyAttr[i].mActionSafePresent = false;
380 ctx->dpyAttr[i].mAsWidthRatio = 0;
381 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500382 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
383 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700384 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700385
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500386 //Make sure that the 3D mode is unset at bootup
387 //This makes sure that the state is accurate on framework reboots
388 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
389
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530390 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
391 ctx->mPrevHwLayerCount[i] = 0;
392 }
393
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500394 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700395 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700396
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400397 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500398 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700399 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530400 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800401
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700402 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700403 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700404 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400405
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700406 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
407 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
408
Ramakant Singh0def28c2014-03-28 20:43:13 +0530409 ctx->enableABC = false;
410 property_get("debug.sf.hwc.canUseABC", value, "0");
411 ctx->enableABC = atoi(value) ? true : false;
412
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530413 // Initializing boot anim completed check to false
414 ctx->mBootAnimCompleted = false;
415
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700416 // Initialize gpu perfomance hint related parameters
417 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700418#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700419 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
420
421 ctx->mGPUHintInfo.mEGLDisplay = NULL;
422 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700423 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700424 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700425#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700426 // Read the system property to determine if windowboxing feature is enabled.
427 ctx->mWindowboxFeature = false;
428 if(property_get("sys.hwc.windowbox_feature", value, "false")
429 && !strcmp(value, "true")) {
430 ctx->mWindowboxFeature = true;
431 }
432
Raj Kamal0d53fc62014-11-25 17:36:36 +0530433 ctx->mUseMetaDataRefreshRate = true;
434 if(property_get("persist.metadata_dynfps.disable", value, "false")
435 && !strcmp(value, "true")) {
436 ctx->mUseMetaDataRefreshRate = false;
437 }
438
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700439 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800440 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700441 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700442 ALOGI("MDP version: %d", ctx->mMDP.version);
Arun Kumar K.R205df772015-02-20 18:45:58 -0800443
444 return 0;
445
446OpenFBError:
447 ALOGE("%s: Fatal Error: FB Open failed!!!", __FUNCTION__);
448 delete ctx->mHDMIDisplay;
449 return error;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700450}
451
452void closeContext(hwc_context_t *ctx)
453{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500454 if(ctx->mOverlay) {
455 delete ctx->mOverlay;
456 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700457 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700458
Saurabh Shahacf10202013-02-26 10:15:15 -0800459 if(ctx->mRotMgr) {
460 delete ctx->mRotMgr;
461 ctx->mRotMgr = NULL;
462 }
463
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700464 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800465 if(ctx->mCopyBit[i]) {
466 delete ctx->mCopyBit[i];
467 ctx->mCopyBit[i] = NULL;
468 }
469 }
470
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800471 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700472 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
473 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700474 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700475
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700476 if(ctx->mHDMIDisplay) {
477 delete ctx->mHDMIDisplay;
478 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700479 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400480
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700481 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700482 destroyCompositionResources(ctx, i);
483
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700484 if(ctx->mHwcDebug[i]) {
485 delete ctx->mHwcDebug[i];
486 ctx->mHwcDebug[i] = NULL;
487 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700488 if(ctx->mLayerRotMap[i]) {
489 delete ctx->mLayerRotMap[i];
490 ctx->mLayerRotMap[i] = NULL;
491 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800492 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800493 if(ctx->mHWCVirtual) {
494 delete ctx->mHWCVirtual;
495 ctx->mHWCVirtual = NULL;
496 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700497 if(ctx->mAD) {
498 delete ctx->mAD;
499 ctx->mAD = NULL;
500 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800501
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400502 if(ctx->mQService) {
503 delete ctx->mQService;
504 ctx->mQService = NULL;
505 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700506}
507
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700508//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530509uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700510 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
511 uint32_t rate = refreshRate;
512 for(int i=0; i< count; i++) {
513 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
514 // Most likely used for video, the fps can fluctuate
515 // Ex: b/w 29 and 30 for 30 fps clip
516 rate = stdRefreshRates[i];
517 break;
518 }
519 }
520 return rate;
521}
522
523//Helper func to set the dyn fps
524void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
525 //Update only if different
526 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
527 return;
528 const int fbNum = Overlay::getFbForDpy(dpy);
529 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
530 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800531 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700532
533 int fd = open(sysfsPath, O_WRONLY);
534 if(fd >= 0) {
535 char str[64];
536 snprintf(str, sizeof(str), "%d", refreshRate);
537 ssize_t ret = write(fd, str, strlen(str));
538 if(ret < 0) {
539 ALOGE("%s: Failed to write %d with error %s",
540 __FUNCTION__, refreshRate, strerror(errno));
541 } else {
542 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
543 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
544 __FUNCTION__, refreshRate);
545 }
546 close(fd);
547 } else {
548 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
549 strerror(errno));
550 }
551}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500552
553void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700554{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500555 va_list varargs;
556 va_start(varargs, fmt);
557 buf.appendFormatV(fmt, varargs);
558 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700559}
560
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700561int getExtOrientation(hwc_context_t* ctx) {
562 int extOrient = ctx->mExtOrientation;
563 if(ctx->mBufferMirrorMode)
564 extOrient = getMirrorModeOrientation(ctx);
565 return extOrient;
566}
567
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800568/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700569void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
570 // Position
571 int x = rect.left, y = rect.top;
572 int w = rect.right - rect.left;
573 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800574
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800575 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800576 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800577 // Read action safe properties
578 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
579 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700580
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800581 float wRatio = 1.0;
582 float hRatio = 1.0;
583 float xRatio = 1.0;
584 float yRatio = 1.0;
585
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700586 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
587 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700588 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
589 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700590 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700591 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700592 }
593
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800594
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700595 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700596 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700597
598 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700599 swap(fbWidth, fbHeight);
600
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800601 float asX = 0;
602 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530603 float asW = (float)fbWidth;
604 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800605
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800606 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530607 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
608 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
609 asX = ((float)fbWidth - asW) / 2;
610 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800611
612 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530613 xRatio = (float)x/(float)fbWidth;
614 yRatio = (float)y/(float)fbHeight;
615 wRatio = (float)w/(float)fbWidth;
616 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800617
618 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530619 x = int((xRatio * asW) + asX);
620 y = int((yRatio * asH) + asY);
621 w = int(wRatio * asW);
622 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800623
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700624 // Convert it back to hwc_rect_t
625 rect.left = x;
626 rect.top = y;
627 rect.right = w + rect.left;
628 rect.bottom = h + rect.top;
629
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800630 return;
631}
632
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700633// This function gets the destination position for Seconday display
634// based on the position and aspect ratio with orientation
635void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
636 hwc_rect_t& inRect, hwc_rect_t& outRect) {
637 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530638 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
639 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700640 //display position(x,y,w,h) in correct aspectratio after rotation
641 int xPos = 0;
642 int yPos = 0;
643 float width = fbWidth;
644 float height = fbHeight;
645 // Width/Height used for calculation, after rotation
646 float actualWidth = fbWidth;
647 float actualHeight = fbHeight;
648
649 float wRatio = 1.0;
650 float hRatio = 1.0;
651 float xRatio = 1.0;
652 float yRatio = 1.0;
653 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
654
655 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
656 inRect.bottom - inRect.top);
657 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
658 outRect.bottom - outRect.top);
659
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530660 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700661 eTransform extorient = static_cast<eTransform>(extOrientation);
662 // To calculate the destination co-ordinates in the new orientation
663 preRotateSource(extorient, whf, inPos);
664
665 if(extOrientation & HAL_TRANSFORM_ROT_90) {
666 // Swap width/height for input position
667 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700668 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
669 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700670 xPos = rect.left;
671 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530672 width = float(rect.right - rect.left);
673 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700674 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700675 xRatio = (float)((float)inPos.x/actualWidth);
676 yRatio = (float)((float)inPos.y/actualHeight);
677 wRatio = (float)((float)inPos.w/actualWidth);
678 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800679
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530680 //Calculate the pos9ition...
681 outPos.x = uint32_t((xRatio * width) + (float)xPos);
682 outPos.y = uint32_t((yRatio * height) + (float)yPos);
683 outPos.w = uint32_t(wRatio * width);
684 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700685 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
686 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
687 outPos.w, outPos.h);
688
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700689 // For sidesync, the dest fb will be in portrait orientation, and the crop
690 // will be updated to avoid the black side bands, and it will be upscaled
691 // to fit the dest RB, so recalculate
692 // the position based on the new width and height
693 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
694 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800695 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700696 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530697 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700698 // GetaspectRatio -- tricky to get the correct aspect ratio
699 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700700 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530701 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700702 xPos = r.left;
703 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530704 float tempHeight = float(r.bottom - r.top);
705 yRatio = (float)yPos/height;
706 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700707 hRatio = tempHeight/height;
708
709 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530710 outPos.x = uint32_t(xRatio * fbWidth);
711 outPos.y = uint32_t(yRatio * fbHeight);
712 outPos.w = uint32_t(wRatio * fbWidth);
713 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700714
715 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
716 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
717 outPos.x, outPos.y,
718 outPos.w, outPos.h);
719 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700720 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700721 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700722 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700723 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700724 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
725 extW = ctx->mHWCVirtual->getScalingWidth();
726 extH = ctx->mHWCVirtual->getScalingHeight();
727 }
728 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
729 __FUNCTION__, extW, extH);
730
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530731 fbWidth = (float)ctx->dpyAttr[dpy].xres;
732 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700733 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530734 xRatio = (float)outPos.x/fbWidth;
735 yRatio = (float)outPos.y/fbHeight;
736 wRatio = (float)outPos.w/fbWidth;
737 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700738
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530739 outPos.x = uint32_t(xRatio * (float)extW);
740 outPos.y = uint32_t(yRatio * (float)extH);
741 outPos.w = uint32_t(wRatio * (float)extW);
742 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700743 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700744 // Convert Dim to hwc_rect_t
745 outRect.left = outPos.x;
746 outRect.top = outPos.y;
747 outRect.right = outPos.x + outPos.w;
748 outRect.bottom = outPos.y + outPos.h;
749
750 return;
751}
752
753bool isPrimaryPortrait(hwc_context_t *ctx) {
754 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
755 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
756 if(fbWidth < fbHeight) {
757 return true;
758 }
759 return false;
760}
761
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700762bool isOrientationPortrait(hwc_context_t *ctx) {
763 if(isPrimaryPortrait(ctx)) {
764 return !(ctx->deviceOrientation & 0x1);
765 }
766 return (ctx->deviceOrientation & 0x1);
767}
768
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700769void calcExtDisplayPosition(hwc_context_t *ctx,
770 private_handle_t *hnd,
771 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700772 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700773 hwc_rect_t& displayFrame,
774 int& transform,
775 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700776 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700777 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530778 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700779 if(!isYuvBuffer(hnd)) {
780 if(extOrient & HWC_TRANSFORM_ROT_90) {
781 int dstWidth = ctx->dpyAttr[dpy].xres;
782 int dstHeight = ctx->dpyAttr[dpy].yres;;
783 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
784 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
785 if(!isPrimaryPortrait(ctx)) {
786 swap(srcWidth, srcHeight);
787 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700788 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700789 srcHeight, displayFrame);
790 // Crop - this is needed, because for sidesync, the dest fb will
791 // be in portrait orientation, so update the crop to not show the
792 // black side bands.
793 if (isOrientationPortrait(ctx)) {
794 sourceCrop = displayFrame;
795 displayFrame.left = 0;
796 displayFrame.top = 0;
797 displayFrame.right = dstWidth;
798 displayFrame.bottom = dstHeight;
799 }
800 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700801 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700802 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700803 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700804 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530805 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
806 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700807 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700808 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700809 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700810 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
811 extW = ctx->mHWCVirtual->getScalingWidth();
812 extH = ctx->mHWCVirtual->getScalingHeight();
813 }
814 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
815 __FUNCTION__, extW, extH);
816
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700817 //Calculate the ratio...
818 float wRatio = ((float)extW)/fbWidth;
819 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700820
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700821 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530822 displayFrame.left = int(wRatio*(float)displayFrame.left);
823 displayFrame.top = int(hRatio*(float)displayFrame.top);
824 displayFrame.right = int(wRatio*(float)displayFrame.right);
825 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700826 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
827 " for MDPDownscale feature [%d %d %d %d]",
828 displayFrame.left, displayFrame.top,
829 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700830 }
831 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700832 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700833 getAspectRatioPosition(ctx, dpy, extOrient,
834 displayFrame, displayFrame);
835 }
836 }
837 // If there is a external orientation set, use that
838 if(extOrient) {
839 transform = extOrient;
840 orient = static_cast<ovutils::eTransform >(extOrient);
841 }
842 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
843 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700844 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700845}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700846
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700847/* Returns the orientation which needs to be set on External for
848 * SideSync/Buffer Mirrormode
849 */
850int getMirrorModeOrientation(hwc_context_t *ctx) {
851 int extOrientation = 0;
852 int deviceOrientation = ctx->deviceOrientation;
853 if(!isPrimaryPortrait(ctx))
854 deviceOrientation = (deviceOrientation + 1) % 4;
855 if (deviceOrientation == 0)
856 extOrientation = HWC_TRANSFORM_ROT_270;
857 else if (deviceOrientation == 1)//90
858 extOrientation = 0;
859 else if (deviceOrientation == 2)//180
860 extOrientation = HWC_TRANSFORM_ROT_90;
861 else if (deviceOrientation == 3)//270
862 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
863
864 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700865}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700866
Raj kamal59fea562014-04-01 16:52:19 +0530867/* Get External State names */
868const char* getExternalDisplayState(uint32_t external_state) {
869 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
870 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
871 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
872 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
873 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
874
875 if(external_state >= EXTERNAL_MAXSTATES) {
876 return "EXTERNAL_INVALID";
877 }
878
879 return externalStates[external_state];
880}
881
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530882bool isDownscaleRequired(hwc_layer_1_t const* layer) {
883 hwc_rect_t displayFrame = layer->displayFrame;
884 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
885 int dst_w, dst_h, src_w, src_h;
886 dst_w = displayFrame.right - displayFrame.left;
887 dst_h = displayFrame.bottom - displayFrame.top;
888 src_w = sourceCrop.right - sourceCrop.left;
889 src_h = sourceCrop.bottom - sourceCrop.top;
890
891 if(((src_w > dst_w) || (src_h > dst_h)))
892 return true;
893
894 return false;
895}
896bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500897 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500898 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700899 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500900
901 dst_w = displayFrame.right - displayFrame.left;
902 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500903 src_w = sourceCrop.right - sourceCrop.left;
904 src_h = sourceCrop.bottom - sourceCrop.top;
905
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800906 if(layer->transform & HWC_TRANSFORM_ROT_90)
907 swap(src_w, src_h);
908
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800909 if(((src_w != dst_w) || (src_h != dst_h)))
910 return true;
911
912 return false;
913}
914
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700915// Checks if layer needs scaling with split
916bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
917 const int& dpy) {
918
919 int src_width_l, src_height_l;
920 int src_width_r, src_height_r;
921 int dst_width_l, dst_height_l;
922 int dst_width_r, dst_height_r;
923 int hw_w = ctx->dpyAttr[dpy].xres;
924 int hw_h = ctx->dpyAttr[dpy].yres;
925 hwc_rect_t cropL, dstL, cropR, dstR;
926 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700927 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700928 hwc_rect_t displayFrame = layer->displayFrame;
929 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700930
931 cropL = sourceCrop;
932 dstL = displayFrame;
933 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800934 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700935 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
936
937 cropR = sourceCrop;
938 dstR = displayFrame;
939 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800940 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700941 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
942
943 // Sanitize Crop to stitch
944 sanitizeSourceCrop(cropL, cropR, hnd);
945
946 // Calculate the left dst
947 dst_width_l = dstL.right - dstL.left;
948 dst_height_l = dstL.bottom - dstL.top;
949 src_width_l = cropL.right - cropL.left;
950 src_height_l = cropL.bottom - cropL.top;
951
952 // check if there is any scaling on the left
953 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
954 return true;
955
956 // Calculate the right dst
957 dst_width_r = dstR.right - dstR.left;
958 dst_height_r = dstR.bottom - dstR.top;
959 src_width_r = cropR.right - cropR.left;
960 src_height_r = cropR.bottom - cropR.top;
961
962 // check if there is any scaling on the right
963 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
964 return true;
965
966 return false;
967}
968
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530969bool isAlphaScaled(hwc_layer_1_t const* layer) {
970 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530971 return true;
972 }
973 return false;
974}
975
976bool isAlphaPresent(hwc_layer_1_t const* layer) {
977 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400978 if(hnd) {
979 int format = hnd->format;
980 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530981 case HAL_PIXEL_FORMAT_RGBA_8888:
982 case HAL_PIXEL_FORMAT_BGRA_8888:
983 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500984 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530985 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400986 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500987 }
988 return false;
989}
990
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700991static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
992 hwc_rect_t& crop, hwc_rect_t& dst) {
993 int hw_w = ctx->dpyAttr[dpy].xres;
994 int hw_h = ctx->dpyAttr[dpy].yres;
995 if(dst.left < 0 || dst.top < 0 ||
996 dst.right > hw_w || dst.bottom > hw_h) {
997 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800998 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700999 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1000 }
1001}
1002
1003static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1004 const int& dpy) {
1005 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1006 hwc_layer_1_t *layer = &list->hwLayers[i];
1007 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001008 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1009 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001010 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001011 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001012 (hwc_rect_t&)crop,
1013 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301014 layer->sourceCropf.left = (float)crop.left;
1015 layer->sourceCropf.right = (float)crop.right;
1016 layer->sourceCropf.top = (float)crop.top;
1017 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001018 }
1019}
1020
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001021void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001022 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001023 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1024 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301025 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1026 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001027 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301028 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001029 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001030 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001031 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001032 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001033 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301034 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001035 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301036 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001037 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001038 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1039 uint32_t refreshRate = 0;
1040 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001041 int s3dFormat = HAL_NO_3D;
1042 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001043
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001044 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001045 resetROI(ctx, dpy);
1046
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001047 trimList(ctx, list, dpy);
1048 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001049 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001050 hwc_layer_1_t const* layer = &list->hwLayers[i];
1051 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001052
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001053#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001054 // Window boxing feature is applicable obly for external display, So
1055 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001056 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001057 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001058 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001059 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1060 ctx->listStats[dpy].isDisplayAnimating = true;
1061 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001062 if(isSecureDisplayBuffer(hnd)) {
1063 ctx->listStats[dpy].secureUI = true;
1064 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001065#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001066 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1067 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001068 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001069
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001070 //reset yuv indices
1071 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301072 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001073
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001074 if (isSecureBuffer(hnd)) {
1075 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001076 if(not isYuvBuffer(hnd)) {
1077 // cache secureRGB layer parameters like we cache for YUV layers
1078 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1079 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1080 secureRGBCount++;
1081 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001082 }
1083
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001084 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001085 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001086 }
1087
1088 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001089 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301090 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001091 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001092
Raj Kamal389d6e32014-08-04 14:43:24 +05301093 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301094 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301095 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301096 yuv4k2kCount++;
1097 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001098
1099 // Gets set if one YUV layer is 3D
1100 if (displaySupports3D(ctx,dpy)) {
1101 s3dFormat = get3DFormat(hnd);
1102 if(s3dFormat != HAL_NO_3D)
1103 s3dLayerCount++;
1104 }
1105
Naseer Ahmed29a26812012-06-14 00:56:20 -07001106 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301107 if(layer->blending == HWC_BLENDING_PREMULT)
1108 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001109
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001110#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301111 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001112 //dyn fps: get refreshrate from metadata
1113 //Support multiple refresh rates if they are same
1114 //else set to default
1115 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1116 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1117 // Valid refreshRate in metadata and within the range
1118 uint32_t rate = roundOff(mdata->refreshrate);
1119 if((rate >= mdpHw.getMinFpsSupported() &&
1120 rate <= mdpHw.getMaxFpsSupported())) {
1121 if (!refreshRate) {
1122 refreshRate = rate;
1123 } else if(refreshRate != rate) {
1124 // multiple refreshrate requests, set to default
1125 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1126 }
1127 }
1128 }
1129 }
1130#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001131 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001132
1133 //Set the TV's 3D mode based on format if it was not forced
1134 //Only one 3D YUV layer is supported on external
1135 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1136 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1137 //XXX: Rapidly going in and out of 3D mode in some cases such
1138 // as rotation might cause flickers. The OEMs are recommended to disable
1139 // rotation on HDMI globally or in the app that plays 3D video
1140 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1141 }
1142
Ping Li9404e2a2013-04-24 16:36:03 -04001143 if(ctx->listStats[dpy].yuvCount > 0) {
1144 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1145 if (atoi(property) != 1) {
1146 property_set("hw.cabl.yuv", "1");
1147 }
1148 }
1149 } else {
1150 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1151 if (atoi(property) != 0) {
1152 property_set("hw.cabl.yuv", "0");
1153 }
1154 }
1155 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001156
1157 //The marking of video begin/end is useful on some targets where we need
1158 //to have a padding round to be able to shift pipes across mixers.
1159 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1160 ctx->mVideoTransFlag = true;
1161 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301162
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001163 if(dpy == HWC_DISPLAY_PRIMARY) {
1164 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001165 //Store the requested fresh rate
1166 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1167 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001168 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001169}
1170
Naseer Ahmed018e5452012-12-03 14:46:15 -05001171
Saurabh Shah68107422013-07-09 11:12:42 -07001172static void calc_cut(double& leftCutRatio, double& topCutRatio,
1173 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001174 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001175 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001176 }
1177 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001178 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001179 }
1180 if(orient & HAL_TRANSFORM_ROT_90) {
1181 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001182 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001183 leftCutRatio = topCutRatio;
1184 topCutRatio = rightCutRatio;
1185 rightCutRatio = bottomCutRatio;
1186 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001187 }
1188}
1189
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001190bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001191 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1192 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1193 ctx->mSecuring) {
1194 return true;
1195 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001196 if (isSecureModePolicy(ctx->mMDP.version)) {
1197 private_handle_t *hnd = (private_handle_t *)layer->handle;
1198 if(ctx->mSecureMode) {
1199 if (! isSecureBuffer(hnd)) {
1200 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1201 __FUNCTION__);
1202 return true;
1203 }
1204 } else {
1205 if (isSecureBuffer(hnd)) {
1206 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1207 __FUNCTION__);
1208 return true;
1209 }
1210 }
1211 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001212 return false;
1213}
1214
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001215bool isSecureModePolicy(int mdpVersion) {
1216 if (mdpVersion < qdutils::MDSS_V5)
1217 return true;
1218 else
1219 return false;
1220}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001221
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001222bool isRotatorSupportedFormat(private_handle_t *hnd) {
1223 // Following rotator src formats are supported by mdp driver
1224 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001225 if(hnd != NULL) {
1226 switch(hnd->format) {
1227 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001228 case HAL_PIXEL_FORMAT_RGBA_5551:
1229 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001230 case HAL_PIXEL_FORMAT_RGB_565:
1231 case HAL_PIXEL_FORMAT_RGB_888:
1232 case HAL_PIXEL_FORMAT_BGRA_8888:
1233 return true;
1234 default:
1235 return false;
1236 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001237 }
1238 return false;
1239}
1240
1241bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001242 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001243 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001244 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001245 !ctx->mMDP.version < qdutils::MDSS_V5)
1246 || isYuvBuffer(hnd)) {
1247 return true;
1248 }
1249 return false;
1250}
1251
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001252// returns true if Action safe dimensions are set and target supports Actionsafe
1253bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1254 // if external supports underscan, do nothing
1255 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001256 // Disable Action safe for 8974 due to HW limitation for downscaling
1257 // layers with overlapped region
1258 // Disable Actionsafe for non HDMI displays.
1259 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1260 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001261 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001262 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001263 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001264
1265 char value[PROPERTY_VALUE_MAX];
1266 // Read action safe properties
1267 property_get("persist.sys.actionsafe.width", value, "0");
1268 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1269 property_get("persist.sys.actionsafe.height", value, "0");
1270 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1271
1272 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1273 //No action safe ratio set, return
1274 return false;
1275 }
1276 return true;
1277}
1278
Naseer Ahmed522ce662013-03-18 20:14:05 -04001279int getBlending(int blending) {
1280 switch(blending) {
1281 case HWC_BLENDING_NONE:
1282 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1283 case HWC_BLENDING_PREMULT:
1284 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1285 case HWC_BLENDING_COVERAGE :
1286 default:
1287 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1288 }
1289}
1290
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001291//Crops source buffer against destination and FB boundaries
1292void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001293 const hwc_rect_t& scissor, int orient) {
1294
Saurabh Shah27c1d652012-08-14 19:30:28 -07001295 int& crop_l = crop.left;
1296 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001297 int& crop_r = crop.right;
1298 int& crop_b = crop.bottom;
1299 int crop_w = crop.right - crop.left;
1300 int crop_h = crop.bottom - crop.top;
1301
Saurabh Shah27c1d652012-08-14 19:30:28 -07001302 int& dst_l = dst.left;
1303 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001304 int& dst_r = dst.right;
1305 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001306 int dst_w = abs(dst.right - dst.left);
1307 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001308
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001309 const int& sci_l = scissor.left;
1310 const int& sci_t = scissor.top;
1311 const int& sci_r = scissor.right;
1312 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001313
Saurabh Shah68107422013-07-09 11:12:42 -07001314 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1315 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001316
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001317 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001318 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001319 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001320 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001321
1322 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001323 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001324 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001325 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001326
1327 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001328 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001329 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001330 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001331
1332 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001333 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001334 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001335 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001336
Saurabh Shah541b59d2012-10-11 11:08:12 -07001337 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301338 crop_l += (int)round((double)crop_w * leftCutRatio);
1339 crop_t += (int)round((double)crop_h * topCutRatio);
1340 crop_r -= (int)round((double)crop_w * rightCutRatio);
1341 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001342}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001343
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301344bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1345 const hwc_layer_1_t* layer2) {
1346 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1347 layer2->displayFrame);
1348 return isValidRect(irect);
1349}
1350
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001351bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1352{
1353 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1354 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1355}
1356
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001357bool isValidRect(const hwc_rect& rect)
1358{
1359 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301360}
1361
Ramakant Singh21cec722014-03-07 19:11:45 +05301362bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1363 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1364 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1365 return true ;
1366 return false;
1367}
1368
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001369hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1370{
1371 hwc_rect_t res;
1372
1373 if(!isValidRect(rect))
1374 return (hwc_rect_t){0, 0, 0, 0};
1375
1376 res.left = rect.left + x_off;
1377 res.top = rect.top + y_off;
1378 res.right = rect.right + x_off;
1379 res.bottom = rect.bottom + y_off;
1380
1381 return res;
1382}
1383
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001384/* computes the intersection of two rects */
1385hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1386{
1387 hwc_rect_t res;
1388
1389 if(!isValidRect(rect1) || !isValidRect(rect2)){
1390 return (hwc_rect_t){0, 0, 0, 0};
1391 }
1392
1393
1394 res.left = max(rect1.left, rect2.left);
1395 res.top = max(rect1.top, rect2.top);
1396 res.right = min(rect1.right, rect2.right);
1397 res.bottom = min(rect1.bottom, rect2.bottom);
1398
1399 if(!isValidRect(res))
1400 return (hwc_rect_t){0, 0, 0, 0};
1401
1402 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301403}
1404
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001405/* computes the union of two rects */
1406hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1407{
1408 hwc_rect_t res;
1409
1410 if(!isValidRect(rect1)){
1411 return rect2;
1412 }
1413
1414 if(!isValidRect(rect2)){
1415 return rect1;
1416 }
1417
1418 res.left = min(rect1.left, rect2.left);
1419 res.top = min(rect1.top, rect2.top);
1420 res.right = max(rect1.right, rect2.right);
1421 res.bottom = max(rect1.bottom, rect2.bottom);
1422
1423 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301424}
1425
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001426/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1427 * a single rect */
1428hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301429
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001430 hwc_rect_t res = rect1;
1431
1432 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1433 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1434 res.top = rect2.bottom;
1435 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1436 res.bottom = rect2.top;
1437 }
1438 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1439 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1440 res.left = rect2.right;
1441 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1442 res.right = rect2.left;
1443 }
1444 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301445}
1446
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001447void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301448 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301449 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301450 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001451 //If it is opaque see if we can substract this region from below
1452 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301453 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1454 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301455 int j= i-1;
1456 hwc_rect_t& topframe =
1457 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1458 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301459 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001460 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1461 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001462 hwc_rect_t bottomCrop =
1463 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001464 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1465 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001466
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001467 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1468 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001469 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001470 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001471 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001472 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001473 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001474 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301475 layer->sourceCropf.left =(float)bottomCrop.left;
1476 layer->sourceCropf.top = (float)bottomCrop.top;
1477 layer->sourceCropf.right = (float)bottomCrop.right;
1478 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001479#ifdef QCOM_BSP
1480 //Update layer dirtyRect
1481 layer->dirtyRect = getIntersection(bottomCrop,
1482 layer->dirtyRect);
1483#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001484 }
1485 }
1486 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301487 }
1488 }
1489 i--;
1490 }
1491}
1492
Naseer Ahmed64b81212013-02-14 10:29:47 -05001493void getNonWormholeRegion(hwc_display_contents_1_t* list,
1494 hwc_rect_t& nwr)
1495{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301496 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001497 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1498 //Initiliaze nwr to first frame
1499 nwr.left = list->hwLayers[0].displayFrame.left;
1500 nwr.top = list->hwLayers[0].displayFrame.top;
1501 nwr.right = list->hwLayers[0].displayFrame.right;
1502 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1503
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301504 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001505 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001506 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001507 }
1508
1509 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001510 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001511}
1512
Saurabh Shah747af1e2013-02-26 10:25:12 -08001513void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001514 if(LIKELY(list)) {
1515 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1516 //Close the acquireFenceFds
1517 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1518 if(list->hwLayers[i].acquireFenceFd >= 0) {
1519 close(list->hwLayers[i].acquireFenceFd);
1520 list->hwLayers[i].acquireFenceFd = -1;
1521 }
1522 }
1523 //Writeback
1524 if(list->outbufAcquireFenceFd >= 0) {
1525 close(list->outbufAcquireFenceFd);
1526 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001527 }
1528 }
1529}
1530
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001531int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001532 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001533 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001534 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001535 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001536 int count = 0;
1537 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001538 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001539 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001540 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001541
1542 struct mdp_buf_sync data;
1543 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001544 data.acq_fen_fd = acquireFd;
1545 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001546 data.retire_fen_fd = &retireFd;
1547 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001548
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001549 char property[PROPERTY_VALUE_MAX];
1550 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1551 if(atoi(property) == 0)
1552 swapzero = true;
1553 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001554
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001555 bool isExtAnimating = false;
1556 if(dpy)
1557 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001558
Saurabh Shah23a813c2013-03-20 16:58:12 -07001559 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001560 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001561 int rotFd = ctx->mRotMgr->getRotDevFd();
1562 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001563 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1564 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1565 if((currRot == NULL) || (currLayer == NULL)) {
1566 continue;
1567 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001568 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001569 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001570 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001571 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001572 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001573 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001574 if(currLayer->acquireFenceFd >= 0) {
1575 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1576 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001577 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301578 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301579 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1580
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001581 if(ret < 0) {
1582 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1583 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001584 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001585 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001586 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001587 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001588 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001589 dup(rotReleaseFd);
1590 //A buffer is free to be used by producer as soon as its copied to
1591 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001592 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001593 rotReleaseFd;
1594 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001595 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001596
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301597 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001598 if(list->outbufAcquireFenceFd >= 0) {
1599 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301600 if(LIKELY(!swapzero) )
1601 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001602 }
1603
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001604 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301605 if(((isAbcInUse(ctx)== true ) ||
1606 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001607 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301608 if(LIKELY(!swapzero) ) {
1609 // if ABC is enabled for more than one layer.
1610 // renderBufIndexforABC will work as FB.Hence
1611 // set the acquireFD from fd - which is coming from copybit
1612 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1613 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1614 acquireFd[count++] = fd;
1615 else
1616 continue;
1617 } else
1618 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1619 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001620 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001621 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301622 if(LIKELY(!swapzero) ) {
1623 if(fd >= 0) {
1624 //set the acquireFD from fd - which is coming from c2d
1625 acquireFd[count++] = fd;
1626 // Buffer sync IOCTL should be async when using c2d fence is
1627 // used
1628 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1629 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1630 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1631 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001632 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001633 }
1634
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001635 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001636 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301637 if(LIKELY(!swapzero) )
1638 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001639 }
1640
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001641 data.acq_fen_fd_cnt = count;
1642 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001643
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001644 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001645 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001646 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001647 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001648
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001649 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001650 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1651 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301652 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001653 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1654 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001655 close(releaseFd);
1656 releaseFd = -1;
1657 close(retireFd);
1658 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001659 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001660
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001661 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001662 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001663#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001664 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001665#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001666 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001667 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001668 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001669 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001670 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001671 // Release all the app layer fds immediately,
1672 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001673 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001674 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001675#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001676 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301677 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301678
1679 // if ABC is enabled for more than one layer
1680 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1681 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1682 list->hwLayers[i].releaseFenceFd = dup(fd);
1683 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1684 (isAbcInUse(ctx) == false)){
1685 //For Blit, the app layers should be released when the Blit
1686 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301687 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001688 } else
1689#endif
1690 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301691 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1692 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001693 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001694 }
1695 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001696
1697 if(fd >= 0) {
1698 close(fd);
1699 fd = -1;
1700 }
1701
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001702 if (ctx->mCopyBit[dpy]) {
1703 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001704 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1705 else
1706 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1707 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001708
Saurabh Shah23a813c2013-03-20 16:58:12 -07001709 //Signals when MDP finishes reading rotator buffers.
1710 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001711 close(releaseFd);
1712 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001713
Arun Kumar K.R51835182013-11-19 11:20:28 -08001714 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001715 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001716 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001717 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001718 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001719 return ret;
1720}
1721
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001722void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001723 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001724 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001725 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001726 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001727
1728 if(layer->blending == HWC_BLENDING_PREMULT) {
1729 ovutils::setMdpFlags(mdpFlags,
1730 ovutils::OV_MDP_BLEND_FG_PREMULT);
1731 }
1732
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001733 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1734 metadata->interlaced) {
1735 ovutils::setMdpFlags(mdpFlags,
1736 ovutils::OV_MDP_DEINTERLACE);
1737 }
1738
1739 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1740 if(isSecureBuffer(hnd)) {
1741 ovutils::setMdpFlags(mdpFlags,
1742 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301743 ovutils::setMdpFlags(mdpFlags,
1744 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1745 }
1746
1747 if(isProtectedBuffer(hnd)) {
1748 ovutils::setMdpFlags(mdpFlags,
1749 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001750 }
1751
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001752 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001753 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001754 ovutils::setMdpFlags(mdpFlags,
1755 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1756 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001757
1758 //Pre-rotation will be used using rotator.
1759 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1760 ovutils::setMdpFlags(mdpFlags,
1761 ovutils::OV_MDP_SOURCE_ROTATED_90);
1762 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001763 //No 90 component and no rot-downscale then flips done by MDP
1764 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001765 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1766 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001767 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1768 }
1769
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001770 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001771 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1772 }
1773 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001774
1775 if(metadata &&
1776 ((metadata->operation & PP_PARAM_HSIC)
1777 || (metadata->operation & PP_PARAM_IGC)
1778 || (metadata->operation & PP_PARAM_SHARP2))) {
1779 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1780 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001781}
1782
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301783int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001784 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001785 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001786
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301787 // Fix alignments for TILED format
1788 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1789 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1790 whf.w = utils::alignup(whf.w, 64);
1791 whf.h = utils::alignup(whf.h, 32);
1792 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001793 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001794
1795 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1796 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001797 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1798 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001799 rot->setCrop(rotCrop);
1800 }
1801
Saurabh Shahacf10202013-02-26 10:15:15 -08001802 rot->setFlags(mdpFlags);
1803 rot->setTransform(orient);
1804 rot->setDownscale(downscale);
1805 if(!rot->commit()) return -1;
1806 return 0;
1807}
1808
Saurabh Shahe2474082013-05-15 16:32:13 -07001809int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001810 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001811 const hwc_rect_t& pos, const MetaData_t *metadata,
1812 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001813 ov->setSource(parg, dest);
1814 ov->setTransform(orient, dest);
1815
1816 int crop_w = crop.right - crop.left;
1817 int crop_h = crop.bottom - crop.top;
1818 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1819 ov->setCrop(dcrop, dest);
1820
1821 int posW = pos.right - pos.left;
1822 int posH = pos.bottom - pos.top;
1823 Dim position(pos.left, pos.top, posW, posH);
1824 ov->setPosition(position, dest);
1825
Saurabh Shah5daeee52013-01-23 16:52:26 +08001826 if (metadata)
1827 ov->setVisualParams(*metadata, dest);
1828
Saurabh Shahacf10202013-02-26 10:15:15 -08001829 if (!ov->commit(dest)) {
1830 return -1;
1831 }
1832 return 0;
1833}
1834
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001835int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1836 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001837 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001838
1839 hwc_rect_t dst = layer->displayFrame;
1840 trimLayer(ctx, dpy, 0, dst, dst);
1841
1842 int w = ctx->dpyAttr[dpy].xres;
1843 int h = ctx->dpyAttr[dpy].yres;
1844 int dst_w = dst.right - dst.left;
1845 int dst_h = dst.bottom - dst.top;
1846 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001847 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001848
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001849 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001850 if (layer->blending == HWC_BLENDING_PREMULT)
1851 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1852
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001853 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001854 layer->planeAlpha,
1855 (ovutils::eBlending) getBlending(layer->blending));
1856
1857 // Configure MDP pipe for Color layer
1858 Dim pos(dst.left, dst.top, dst_w, dst_h);
1859 ctx->mOverlay->setSource(parg, dest);
1860 ctx->mOverlay->setColor(color, dest);
1861 ctx->mOverlay->setTransform(0, dest);
1862 ctx->mOverlay->setCrop(pos, dest);
1863 ctx->mOverlay->setPosition(pos, dest);
1864
1865 if (!ctx->mOverlay->commit(dest)) {
1866 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1867 return -1;
1868 }
1869 return 0;
1870}
1871
Saurabh Shahe2474082013-05-15 16:32:13 -07001872void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001873 hwc_rect_t& crop, Rotator *rot) {
1874 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001875 crop.right - crop.left,
1876 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001877 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1878 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001879 //B-family rotator internally could modify destination dimensions if
1880 //downscaling is supported
1881 whf = rot->getDstWhf();
1882 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001883 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001884 //A-family rotator rotates entire buffer irrespective of crop, forcing
1885 //us to recompute the crop based on transform
1886 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1887 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001888 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001889
1890 crop.left = transformedCrop.x;
1891 crop.top = transformedCrop.y;
1892 crop.right = transformedCrop.x + transformedCrop.w;
1893 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001894}
1895
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001896int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1897 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1898 return 0;
1899 }
1900
1901 int downscale = 0;
1902 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1903 hwc_rect_t dst = layer->displayFrame;
1904 private_handle_t *hnd = (private_handle_t *)layer->handle;
1905
1906 if(not hnd) {
1907 return 0;
1908 }
1909
1910 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1911 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1912 && metadata->interlaced;
1913 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001914 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001915
1916 if(isYuvBuffer(hnd)) {
1917 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1918 ctx->mMDP.version < qdutils::MDSS_V5) {
1919 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1920 crop.bottom - crop.top, dst.right - dst.left,
1921 dst.bottom - dst.top, format, isInterlaced);
1922 } else {
1923 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1924 crop.bottom - crop.top);
1925 Dim pos(dst.left, dst.top, dst.right - dst.left,
1926 dst.bottom - dst.top);
1927 if(transform & HAL_TRANSFORM_ROT_90) {
1928 swap(adjCrop.w, adjCrop.h);
1929 }
1930 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1931 pos.h, format, isInterlaced);
1932 }
1933 }
1934 return downscale;
1935}
1936
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001937bool isZoomModeEnabled(hwc_rect_t crop) {
1938 // This does not work for zooming in top left corner of the image
1939 return(crop.top > 0 || crop.left > 0);
1940}
1941
1942void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1943 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1944 crop.left, crop.top, crop.right, crop.bottom);
1945 if(isZoomModeEnabled(crop)) {
1946 Dim srcCrop(crop.left, crop.top,
1947 crop.right - crop.left,
1948 crop.bottom - crop.top);
1949 int extW = ctx->dpyAttr[dpy].xres;
1950 int extH = ctx->dpyAttr[dpy].yres;
1951 //Crop the original video in order to fit external display aspect ratio
1952 if(srcCrop.w * extH < extW * srcCrop.h) {
1953 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1954 crop.top += offset;
1955 crop.bottom -= offset;
1956 } else {
1957 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1958 crop.left += offset;
1959 crop.right -= offset;
1960 }
1961 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1962 " source crop [%d %d %d %d]", extW, extH, dpy,
1963 crop.left, crop.top, crop.right, crop.bottom);
1964 }
1965}
1966
1967void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1968 hwc_rect_t& dst, int dpy) {
1969 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1970 dst.left, dst.top, dst.right, dst.bottom);
1971 Dim srcCrop(crop.left, crop.top,
1972 crop.right - crop.left,
1973 crop.bottom - crop.top);
1974 int extW = ctx->dpyAttr[dpy].xres;
1975 int extH = ctx->dpyAttr[dpy].yres;
1976 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07001977 // when zoom in mode is enabled or the ratio between video aspect ratio
1978 // and external display aspect ratio is below the minimum tolerance level
1979 // and above maximum tolerance level
1980 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
1981 float extDisplayAspectRatio = ((float)extW / (float)extH);
1982 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
1983 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
1984 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001985 dst.left = 0;
1986 dst.top = 0;
1987 dst.right = extW;
1988 dst.bottom = extH;
1989 }
1990 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1991 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
1992 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
1993 crop.left, crop.top, crop.right, crop.bottom);
1994}
1995
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001996void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001997 hwc_rect_t& dst, int dpy) {
1998 updateCropAIVVideoMode(ctx, crop, dpy);
1999 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2000}
2001
Saurabh Shah88e4d272013-09-03 13:31:29 -07002002int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002003 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002004 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002005
2006 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002007
Saurabh Shahacf10202013-02-26 10:15:15 -08002008 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002009 if (layer->flags & HWC_COLOR_FILL) {
2010 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002011 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002012 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002013 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2014 return -1;
2015 }
2016
Saurabh Shah5daeee52013-01-23 16:52:26 +08002017 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2018
Saurabh Shah62e1d732013-09-17 10:44:05 -07002019 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002020 hwc_rect_t dst = layer->displayFrame;
2021 int transform = layer->transform;
2022 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002023 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002024 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302025 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002026
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002027 // Handle R/B swap
2028 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2029 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2030 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2031 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2032 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2033 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002034 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002035 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2036 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002037 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002038 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002039 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002040 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002041
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002042 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002043 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002044 *rot = ctx->mRotMgr->getNext();
2045 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002046 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002047 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2048 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002049 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002050 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2051 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002052 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002053 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002054 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002055 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002056 }
2057
Saurabh Shah76fd6552013-03-14 14:45:38 -07002058 //For the mdp, since either we are pre-rotating or MDP does flips
2059 orient = OVERLAY_TRANSFORM_0;
2060 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002061 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002062 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2063 (ovutils::eBlending) getBlending(layer->blending));
2064
Saurabh Shah5daeee52013-01-23 16:52:26 +08002065 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002066 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2067 return -1;
2068 }
2069 return 0;
2070}
2071
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002072//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002073void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002074 private_handle_t *hnd) {
2075 if(cropL.right - cropL.left) {
2076 if(isYuvBuffer(hnd)) {
2077 //Always safe to even down left
2078 ovutils::even_floor(cropL.left);
2079 //If right is even, automatically width is even, since left is
2080 //already even
2081 ovutils::even_floor(cropL.right);
2082 }
2083 //Make sure there are no gaps between left and right splits if the layer
2084 //is spread across BOTH halves
2085 if(cropR.right - cropR.left) {
2086 cropR.left = cropL.right;
2087 }
2088 }
2089
2090 if(cropR.right - cropR.left) {
2091 if(isYuvBuffer(hnd)) {
2092 //Always safe to even down left
2093 ovutils::even_floor(cropR.left);
2094 //If right is even, automatically width is even, since left is
2095 //already even
2096 ovutils::even_floor(cropR.right);
2097 }
2098 }
2099}
2100
Saurabh Shah88e4d272013-09-03 13:31:29 -07002101int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002102 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002103 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002104 Rotator **rot) {
2105 private_handle_t *hnd = (private_handle_t *)layer->handle;
2106 if(!hnd) {
2107 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2108 return -1;
2109 }
2110
Saurabh Shah5daeee52013-01-23 16:52:26 +08002111 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2112
Saurabh Shahacf10202013-02-26 10:15:15 -08002113 int hw_w = ctx->dpyAttr[dpy].xres;
2114 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002115 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002116 hwc_rect_t dst = layer->displayFrame;
2117 int transform = layer->transform;
2118 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002119 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002120 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302121 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002122
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002123 // Handle R/B swap
2124 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2125 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2126 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2127 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2128 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2129 }
2130
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002131 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002132 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2133 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002134 }
2135
2136 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002137 ActionSafe, and extorientation features. */
2138 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002139 int downscale = getRotDownscale(ctx, layer);
2140 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002141
2142 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2143 //Enable overfetch
2144 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2145 }
2146
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002147 //Will do something only if feature enabled and conditions suitable
2148 //hollow call otherwise
2149 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2150 overlay::Writeback *wb = overlay::Writeback::getInstance();
2151 whf.format = wb->getOutputFormat();
2152 }
2153
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002154 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002155 (*rot) = ctx->mRotMgr->getNext();
2156 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002157 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002158 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002159 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2160 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002161 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002162 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002163 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002164 rotFlags |= ROT_PREROTATED;
2165 }
2166
2167 eMdpFlags mdpFlagsR = mdpFlagsL;
2168 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2169
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002170 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2171 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002172
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002173 const int lSplit = getLeftSplit(ctx, dpy);
2174
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002175 // Calculate Left rects
2176 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002177 tmp_cropL = crop;
2178 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002179 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002180 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002181 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2182 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002183
2184 // Calculate Right rects
2185 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002186 tmp_cropR = crop;
2187 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002188 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002189 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002190 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2191 }
2192
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002193 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2194
Saurabh Shah94d62362013-07-02 10:58:48 -07002195 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002196 //Not needed if the layer is confined to one half of the screen.
2197 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002198 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2199 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002200 hwc_rect_t new_cropR;
2201 new_cropR.left = tmp_cropL.left;
2202 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2203
2204 hwc_rect_t new_cropL;
2205 new_cropL.left = new_cropR.right;
2206 new_cropL.right = tmp_cropR.right;
2207
2208 tmp_cropL.left = new_cropL.left;
2209 tmp_cropL.right = new_cropL.right;
2210
2211 tmp_cropR.left = new_cropR.left;
2212 tmp_cropR.right = new_cropR.right;
2213
2214 }
2215
Saurabh Shah76fd6552013-03-14 14:45:38 -07002216 //For the mdp, since either we are pre-rotating or MDP does flips
2217 orient = OVERLAY_TRANSFORM_0;
2218 transform = 0;
2219
Saurabh Shahacf10202013-02-26 10:15:15 -08002220 //configure left mixer
2221 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002222 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002223 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2224 (ovutils::eBlending) getBlending(layer->blending));
2225
Saurabh Shahacf10202013-02-26 10:15:15 -08002226 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002227 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002228 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2229 return -1;
2230 }
2231 }
2232
2233 //configure right mixer
2234 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002235 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002236 static_cast<eRotFlags>(rotFlags),
2237 layer->planeAlpha,
2238 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002239 tmp_dstR.right = tmp_dstR.right - lSplit;
2240 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002241 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002242 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002243 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2244 return -1;
2245 }
2246 }
2247
2248 return 0;
2249}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002250
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002251int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2252 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2253 const eDest& lDest, const eDest& rDest,
2254 Rotator **rot) {
2255 private_handle_t *hnd = (private_handle_t *)layer->handle;
2256 if(!hnd) {
2257 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2258 return -1;
2259 }
2260 //Both pipes are configured to the same mixer
2261 eZorder lz = z;
2262 eZorder rz = (eZorder)(z + 1);
2263
2264 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2265
2266 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2267 hwc_rect_t dst = layer->displayFrame;
2268 int transform = layer->transform;
2269 eTransform orient = static_cast<eTransform>(transform);
2270 int rotFlags = ROT_FLAGS_NONE;
2271 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2272 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2273
2274 int downscale = getRotDownscale(ctx, layer);
2275 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2276
2277 //XXX: Check if rotation is supported and valid for 3D
2278 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2279 (*rot) = ctx->mRotMgr->getNext();
2280 if((*rot) == NULL) return -1;
2281 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2282 //Configure rotator for pre-rotation
2283 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2284 ALOGE("%s: configRotator failed!", __FUNCTION__);
2285 return -1;
2286 }
2287 updateSource(orient, whf, crop, *rot);
2288 rotFlags |= ROT_PREROTATED;
2289 }
2290
2291 eMdpFlags mdpFlagsR = mdpFlagsL;
2292
2293 hwc_rect_t cropL = crop, dstL = dst;
2294 hwc_rect_t cropR = crop, dstR = dst;
2295 int hw_w = ctx->dpyAttr[dpy].xres;
2296 int hw_h = ctx->dpyAttr[dpy].yres;
2297
2298 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2299 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2300 // Calculate Left rects
2301 // XXX: This assumes crop.right/2 is the center point of the video
2302 cropL.right = crop.right/2;
2303 dstL.left = dst.left/2;
2304 dstL.right = dst.right/2;
2305
2306 // Calculate Right rects
2307 cropR.left = crop.right/2;
2308 dstR.left = hw_w/2 + dst.left/2;
2309 dstR.right = hw_w/2 + dst.right/2;
2310 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2311 // Calculate Left rects
2312 cropL.bottom = crop.bottom/2;
2313 dstL.top = dst.top/2;
2314 dstL.bottom = dst.bottom/2;
2315
2316 // Calculate Right rects
2317 cropR.top = crop.bottom/2;
2318 dstR.top = hw_h/2 + dst.top/2;
2319 dstR.bottom = hw_h/2 + dst.bottom/2;
2320 } else {
2321 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2322 return -1;
2323 }
2324
2325 //For the mdp, since either we are pre-rotating or MDP does flips
2326 orient = OVERLAY_TRANSFORM_0;
2327 transform = 0;
2328
2329 //configure left pipe
2330 if(lDest != OV_INVALID) {
2331 PipeArgs pargL(mdpFlagsL, whf, lz,
2332 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2333 (ovutils::eBlending) getBlending(layer->blending));
2334
2335 if(configMdp(ctx->mOverlay, pargL, orient,
2336 cropL, dstL, metadata, lDest) < 0) {
2337 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2338 return -1;
2339 }
2340 }
2341
2342 //configure right pipe
2343 if(rDest != OV_INVALID) {
2344 PipeArgs pargR(mdpFlagsR, whf, rz,
2345 static_cast<eRotFlags>(rotFlags),
2346 layer->planeAlpha,
2347 (ovutils::eBlending) getBlending(layer->blending));
2348 if(configMdp(ctx->mOverlay, pargR, orient,
2349 cropR, dstR, metadata, rDest) < 0) {
2350 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2351 return -1;
2352 }
2353 }
2354
2355 return 0;
2356}
2357
radhakrishnac9a67412013-09-25 17:40:42 +05302358int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2359 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002360 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302361 Rotator **rot) {
2362 private_handle_t *hnd = (private_handle_t *)layer->handle;
2363 if(!hnd) {
2364 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2365 return -1;
2366 }
2367
2368 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2369
radhakrishnac9a67412013-09-25 17:40:42 +05302370 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2371 hwc_rect_t dst = layer->displayFrame;
2372 int transform = layer->transform;
2373 eTransform orient = static_cast<eTransform>(transform);
2374 const int downscale = 0;
2375 int rotFlags = ROT_FLAGS_NONE;
2376 //Splitting only YUV layer on primary panel needs different zorders
2377 //for both layers as both the layers are configured to single mixer
2378 eZorder lz = z;
2379 eZorder rz = (eZorder)(z + 1);
2380
2381 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302382 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302383
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002384 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002385 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2386 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002387 }
2388
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002389 /* Calculate the external display position based on MDP downscale,
2390 ActionSafe, and extorientation features. */
2391 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2392
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002393 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302394 trimLayer(ctx, dpy, transform, crop, dst);
2395
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002396 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302397 (*rot) = ctx->mRotMgr->getNext();
2398 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002399 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302400 //Configure rotator for pre-rotation
2401 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2402 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302403 return -1;
2404 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002405 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302406 rotFlags |= ROT_PREROTATED;
2407 }
2408
2409 eMdpFlags mdpFlagsR = mdpFlagsL;
2410 int lSplit = dst.left + (dst.right - dst.left)/2;
2411
2412 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2413 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2414
2415 if(lDest != OV_INVALID) {
2416 tmp_cropL = crop;
2417 tmp_dstL = dst;
2418 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2419 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2420 }
2421 if(rDest != OV_INVALID) {
2422 tmp_cropR = crop;
2423 tmp_dstR = dst;
2424 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2425 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2426 }
2427
2428 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2429
2430 //When buffer is H-flipped, contents of mixer config also needs to swapped
2431 //Not needed if the layer is confined to one half of the screen.
2432 //If rotator has been used then it has also done the flips, so ignore them.
2433 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2434 && rDest != OV_INVALID && (*rot) == NULL) {
2435 hwc_rect_t new_cropR;
2436 new_cropR.left = tmp_cropL.left;
2437 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2438
2439 hwc_rect_t new_cropL;
2440 new_cropL.left = new_cropR.right;
2441 new_cropL.right = tmp_cropR.right;
2442
2443 tmp_cropL.left = new_cropL.left;
2444 tmp_cropL.right = new_cropL.right;
2445
2446 tmp_cropR.left = new_cropR.left;
2447 tmp_cropR.right = new_cropR.right;
2448
2449 }
2450
2451 //For the mdp, since either we are pre-rotating or MDP does flips
2452 orient = OVERLAY_TRANSFORM_0;
2453 transform = 0;
2454
2455 //configure left half
2456 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002457 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302458 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2459 (ovutils::eBlending) getBlending(layer->blending));
2460
2461 if(configMdp(ctx->mOverlay, pargL, orient,
2462 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2463 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2464 return -1;
2465 }
2466 }
2467
2468 //configure right half
2469 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002470 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302471 static_cast<eRotFlags>(rotFlags),
2472 layer->planeAlpha,
2473 (ovutils::eBlending) getBlending(layer->blending));
2474 if(configMdp(ctx->mOverlay, pargR, orient,
2475 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2476 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2477 return -1;
2478 }
2479 }
2480
2481 return 0;
2482}
2483
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002484bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302485 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002486 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002487 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302488 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302489 * in LINE and BLOCK modes for writeback panels.
2490 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002491 if(dpy == HWC_DISPLAY_PRIMARY)
2492 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002493 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302494 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2495 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002496 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002497 return true;
2498}
2499
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002500int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2501 //Default even split for all displays with high res
2502 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2503 if(dpy == HWC_DISPLAY_PRIMARY &&
2504 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2505 //Override if split published by driver for primary
2506 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2507 }
2508 return lSplit;
2509}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002510
Saurabh Shah88e4d272013-09-03 13:31:29 -07002511bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302512 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002513 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002514 return true;
2515 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302516 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002517 return true;
2518 }
2519 return false;
2520}
2521
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002522//clear prev layer prop flags and realloc for current frame
2523void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2524 if(ctx->layerProp[dpy]) {
2525 delete[] ctx->layerProp[dpy];
2526 ctx->layerProp[dpy] = NULL;
2527 }
2528 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2529}
2530
Ramakant Singh0def28c2014-03-28 20:43:13 +05302531bool isAbcInUse(hwc_context_t *ctx){
2532 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2533}
2534
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002535void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2536 if (ohnd != NULL && ohnd->base) {
2537 char dumpFilename[PATH_MAX];
2538 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002539 int width = getWidth(ohnd);
2540 int height = getHeight(ohnd);
2541 int format = ohnd->format;
2542 //dummy aligned w & h.
2543 int alW = 0, alH = 0;
2544 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002545 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2546 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002547 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2548 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002549 FILE* fp = fopen(dumpFilename, "w+");
2550 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002551 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002552 fclose(fp);
2553 }
2554 ALOGD("Buffer[%s] Dump to %s: %s",
2555 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2556 }
2557}
2558
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002559bool isGLESComp(hwc_context_t *ctx,
2560 hwc_display_contents_1_t* list) {
2561 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2562 for(int index = 0; index < numAppLayers; index++) {
2563 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2564 if(layer->compositionType == HWC_FRAMEBUFFER)
2565 return true;
2566 }
2567 return false;
2568}
2569
2570void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2571 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002572 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002573 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002574
2575#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002576 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2577 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2578 hint to default if the previous composition is GPU or current GPU
2579 composition is due to idle fallback */
2580 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2581 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2582 if(!gpuHint->mEGLDisplay) {
2583 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2584 return;
2585 }
2586 gpuHint->mEGLContext = eglGetCurrentContext();
2587 if(!gpuHint->mEGLContext) {
2588 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2589 return;
2590 }
2591 }
2592 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002593 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2594 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002595 EGLint attr_list[] = {EGL_GPU_HINT_1,
2596 EGL_GPU_LEVEL_3,
2597 EGL_NONE };
2598 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2599 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2600 gpuHint->mEGLContext, attr_list)) {
2601 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2602 } else {
2603 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002604 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002605 }
2606 } else {
2607 EGLint attr_list[] = {EGL_GPU_HINT_1,
2608 EGL_GPU_LEVEL_0,
2609 EGL_NONE };
2610 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2611 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2612 gpuHint->mEGLContext, attr_list)) {
2613 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2614 } else {
2615 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2616 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002617 if(MDPComp::isIdleFallback()) {
2618 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2619 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002620 }
2621 } else {
2622 /* set the GPU hint flag to default for MDP composition */
2623 EGLint attr_list[] = {EGL_GPU_HINT_1,
2624 EGL_GPU_LEVEL_0,
2625 EGL_NONE };
2626 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2627 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2628 gpuHint->mEGLContext, attr_list)) {
2629 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2630 } else {
2631 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2632 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002633 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002634 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002635#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002636}
2637
Sushil Chauhandefd3522014-05-13 18:17:12 -07002638bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2639 // To be peripheral, 3 boundaries should match.
2640 uint8_t eqBounds = 0;
2641 if (rect1.left == rect2.left)
2642 eqBounds++;
2643 if (rect1.top == rect2.top)
2644 eqBounds++;
2645 if (rect1.right == rect2.right)
2646 eqBounds++;
2647 if (rect1.bottom == rect2.bottom)
2648 eqBounds++;
2649 return (eqBounds == 3);
2650}
2651
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302652void processBootAnimCompleted(hwc_context_t *ctx) {
2653 char value[PROPERTY_VALUE_MAX];
2654 int boot_finished = 0, ret = -1;
2655 int (*applyMode)(int) = NULL;
2656 void *modeHandle = NULL;
2657
2658 // Reading property set on boot finish in SF
2659 property_get("service.bootanim.exit", value, "0");
2660 boot_finished = atoi(value);
2661 if (!boot_finished)
2662 return;
2663
2664 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2665 if (modeHandle) {
2666 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2667 if (applyMode) {
2668 ret = applyMode(HWC_DISPLAY_PRIMARY);
2669 if (ret)
2670 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2671 } else {
2672 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2673 }
2674 dlclose(modeHandle);
2675 } else {
2676 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
2677 }
2678
2679 ctx->mBootAnimCompleted = true;
2680}
2681
Saurabh Shahcd018352014-11-11 13:54:19 -08002682void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2683 const private_handle_t *hnd,
2684 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002685 const int& transform,const int& downscale,
2686 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002687 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302688 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002689 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002690 return;
2691 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002692 //Disabled at runtime
2693 if(not ctx->mBWCEnabled) return;
2694 //BWC not supported with rot-downscale
2695 if(downscale) return;
2696 //Not enabled for secondary displays
2697 if(dpy) return;
2698 //Not enabled for non-video buffers
2699 if(not isYuvBuffer(hnd)) return;
2700
Saurabh Shahb6810df2014-06-17 16:00:22 -07002701 int src_w = crop.right - crop.left;
2702 int src_h = crop.bottom - crop.top;
2703 int dst_w = dst.right - dst.left;
2704 int dst_h = dst.bottom - dst.top;
2705 if(transform & HAL_TRANSFORM_ROT_90) {
2706 swap(src_w, src_h);
2707 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002708 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002709 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002710 return;
2711 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002712 //Decimation necessary, cannot use BWC. H/W requirement.
2713 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002714 uint8_t horzDeci = 0;
2715 uint8_t vertDeci = 0;
2716 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2717 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002718 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002719 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002720
2721 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2722}
2723
Saurabh Shah23a813c2013-03-20 16:58:12 -07002724void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302725 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002726 mLayer[mCount] = layer;
2727 mRot[mCount] = rot;
2728 mCount++;
2729}
2730
2731void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302732 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002733 mLayer[i] = 0;
2734 mRot[i] = 0;
2735 }
2736 mCount = 0;
2737}
2738
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002739void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002740 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002741 reset();
2742}
2743
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302744bool LayerRotMap::isRotCached(uint32_t index) const {
2745 overlay::Rotator* rot = getRot(index);
2746 hwc_layer_1_t* layer = getLayer(index);
2747
2748 if(rot and layer and layer->handle) {
2749 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2750 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2751 }
2752 return false;
2753}
2754
Saurabh Shah23a813c2013-03-20 16:58:12 -07002755void LayerRotMap::setReleaseFd(const int& fence) {
2756 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302757 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2758 /* Ensure that none of the above (Rotator-instance,
2759 * layer and layer-handle) are NULL*/
2760 if(isRotCached(i))
2761 mRot[i]->setPrevBufReleaseFd(dup(fence));
2762 else
2763 mRot[i]->setCurrBufReleaseFd(dup(fence));
2764 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002765 }
2766}
2767
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002768hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2769 int lRoiWidth = 0, rRoiWidth = 0;
2770 int half_frame_width = fullFrame.right/2;
2771
2772 hwc_rect lFrame = fullFrame;
2773 hwc_rect rFrame = fullFrame;
2774 lFrame.right = (lFrame.right - lFrame.left)/2;
2775 rFrame.left = lFrame.right;
2776
2777 hwc_rect lRoi = getIntersection(roi, lFrame);
2778 hwc_rect rRoi = getIntersection(roi, rFrame);
2779
2780 lRoiWidth = lRoi.right - lRoi.left;
2781 rRoiWidth = rRoi.right - rRoi.left;
2782
2783 if(lRoiWidth && rRoiWidth) {
2784 if(lRoiWidth < rRoiWidth)
2785 roi.left = half_frame_width - rRoiWidth;
2786 else
2787 roi.right = half_frame_width + lRoiWidth;
2788 }
2789 return roi;
2790}
2791
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002792void resetROI(hwc_context_t *ctx, const int dpy) {
2793 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2794 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002795
2796 /* When source split is enabled, both the panels are calibrated
2797 * in a single coordinate system. So only one ROI is generated
2798 * for the whole panel extending equally from the midpoint and
2799 * populated for the left side. */
2800 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2801 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002802 const int lSplit = getLeftSplit(ctx, dpy);
2803 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2804 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2805 } else {
2806 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2807 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2808 }
2809}
2810
2811hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002812{
2813 if(!isValidRect(roi))
2814 return roi;
2815
2816 struct hwc_rect t_roi = roi;
2817
2818 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2819 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2820 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2821 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2822 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002823 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002824
2825 /* Align to minimum width recommended by the panel */
2826 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2827 if((t_roi.left + MIN_WIDTH) > boundary.right)
2828 t_roi.left = t_roi.right - MIN_WIDTH;
2829 else
2830 t_roi.right = t_roi.left + MIN_WIDTH;
2831 }
2832
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002833 /* Align to minimum height recommended by the panel */
2834 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2835 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2836 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2837 else
2838 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2839 }
2840
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002841 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002842 if(LEFT_ALIGN)
2843 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2844
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002845 if(WIDTH_ALIGN) {
2846 int width = t_roi.right - t_roi.left;
2847 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2848 t_roi.right = t_roi.left + width;
2849
2850 if(t_roi.right > boundary.right) {
2851 t_roi.right = boundary.right;
2852 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002853
2854 if(LEFT_ALIGN)
2855 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002856 }
2857 }
2858
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002859
2860 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002861 if(TOP_ALIGN)
2862 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2863
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002864 if(HEIGHT_ALIGN) {
2865 int height = t_roi.bottom - t_roi.top;
2866 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2867 t_roi.bottom = t_roi.top + height;
2868
2869 if(t_roi.bottom > boundary.bottom) {
2870 t_roi.bottom = boundary.bottom;
2871 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002872
2873 if(TOP_ALIGN)
2874 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002875 }
2876 }
2877
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002878
2879 return t_roi;
2880}
2881
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002882void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002883 if(ctx->dpyAttr[dpy].connected) {
2884 ctx->mDrawLock.lock();
2885 ctx->dpyAttr[dpy].isActive = true;
2886 ctx->dpyAttr[dpy].isPause = true;
2887 ctx->mDrawLock.unlock();
2888 ctx->proc->invalidate(ctx->proc);
2889
2890 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2891 * 2 / 1000);
2892
2893 // At this point all the pipes used by External have been
2894 // marked as UNSET.
2895 ctx->mDrawLock.lock();
2896 // Perform commit to unstage the pipes.
2897 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2898 ALOGE("%s: display commit fail! for %d dpy",
2899 __FUNCTION__, dpy);
2900 }
2901 ctx->mDrawLock.unlock();
2902 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002903 }
2904 return;
2905}
2906
2907void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002908 if(ctx->dpyAttr[dpy].connected) {
2909 ctx->mDrawLock.lock();
2910 ctx->dpyAttr[dpy].isConfiguring = true;
2911 ctx->dpyAttr[dpy].isActive = true;
2912 ctx->mDrawLock.unlock();
2913 ctx->proc->invalidate(ctx->proc);
2914
2915 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2916 * 2 / 1000);
2917
2918 //At this point external has all the pipes it would need.
2919 ctx->mDrawLock.lock();
2920 ctx->dpyAttr[dpy].isPause = false;
2921 ctx->mDrawLock.unlock();
2922 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002923 }
2924 return;
2925}
2926
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002927void clearPipeResources(hwc_context_t* ctx, int dpy) {
2928 if(ctx->mOverlay) {
2929 ctx->mOverlay->configBegin();
2930 ctx->mOverlay->configDone();
2931 }
2932 if(ctx->mRotMgr) {
2933 ctx->mRotMgr->clear();
2934 }
2935 // Call a display commit to ensure that pipes and associated
2936 // fd's are cleaned up.
2937 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2938 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2939 }
2940}
2941
2942// Handles online events when HDMI is the primary display. In particular,
2943// online events for hdmi connected before AND after boot up and HWC init.
2944void handle_online(hwc_context_t* ctx, int dpy) {
2945 // Close the current fd if it was opened earlier on when HWC
2946 // was initialized.
2947 if (ctx->dpyAttr[dpy].fd >= 0) {
2948 close(ctx->dpyAttr[dpy].fd);
2949 ctx->dpyAttr[dpy].fd = -1;
2950 }
2951 // TODO: If HDMI is connected after the display has booted up,
2952 // and the best configuration is different from the default
2953 // then we need to deal with this appropriately.
Arun Kumar K.R205df772015-02-20 18:45:58 -08002954 int error = ctx->mHDMIDisplay->configure();
2955 if (error < 0) {
2956 ALOGE("Error opening FrameBuffer");
2957 return;
2958 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002959 updateDisplayInfo(ctx, dpy);
2960 initCompositionResources(ctx, dpy);
2961 ctx->dpyAttr[dpy].connected = true;
2962}
2963
2964// Handles offline events for HDMI. This can be used for offline events
2965// initiated by the HDMI driver and the CEC framework.
2966void handle_offline(hwc_context_t* ctx, int dpy) {
2967 destroyCompositionResources(ctx, dpy);
2968 // Clear all pipe resources and call a display commit to ensure
2969 // that all the fd's are closed. This will ensure that the HDMI
2970 // core turns off and that we receive an event the next time the
2971 // cable is connected.
2972 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
2973 clearPipeResources(ctx, dpy);
2974 }
2975 ctx->mHDMIDisplay->teardown();
2976 resetDisplayInfo(ctx, dpy);
2977 ctx->dpyAttr[dpy].connected = false;
2978 ctx->dpyAttr[dpy].isActive = false;
2979}
2980
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002981int convertS3DFormatToMode(int s3DFormat) {
2982 int ret;
2983 switch(s3DFormat) {
2984 case HAL_3D_SIDE_BY_SIDE_L_R:
2985 case HAL_3D_SIDE_BY_SIDE_R_L:
2986 ret = HDMI_S3D_SIDE_BY_SIDE;
2987 break;
2988 case HAL_3D_TOP_BOTTOM:
2989 ret = HDMI_S3D_TOP_AND_BOTTOM;
2990 break;
2991 default:
2992 ret = HDMI_S3D_NONE;
2993 }
2994 return ret;
2995}
2996
2997bool needs3DComposition(hwc_context_t* ctx, int dpy) {
2998 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
2999 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3000}
3001
3002void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3003 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3004 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3005 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3006 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3007 }
3008 }
3009}
3010
3011bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3012 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3013 ((dpy == HWC_DISPLAY_PRIMARY) &&
3014 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3015}
3016
3017
Saurabh Shahacf10202013-02-26 10:15:15 -08003018};//namespace qhwc