blob: 2d4363e86c9e06b31dcf24a417a08158cc5b8f0f [file] [log] [blame]
Naseer Ahmed29a26812012-06-14 00:56:20 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Zohaib Alamc9d00cd2014-01-24 16:38:32 -05003 * Copyright (C) 2012-2014, The Linux Foundation All rights reserved.
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08004 *
5 * Not a Contribution, Apache license notifications and license are retained
6 * for attribution purposes only.
Naseer Ahmed29a26812012-06-14 00:56:20 -07007 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
Naseer Ahmed099a6932013-09-09 14:25:20 -040020#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080021#define HWC_UTILS_DEBUG 0
Saurabh Shahc5b96dc2013-06-05 13:19:52 -070022#include <math.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050023#include <sys/ioctl.h>
Naseer Ahmed66e97882013-03-19 20:42:11 -040024#include <linux/fb.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080025#include <binder/IServiceManager.h>
Naseer Ahmed5b6708a2012-08-02 13:46:08 -070026#include <EGL/egl.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070027#include <cutils/properties.h>
Naseer Ahmed099a6932013-09-09 14:25:20 -040028#include <utils/Trace.h>
Saurabh Shahfc2acbe2012-08-17 19:47:52 -070029#include <gralloc_priv.h>
Naseer Ahmed758bfc52012-11-28 17:02:08 -050030#include <overlay.h>
Saurabh Shahacf10202013-02-26 10:15:15 -080031#include <overlayRotator.h>
Saurabh Shaha9da08f2013-07-03 13:27:53 -070032#include <overlayWriteback.h>
Naseer Ahmed29a26812012-06-14 00:56:20 -070033#include "hwc_utils.h"
Naseer Ahmed54821fe2012-11-28 18:44:38 -050034#include "hwc_mdpcomp.h"
Saurabh Shahcf053c62012-12-13 12:32:55 -080035#include "hwc_fbupdate.h"
Saurabh Shaha9da08f2013-07-03 13:27:53 -070036#include "hwc_ad.h"
Naseer Ahmeda87da602012-07-01 23:54:19 -070037#include "mdp_version.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080038#include "hwc_copybit.h"
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -070039#include "hwc_dump_layers.h"
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -070040#include "hdmi.h"
Saurabh Shah86c17292013-02-08 15:24:13 -080041#include "hwc_qclient.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070042#include "QService.h"
Arun Kumar K.R361da4f2012-11-28 10:42:59 -080043#include "comptype.h"
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -080044#include "hwc_virtual.h"
Tatenda Chipeperekwaa7dd23c2014-03-05 13:02:24 -080045#include "qd_utils.h"
Ramakant Singh98c533c2014-09-30 19:01:54 +053046#include <sys/sysinfo.h>
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +053047#include <dlfcn.h>
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -050048#include <video/msm_hdmi_modes.h>
Saurabh Shah86c17292013-02-08 15:24:13 -080049
50using namespace qClient;
51using namespace qService;
52using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080053using namespace overlay;
54using namespace overlay::utils;
55namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080056
Saurabh Shah74eff4d2014-03-28 16:33:13 -070057#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070058#ifdef __cplusplus
59extern "C" {
60#endif
61
62EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
63 EGLint *attrib_list);
64#define EGL_GPU_HINT_1 0x32D0
65#define EGL_GPU_HINT_2 0x32D1
66
67#define EGL_GPU_LEVEL_0 0x0
68#define EGL_GPU_LEVEL_1 0x1
69#define EGL_GPU_LEVEL_2 0x2
70#define EGL_GPU_LEVEL_3 0x3
71#define EGL_GPU_LEVEL_4 0x4
72#define EGL_GPU_LEVEL_5 0x5
73
74#ifdef __cplusplus
75}
76#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070077#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070078
Ramakant Singhbe390c72014-12-03 23:04:21 +053079#define PROP_DEFAULT_APPBUFFER "hw.sf.app_buff_count"
Ramakant Singh98c533c2014-09-30 19:01:54 +053080#define MAX_RAM_SIZE 512*1024*1024
81#define qHD_WIDTH 540
82
83
Naseer Ahmed29a26812012-06-14 00:56:20 -070084namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070085
Arun Kumar K.R053dc502014-11-13 11:13:43 -080086// Std refresh rates for digital videos- 24p, 30p, 48p and 60p
87uint32_t stdRefreshRates[] = { 30, 24, 48, 60 };
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070088
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053089bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
90{
Jeykumar Sankaran39305802014-12-12 17:55:57 -080091 return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053092 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
93 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
94}
95
Saurabh Shah90c55cf2015-02-10 15:37:39 -080096static void handleFbScaling(hwc_context_t *ctx, int xresPanel, int yresPanel,
97 int width, int height) {
98 const int dpy = HWC_DISPLAY_PRIMARY;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053099 //Store original display resolution.
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800100 ctx->dpyAttr[dpy].xresFB = xresPanel;
101 ctx->dpyAttr[dpy].yresFB = yresPanel;
102 ctx->dpyAttr[dpy].fbScaling = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530103 char property[PROPERTY_VALUE_MAX] = {'\0'};
104 char *yptr = NULL;
105 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
106 yptr = strcasestr(property,"x");
Raj Kamal4a443082014-10-12 21:07:59 +0530107 if(yptr) {
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800108 int xresFB = atoi(property);
109 int yresFB = atoi(yptr + 1);
110 if (isValidResolution(ctx, xresFB, yresFB) &&
111 xresFB != xresPanel && yresFB != yresPanel) {
112 ctx->dpyAttr[dpy].xresFB = xresFB;
113 ctx->dpyAttr[dpy].yresFB = yresFB;
114 ctx->dpyAttr[dpy].fbScaling = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530115
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800116 //Calculate DPI according to changed resolution.
117 float xdpi = ((float)xresFB * 25.4f) / (float)width;
118 float ydpi = ((float)yresFB * 25.4f) / (float)height;
119 ctx->dpyAttr[dpy].xdpi = xdpi;
120 ctx->dpyAttr[dpy].ydpi = ydpi;
Raj Kamal4a443082014-10-12 21:07:59 +0530121 }
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530122 }
123 }
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800124 ctx->dpyAttr[dpy].fbWidthScaleRatio = (float) ctx->dpyAttr[dpy].xres /
125 (float) ctx->dpyAttr[dpy].xresFB;
126 ctx->dpyAttr[dpy].fbHeightScaleRatio = (float) ctx->dpyAttr[dpy].yres /
127 (float) ctx->dpyAttr[dpy].yresFB;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530128}
129
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700130// Initialize hdmi display attributes based on
131// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700132void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700133 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
134 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
135 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
136 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
137 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700138 //FIXME: for now assume HDMI as secure
139 //Will need to read the HDCP status from the driver
140 //and update this accordingly
141 ctx->dpyAttr[dpy].secure = true;
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700142 ctx->mViewFrame[dpy].left = 0;
143 ctx->mViewFrame[dpy].top = 0;
144 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
145 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
146}
147
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700148// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700149void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
150 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
151 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
152 // We reset the fd to -1 here but External display class is responsible
153 // for it when the display is disconnected. This is handled as part of
154 // EXTERNAL_OFFLINE event.
155 ctx->dpyAttr[dpy].fd = -1;
156}
157
158// Initialize composition resources
159void initCompositionResources(hwc_context_t* ctx, int dpy) {
160 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
161 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
162}
163
164void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
165 if(ctx->mFBUpdate[dpy]) {
166 delete ctx->mFBUpdate[dpy];
167 ctx->mFBUpdate[dpy] = NULL;
168 }
169 if(ctx->mMDPComp[dpy]) {
170 delete ctx->mMDPComp[dpy];
171 ctx->mMDPComp[dpy] = NULL;
172 }
173}
174
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800175static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700176{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800177 struct fb_fix_screeninfo finfo;
178 struct fb_var_screeninfo info;
179
180 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530181 if(fb_fd < 0) {
182 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800183 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530184 }
185
186 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
187 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
188 strerror(errno));
189 close(fb_fd);
190 return -errno;
191 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800192
193 if (int(info.width) <= 0 || int(info.height) <= 0) {
194 // the driver doesn't return that information
195 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530196 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
197 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700198 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800199
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530200 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
201 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800202
203#ifdef MSMFB_METADATA_GET
204 struct msmfb_metadata metadata;
205 memset(&metadata, 0 , sizeof(metadata));
206 metadata.op = metadata_op_frame_rate;
207
208 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530209 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
210 strerror(errno));
211 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800212 return -errno;
213 }
214
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530215 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800216#else
217 //XXX: Remove reserved field usage on all baselines
218 //The reserved[3] field is used to store FPS by the driver.
219 float fps = info.reserved[3] & 0xFF;
220#endif
221
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530222 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
223 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
224 strerror(errno));
225 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800226 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530227 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800228
229 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
230 //xres, yres may not be 32 aligned
231 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
232 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
233 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
234 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
235 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700236 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
237 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Arun Kumar K.R074c9cf2014-08-21 18:43:53 -0700238 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530239 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
240 (uint32_t)(1000000000l / fps);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800241
Saurabh Shah90c55cf2015-02-10 15:37:39 -0800242 handleFbScaling(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530243
Naseer Ahmed22616d92013-05-15 17:20:26 -0400244 //Unblank primary on first boot
245 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
246 ALOGE("%s: Failed to unblank display", __FUNCTION__);
247 return -errno;
248 }
249 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
250
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800251 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700252}
253
Ramakant Singh98c533c2014-09-30 19:01:54 +0530254static void changeDefaultAppBufferCount() {
255 struct sysinfo info;
256 unsigned long int ramSize = 0;
257 if (!sysinfo(&info)) {
258 ramSize = info.totalram ;
259 }
260 int fb_fd = -1;
261 struct fb_var_screeninfo sInfo ={0};
262 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
263 if (fb_fd >=0) {
264 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
265 close(fb_fd);
266 }
267 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
268 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
Sanjeev Jakkilinkif8bc0362015-02-23 20:20:17 +0530269 property_set(PROP_DEFAULT_APPBUFFER, "3");
Ramakant Singh98c533c2014-09-30 19:01:54 +0530270 }
271}
272
Arun Kumar K.R205df772015-02-20 18:45:58 -0800273int initContext(hwc_context_t *ctx)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700274{
Arun Kumar K.R205df772015-02-20 18:45:58 -0800275 int error = -1;
276 int compositionType = 0;
277
278 //Right now hwc starts the service but anybody could do it, or it could be
279 //independent process as well.
280 QService::init();
281 sp<IQClient> client = new QClient(ctx);
282 sp<IQService> iqs = interface_cast<IQService>(
283 defaultServiceManager()->getService(
284 String16("display.qservice")));
285 if (iqs.get()) {
286 iqs->connect(client);
287 ctx->mQService = reinterpret_cast<QService* >(iqs.get());
288 } else {
289 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
290 return error;
291 }
292
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700293 overlay::Overlay::initOverlay();
294 ctx->mHDMIDisplay = new HDMIDisplay();
295 uint32_t priW = 0, priH = 0;
296 // 1. HDMI as Primary
297 // -If HDMI cable is connected, read display configs from edid data
298 // -If HDMI cable is not connected then use default data in vscreeninfo
299 // 2. HDMI as External
300 // -Initialize HDMI class for use with external display
301 // -Use vscreeninfo to populate display configs
302 if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
303 int connected = ctx->mHDMIDisplay->getConnectedState();
304 if(connected == 1) {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800305 error = ctx->mHDMIDisplay->configure();
306 if (error < 0) {
307 goto OpenFBError;
308 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700309 updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY);
310 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
311 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800312 error = openFramebufferDevice(ctx);
313 if(error < 0) {
314 goto OpenFBError;
315 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700316 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false;
317 }
318 } else {
Arun Kumar K.R205df772015-02-20 18:45:58 -0800319 error = openFramebufferDevice(ctx);
320 if(error < 0) {
321 goto OpenFBError;
322 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -0700323 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
324 // Send the primary resolution to the hdmi display class
325 // to be used for MDP scaling functionality
326 priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
327 priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
328 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
329 }
330
Raj kamal59fea562014-04-01 16:52:19 +0530331 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700332 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
333 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
334 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800335 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800336 ctx->mRotMgr = RotMgr::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -0800337 ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800338
Ramakant Singh98c533c2014-09-30 19:01:54 +0530339 //default_app_buffer for ferrum
340 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
341 changeDefaultAppBufferCount();
342 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700343 // Initialize composition objects for the primary display
344 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800345
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800346 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800347 // decide if we need to open the copybit module.
Arun Kumar K.R205df772015-02-20 18:45:58 -0800348 compositionType =
349 qdutils::QCCompositionType::getInstance().getCompositionType();
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800350
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800351 // Only MDP copybit is used
352 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
353 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530354 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
355 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800356 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530357 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800358 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
359 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800360 }
361
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700362 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700363 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
364 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
365 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
366 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700367 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
368 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
369 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800370
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700371 //Initialize the primary display viewFrame info
372 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
373 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
374 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
375 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
376 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
377 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530378
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700379 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700380 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700381 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700382 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800383 ctx->dpyAttr[i].mActionSafePresent = false;
384 ctx->dpyAttr[i].mAsWidthRatio = 0;
385 ctx->dpyAttr[i].mAsHeightRatio = 0;
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500386 ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE;
387 ctx->dpyAttr[i].s3dModeForced = false;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700388 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700389
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -0500390 //Make sure that the 3D mode is unset at bootup
391 //This makes sure that the state is accurate on framework reboots
392 ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE);
393
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530394 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
395 ctx->mPrevHwLayerCount[i] = 0;
396 }
397
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500398 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700399 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700400
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400401 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500402 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700403 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530404 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800405
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700406 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700407 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700408 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400409
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -0700410 property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0");
411 ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f);
412
Ramakant Singh0def28c2014-03-28 20:43:13 +0530413 ctx->enableABC = false;
414 property_get("debug.sf.hwc.canUseABC", value, "0");
415 ctx->enableABC = atoi(value) ? true : false;
416
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +0530417 // Initializing boot anim completed check to false
418 ctx->mBootAnimCompleted = false;
419
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700420 // Initialize gpu perfomance hint related parameters
421 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700422#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700423 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
424
425 ctx->mGPUHintInfo.mEGLDisplay = NULL;
426 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700427 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700428 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700429#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700430 // Read the system property to determine if windowboxing feature is enabled.
431 ctx->mWindowboxFeature = false;
432 if(property_get("sys.hwc.windowbox_feature", value, "false")
433 && !strcmp(value, "true")) {
434 ctx->mWindowboxFeature = true;
435 }
436
Raj Kamal0d53fc62014-11-25 17:36:36 +0530437 ctx->mUseMetaDataRefreshRate = true;
438 if(property_get("persist.metadata_dynfps.disable", value, "false")
439 && !strcmp(value, "true")) {
440 ctx->mUseMetaDataRefreshRate = false;
441 }
442
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700443 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Arun Kumar K.R2225eaa2014-12-02 15:52:41 -0800444 ctx->mHPDEnabled = false;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700445 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700446 ALOGI("MDP version: %d", ctx->mMDP.version);
Arun Kumar K.R205df772015-02-20 18:45:58 -0800447
448 return 0;
449
450OpenFBError:
451 ALOGE("%s: Fatal Error: FB Open failed!!!", __FUNCTION__);
452 delete ctx->mHDMIDisplay;
453 return error;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700454}
455
456void closeContext(hwc_context_t *ctx)
457{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500458 if(ctx->mOverlay) {
459 delete ctx->mOverlay;
460 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700461 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700462
Saurabh Shahacf10202013-02-26 10:15:15 -0800463 if(ctx->mRotMgr) {
464 delete ctx->mRotMgr;
465 ctx->mRotMgr = NULL;
466 }
467
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700468 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800469 if(ctx->mCopyBit[i]) {
470 delete ctx->mCopyBit[i];
471 ctx->mCopyBit[i] = NULL;
472 }
473 }
474
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800475 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700476 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
477 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700478 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700479
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700480 if(ctx->mHDMIDisplay) {
481 delete ctx->mHDMIDisplay;
482 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700483 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400484
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700485 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700486 destroyCompositionResources(ctx, i);
487
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700488 if(ctx->mHwcDebug[i]) {
489 delete ctx->mHwcDebug[i];
490 ctx->mHwcDebug[i] = NULL;
491 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700492 if(ctx->mLayerRotMap[i]) {
493 delete ctx->mLayerRotMap[i];
494 ctx->mLayerRotMap[i] = NULL;
495 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800496 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800497 if(ctx->mHWCVirtual) {
498 delete ctx->mHWCVirtual;
499 ctx->mHWCVirtual = NULL;
500 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700501 if(ctx->mAD) {
502 delete ctx->mAD;
503 ctx->mAD = NULL;
504 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800505
Naseer Ahmed7a7b66d2014-07-23 17:56:26 -0400506 if(ctx->mQService) {
507 delete ctx->mQService;
508 ctx->mQService = NULL;
509 }
Naseer Ahmed29a26812012-06-14 00:56:20 -0700510}
511
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700512//Helper to roundoff the refreshrates
Raj Kamal0d53fc62014-11-25 17:36:36 +0530513uint32_t roundOff(uint32_t refreshRate) {
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700514 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
515 uint32_t rate = refreshRate;
516 for(int i=0; i< count; i++) {
517 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
518 // Most likely used for video, the fps can fluctuate
519 // Ex: b/w 29 and 30 for 30 fps clip
520 rate = stdRefreshRates[i];
521 break;
522 }
523 }
524 return rate;
525}
526
527//Helper func to set the dyn fps
528void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
529 //Update only if different
530 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
531 return;
532 const int fbNum = Overlay::getFbForDpy(dpy);
533 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
534 snprintf (sysfsPath, sizeof(sysfsPath),
Arun Kumar K.Ree4e2392015-01-12 18:08:34 -0800535 "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700536
537 int fd = open(sysfsPath, O_WRONLY);
538 if(fd >= 0) {
539 char str[64];
540 snprintf(str, sizeof(str), "%d", refreshRate);
541 ssize_t ret = write(fd, str, strlen(str));
542 if(ret < 0) {
543 ALOGE("%s: Failed to write %d with error %s",
544 __FUNCTION__, refreshRate, strerror(errno));
545 } else {
546 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
547 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
548 __FUNCTION__, refreshRate);
549 }
550 close(fd);
551 } else {
552 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
553 strerror(errno));
554 }
555}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500556
557void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700558{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500559 va_list varargs;
560 va_start(varargs, fmt);
561 buf.appendFormatV(fmt, varargs);
562 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700563}
564
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700565int getExtOrientation(hwc_context_t* ctx) {
566 int extOrient = ctx->mExtOrientation;
567 if(ctx->mBufferMirrorMode)
568 extOrient = getMirrorModeOrientation(ctx);
569 return extOrient;
570}
571
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800572/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700573void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
574 // Position
575 int x = rect.left, y = rect.top;
576 int w = rect.right - rect.left;
577 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800578
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800579 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800580 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800581 // Read action safe properties
582 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
583 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700584
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800585 float wRatio = 1.0;
586 float hRatio = 1.0;
587 float xRatio = 1.0;
588 float yRatio = 1.0;
589
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700590 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
591 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700592 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
593 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700594 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700595 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700596 }
597
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800598
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700599 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700600 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700601
602 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700603 swap(fbWidth, fbHeight);
604
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800605 float asX = 0;
606 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530607 float asW = (float)fbWidth;
608 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800609
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800610 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530611 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
612 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
613 asX = ((float)fbWidth - asW) / 2;
614 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800615
616 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530617 xRatio = (float)x/(float)fbWidth;
618 yRatio = (float)y/(float)fbHeight;
619 wRatio = (float)w/(float)fbWidth;
620 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800621
622 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530623 x = int((xRatio * asW) + asX);
624 y = int((yRatio * asH) + asY);
625 w = int(wRatio * asW);
626 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800627
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700628 // Convert it back to hwc_rect_t
629 rect.left = x;
630 rect.top = y;
631 rect.right = w + rect.left;
632 rect.bottom = h + rect.top;
633
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800634 return;
635}
636
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700637// This function gets the destination position for Seconday display
638// based on the position and aspect ratio with orientation
639void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
640 hwc_rect_t& inRect, hwc_rect_t& outRect) {
641 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530642 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
643 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700644 //display position(x,y,w,h) in correct aspectratio after rotation
645 int xPos = 0;
646 int yPos = 0;
647 float width = fbWidth;
648 float height = fbHeight;
649 // Width/Height used for calculation, after rotation
650 float actualWidth = fbWidth;
651 float actualHeight = fbHeight;
652
653 float wRatio = 1.0;
654 float hRatio = 1.0;
655 float xRatio = 1.0;
656 float yRatio = 1.0;
657 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
658
659 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
660 inRect.bottom - inRect.top);
661 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
662 outRect.bottom - outRect.top);
663
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530664 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700665 eTransform extorient = static_cast<eTransform>(extOrientation);
666 // To calculate the destination co-ordinates in the new orientation
667 preRotateSource(extorient, whf, inPos);
668
669 if(extOrientation & HAL_TRANSFORM_ROT_90) {
670 // Swap width/height for input position
671 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700672 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
673 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700674 xPos = rect.left;
675 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530676 width = float(rect.right - rect.left);
677 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700678 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700679 xRatio = (float)((float)inPos.x/actualWidth);
680 yRatio = (float)((float)inPos.y/actualHeight);
681 wRatio = (float)((float)inPos.w/actualWidth);
682 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800683
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530684 //Calculate the pos9ition...
685 outPos.x = uint32_t((xRatio * width) + (float)xPos);
686 outPos.y = uint32_t((yRatio * height) + (float)yPos);
687 outPos.w = uint32_t(wRatio * width);
688 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700689 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
690 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
691 outPos.w, outPos.h);
692
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700693 // For sidesync, the dest fb will be in portrait orientation, and the crop
694 // will be updated to avoid the black side bands, and it will be upscaled
695 // to fit the dest RB, so recalculate
696 // the position based on the new width and height
697 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
698 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800699 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700700 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530701 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700702 // GetaspectRatio -- tricky to get the correct aspect ratio
703 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700704 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530705 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700706 xPos = r.left;
707 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530708 float tempHeight = float(r.bottom - r.top);
709 yRatio = (float)yPos/height;
710 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700711 hRatio = tempHeight/height;
712
713 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530714 outPos.x = uint32_t(xRatio * fbWidth);
715 outPos.y = uint32_t(yRatio * fbHeight);
716 outPos.w = uint32_t(wRatio * fbWidth);
717 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700718
719 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
720 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
721 outPos.x, outPos.y,
722 outPos.w, outPos.h);
723 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700724 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700725 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700726 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700727 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700728 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
729 extW = ctx->mHWCVirtual->getScalingWidth();
730 extH = ctx->mHWCVirtual->getScalingHeight();
731 }
732 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
733 __FUNCTION__, extW, extH);
734
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530735 fbWidth = (float)ctx->dpyAttr[dpy].xres;
736 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700737 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530738 xRatio = (float)outPos.x/fbWidth;
739 yRatio = (float)outPos.y/fbHeight;
740 wRatio = (float)outPos.w/fbWidth;
741 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700742
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530743 outPos.x = uint32_t(xRatio * (float)extW);
744 outPos.y = uint32_t(yRatio * (float)extH);
745 outPos.w = uint32_t(wRatio * (float)extW);
746 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700747 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700748 // Convert Dim to hwc_rect_t
749 outRect.left = outPos.x;
750 outRect.top = outPos.y;
751 outRect.right = outPos.x + outPos.w;
752 outRect.bottom = outPos.y + outPos.h;
753
754 return;
755}
756
757bool isPrimaryPortrait(hwc_context_t *ctx) {
758 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
759 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
760 if(fbWidth < fbHeight) {
761 return true;
762 }
763 return false;
764}
765
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700766bool isOrientationPortrait(hwc_context_t *ctx) {
767 if(isPrimaryPortrait(ctx)) {
768 return !(ctx->deviceOrientation & 0x1);
769 }
770 return (ctx->deviceOrientation & 0x1);
771}
772
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700773void calcExtDisplayPosition(hwc_context_t *ctx,
774 private_handle_t *hnd,
775 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700776 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700777 hwc_rect_t& displayFrame,
778 int& transform,
779 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700780 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700781 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530782 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700783 if(!isYuvBuffer(hnd)) {
784 if(extOrient & HWC_TRANSFORM_ROT_90) {
785 int dstWidth = ctx->dpyAttr[dpy].xres;
786 int dstHeight = ctx->dpyAttr[dpy].yres;;
787 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
788 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
789 if(!isPrimaryPortrait(ctx)) {
790 swap(srcWidth, srcHeight);
791 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700792 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700793 srcHeight, displayFrame);
794 // Crop - this is needed, because for sidesync, the dest fb will
795 // be in portrait orientation, so update the crop to not show the
796 // black side bands.
797 if (isOrientationPortrait(ctx)) {
798 sourceCrop = displayFrame;
799 displayFrame.left = 0;
800 displayFrame.top = 0;
801 displayFrame.right = dstWidth;
802 displayFrame.bottom = dstHeight;
803 }
804 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700805 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700806 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700807 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700808 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530809 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
810 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700811 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700812 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700813 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700814 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
815 extW = ctx->mHWCVirtual->getScalingWidth();
816 extH = ctx->mHWCVirtual->getScalingHeight();
817 }
818 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
819 __FUNCTION__, extW, extH);
820
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700821 //Calculate the ratio...
822 float wRatio = ((float)extW)/fbWidth;
823 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700824
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700825 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530826 displayFrame.left = int(wRatio*(float)displayFrame.left);
827 displayFrame.top = int(hRatio*(float)displayFrame.top);
828 displayFrame.right = int(wRatio*(float)displayFrame.right);
829 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700830 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
831 " for MDPDownscale feature [%d %d %d %d]",
832 displayFrame.left, displayFrame.top,
833 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700834 }
835 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700836 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700837 getAspectRatioPosition(ctx, dpy, extOrient,
838 displayFrame, displayFrame);
839 }
840 }
841 // If there is a external orientation set, use that
842 if(extOrient) {
843 transform = extOrient;
844 orient = static_cast<ovutils::eTransform >(extOrient);
845 }
846 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
847 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700848 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700849}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700850
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700851/* Returns the orientation which needs to be set on External for
852 * SideSync/Buffer Mirrormode
853 */
854int getMirrorModeOrientation(hwc_context_t *ctx) {
855 int extOrientation = 0;
856 int deviceOrientation = ctx->deviceOrientation;
857 if(!isPrimaryPortrait(ctx))
858 deviceOrientation = (deviceOrientation + 1) % 4;
859 if (deviceOrientation == 0)
860 extOrientation = HWC_TRANSFORM_ROT_270;
861 else if (deviceOrientation == 1)//90
862 extOrientation = 0;
863 else if (deviceOrientation == 2)//180
864 extOrientation = HWC_TRANSFORM_ROT_90;
865 else if (deviceOrientation == 3)//270
866 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
867
868 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700869}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700870
Raj kamal59fea562014-04-01 16:52:19 +0530871/* Get External State names */
872const char* getExternalDisplayState(uint32_t external_state) {
873 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
874 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
875 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
876 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
877 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
878
879 if(external_state >= EXTERNAL_MAXSTATES) {
880 return "EXTERNAL_INVALID";
881 }
882
883 return externalStates[external_state];
884}
885
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530886bool isDownscaleRequired(hwc_layer_1_t const* layer) {
887 hwc_rect_t displayFrame = layer->displayFrame;
888 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
889 int dst_w, dst_h, src_w, src_h;
890 dst_w = displayFrame.right - displayFrame.left;
891 dst_h = displayFrame.bottom - displayFrame.top;
892 src_w = sourceCrop.right - sourceCrop.left;
893 src_h = sourceCrop.bottom - sourceCrop.top;
894
895 if(((src_w > dst_w) || (src_h > dst_h)))
896 return true;
897
898 return false;
899}
900bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500901 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500902 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700903 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500904
905 dst_w = displayFrame.right - displayFrame.left;
906 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500907 src_w = sourceCrop.right - sourceCrop.left;
908 src_h = sourceCrop.bottom - sourceCrop.top;
909
Jeykumar Sankaran6a339522014-11-04 16:14:43 -0800910 if(layer->transform & HWC_TRANSFORM_ROT_90)
911 swap(src_w, src_h);
912
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800913 if(((src_w != dst_w) || (src_h != dst_h)))
914 return true;
915
916 return false;
917}
918
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700919// Checks if layer needs scaling with split
920bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
921 const int& dpy) {
922
923 int src_width_l, src_height_l;
924 int src_width_r, src_height_r;
925 int dst_width_l, dst_height_l;
926 int dst_width_r, dst_height_r;
927 int hw_w = ctx->dpyAttr[dpy].xres;
928 int hw_h = ctx->dpyAttr[dpy].yres;
929 hwc_rect_t cropL, dstL, cropR, dstR;
930 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700931 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700932 hwc_rect_t displayFrame = layer->displayFrame;
933 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700934
935 cropL = sourceCrop;
936 dstL = displayFrame;
937 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800938 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700939 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
940
941 cropR = sourceCrop;
942 dstR = displayFrame;
943 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800944 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700945 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
946
947 // Sanitize Crop to stitch
948 sanitizeSourceCrop(cropL, cropR, hnd);
949
950 // Calculate the left dst
951 dst_width_l = dstL.right - dstL.left;
952 dst_height_l = dstL.bottom - dstL.top;
953 src_width_l = cropL.right - cropL.left;
954 src_height_l = cropL.bottom - cropL.top;
955
956 // check if there is any scaling on the left
957 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
958 return true;
959
960 // Calculate the right dst
961 dst_width_r = dstR.right - dstR.left;
962 dst_height_r = dstR.bottom - dstR.top;
963 src_width_r = cropR.right - cropR.left;
964 src_height_r = cropR.bottom - cropR.top;
965
966 // check if there is any scaling on the right
967 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
968 return true;
969
970 return false;
971}
972
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530973bool isAlphaScaled(hwc_layer_1_t const* layer) {
974 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530975 return true;
976 }
977 return false;
978}
979
980bool isAlphaPresent(hwc_layer_1_t const* layer) {
981 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400982 if(hnd) {
983 int format = hnd->format;
984 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530985 case HAL_PIXEL_FORMAT_RGBA_8888:
986 case HAL_PIXEL_FORMAT_BGRA_8888:
987 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500988 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530989 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400990 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500991 }
992 return false;
993}
994
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700995static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
996 hwc_rect_t& crop, hwc_rect_t& dst) {
997 int hw_w = ctx->dpyAttr[dpy].xres;
998 int hw_h = ctx->dpyAttr[dpy].yres;
999 if(dst.left < 0 || dst.top < 0 ||
1000 dst.right > hw_w || dst.bottom > hw_h) {
1001 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08001002 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001003 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
1004 }
1005}
1006
1007static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
1008 const int& dpy) {
1009 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
1010 hwc_layer_1_t *layer = &list->hwLayers[i];
1011 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001012 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
1013 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001014 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001015 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001016 (hwc_rect_t&)crop,
1017 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301018 layer->sourceCropf.left = (float)crop.left;
1019 layer->sourceCropf.right = (float)crop.right;
1020 layer->sourceCropf.top = (float)crop.top;
1021 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001022 }
1023}
1024
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001025void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -07001026 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -07001027 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
1028 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301029 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
1030 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -07001031 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301032 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001033 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001034 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -04001035 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001036 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001037 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +05301038 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001039 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +05301040 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001041 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001042 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
1043 uint32_t refreshRate = 0;
1044 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001045 int s3dFormat = HAL_NO_3D;
1046 int s3dLayerCount = 0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001047
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001048 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001049 resetROI(ctx, dpy);
1050
Sushil Chauhanf68d0df2014-04-09 09:15:37 -07001051 trimList(ctx, list, dpy);
1052 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001053 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -05001054 hwc_layer_1_t const* layer = &list->hwLayers[i];
1055 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001056
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001057#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001058 // Window boxing feature is applicable obly for external display, So
1059 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001060 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001061 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001062 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001063 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
1064 ctx->listStats[dpy].isDisplayAnimating = true;
1065 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001066 if(isSecureDisplayBuffer(hnd)) {
1067 ctx->listStats[dpy].secureUI = true;
1068 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001069#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001070 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
1071 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001072 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001073
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001074 //reset yuv indices
1075 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +05301076 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001077
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001078 if (isSecureBuffer(hnd)) {
1079 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001080 if(not isYuvBuffer(hnd)) {
1081 // cache secureRGB layer parameters like we cache for YUV layers
1082 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1083 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1084 secureRGBCount++;
1085 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001086 }
1087
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001088 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001089 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001090 }
1091
1092 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001093 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301094 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001095 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001096
Raj Kamal389d6e32014-08-04 14:43:24 +05301097 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301098 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301099 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301100 yuv4k2kCount++;
1101 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001102
1103 // Gets set if one YUV layer is 3D
1104 if (displaySupports3D(ctx,dpy)) {
1105 s3dFormat = get3DFormat(hnd);
1106 if(s3dFormat != HAL_NO_3D)
1107 s3dLayerCount++;
1108 }
1109
Naseer Ahmed29a26812012-06-14 00:56:20 -07001110 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301111 if(layer->blending == HWC_BLENDING_PREMULT)
1112 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001113
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001114#ifdef DYNAMIC_FPS
Raj Kamal0d53fc62014-11-25 17:36:36 +05301115 if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001116 //dyn fps: get refreshrate from metadata
1117 //Support multiple refresh rates if they are same
1118 //else set to default
1119 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1120 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1121 // Valid refreshRate in metadata and within the range
1122 uint32_t rate = roundOff(mdata->refreshrate);
1123 if((rate >= mdpHw.getMinFpsSupported() &&
1124 rate <= mdpHw.getMaxFpsSupported())) {
1125 if (!refreshRate) {
1126 refreshRate = rate;
1127 } else if(refreshRate != rate) {
1128 // multiple refreshrate requests, set to default
1129 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1130 }
1131 }
1132 }
1133 }
1134#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001135 }
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05001136
1137 //Set the TV's 3D mode based on format if it was not forced
1138 //Only one 3D YUV layer is supported on external
1139 //If there is more than one 3D YUV layer, the switch to 3D cannot occur.
1140 if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) {
1141 //XXX: Rapidly going in and out of 3D mode in some cases such
1142 // as rotation might cause flickers. The OEMs are recommended to disable
1143 // rotation on HDMI globally or in the app that plays 3D video
1144 setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat));
1145 }
1146
Ping Li9404e2a2013-04-24 16:36:03 -04001147 if(ctx->listStats[dpy].yuvCount > 0) {
1148 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1149 if (atoi(property) != 1) {
1150 property_set("hw.cabl.yuv", "1");
1151 }
1152 }
1153 } else {
1154 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1155 if (atoi(property) != 0) {
1156 property_set("hw.cabl.yuv", "0");
1157 }
1158 }
1159 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001160
1161 //The marking of video begin/end is useful on some targets where we need
1162 //to have a padding round to be able to shift pipes across mixers.
1163 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1164 ctx->mVideoTransFlag = true;
1165 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301166
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001167 if(dpy == HWC_DISPLAY_PRIMARY) {
1168 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001169 //Store the requested fresh rate
1170 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1171 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001172 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001173}
1174
Naseer Ahmed018e5452012-12-03 14:46:15 -05001175
Saurabh Shah68107422013-07-09 11:12:42 -07001176static void calc_cut(double& leftCutRatio, double& topCutRatio,
1177 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001178 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001179 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001180 }
1181 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001182 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001183 }
1184 if(orient & HAL_TRANSFORM_ROT_90) {
1185 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001186 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001187 leftCutRatio = topCutRatio;
1188 topCutRatio = rightCutRatio;
1189 rightCutRatio = bottomCutRatio;
1190 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001191 }
1192}
1193
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001194bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001195 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1196 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1197 ctx->mSecuring) {
1198 return true;
1199 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001200 if (isSecureModePolicy(ctx->mMDP.version)) {
1201 private_handle_t *hnd = (private_handle_t *)layer->handle;
1202 if(ctx->mSecureMode) {
1203 if (! isSecureBuffer(hnd)) {
1204 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1205 __FUNCTION__);
1206 return true;
1207 }
1208 } else {
1209 if (isSecureBuffer(hnd)) {
1210 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1211 __FUNCTION__);
1212 return true;
1213 }
1214 }
1215 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001216 return false;
1217}
1218
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001219bool isSecureModePolicy(int mdpVersion) {
1220 if (mdpVersion < qdutils::MDSS_V5)
1221 return true;
1222 else
1223 return false;
1224}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001225
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001226bool isRotatorSupportedFormat(private_handle_t *hnd) {
1227 // Following rotator src formats are supported by mdp driver
1228 // TODO: Add more formats in future, if mdp driver adds support
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001229 if(hnd != NULL) {
1230 switch(hnd->format) {
1231 case HAL_PIXEL_FORMAT_RGBA_8888:
Ramkumar Radhakrishnanb8eb16d2014-10-09 13:54:07 -07001232 case HAL_PIXEL_FORMAT_RGBA_5551:
1233 case HAL_PIXEL_FORMAT_RGBA_4444:
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001234 case HAL_PIXEL_FORMAT_RGB_565:
1235 case HAL_PIXEL_FORMAT_RGB_888:
1236 case HAL_PIXEL_FORMAT_BGRA_8888:
1237 return true;
1238 default:
1239 return false;
1240 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001241 }
1242 return false;
1243}
1244
1245bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001246 // Rotate layers, if it is not secure display buffer and not
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001247 // for the MDP versions below MDP5
Ramkumar Radhakrishnan629cbf52014-10-14 19:36:33 -07001248 if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) &&
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001249 !ctx->mMDP.version < qdutils::MDSS_V5)
1250 || isYuvBuffer(hnd)) {
1251 return true;
1252 }
1253 return false;
1254}
1255
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001256// returns true if Action safe dimensions are set and target supports Actionsafe
1257bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1258 // if external supports underscan, do nothing
1259 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001260 // Disable Action safe for 8974 due to HW limitation for downscaling
1261 // layers with overlapped region
1262 // Disable Actionsafe for non HDMI displays.
1263 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1264 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001265 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001266 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001267 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001268
1269 char value[PROPERTY_VALUE_MAX];
1270 // Read action safe properties
1271 property_get("persist.sys.actionsafe.width", value, "0");
1272 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1273 property_get("persist.sys.actionsafe.height", value, "0");
1274 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1275
1276 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1277 //No action safe ratio set, return
1278 return false;
1279 }
1280 return true;
1281}
1282
Naseer Ahmed522ce662013-03-18 20:14:05 -04001283int getBlending(int blending) {
1284 switch(blending) {
1285 case HWC_BLENDING_NONE:
1286 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1287 case HWC_BLENDING_PREMULT:
1288 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1289 case HWC_BLENDING_COVERAGE :
1290 default:
1291 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1292 }
1293}
1294
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001295//Crops source buffer against destination and FB boundaries
1296void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001297 const hwc_rect_t& scissor, int orient) {
1298
Saurabh Shah27c1d652012-08-14 19:30:28 -07001299 int& crop_l = crop.left;
1300 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001301 int& crop_r = crop.right;
1302 int& crop_b = crop.bottom;
1303 int crop_w = crop.right - crop.left;
1304 int crop_h = crop.bottom - crop.top;
1305
Saurabh Shah27c1d652012-08-14 19:30:28 -07001306 int& dst_l = dst.left;
1307 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001308 int& dst_r = dst.right;
1309 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001310 int dst_w = abs(dst.right - dst.left);
1311 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001312
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001313 const int& sci_l = scissor.left;
1314 const int& sci_t = scissor.top;
1315 const int& sci_r = scissor.right;
1316 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001317
Saurabh Shah68107422013-07-09 11:12:42 -07001318 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1319 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001320
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001321 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001322 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001323 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001324 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001325
1326 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001327 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001328 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001329 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001330
1331 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001332 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001333 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001334 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001335
1336 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001337 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001338 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001339 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001340
Saurabh Shah541b59d2012-10-11 11:08:12 -07001341 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301342 crop_l += (int)round((double)crop_w * leftCutRatio);
1343 crop_t += (int)round((double)crop_h * topCutRatio);
1344 crop_r -= (int)round((double)crop_w * rightCutRatio);
1345 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001346}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001347
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301348bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1349 const hwc_layer_1_t* layer2) {
1350 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1351 layer2->displayFrame);
1352 return isValidRect(irect);
1353}
1354
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001355bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1356{
1357 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1358 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1359}
1360
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001361bool isValidRect(const hwc_rect& rect)
1362{
1363 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301364}
1365
Ramakant Singh21cec722014-03-07 19:11:45 +05301366bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1367 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1368 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1369 return true ;
1370 return false;
1371}
1372
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001373hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1374{
1375 hwc_rect_t res;
1376
1377 if(!isValidRect(rect))
1378 return (hwc_rect_t){0, 0, 0, 0};
1379
1380 res.left = rect.left + x_off;
1381 res.top = rect.top + y_off;
1382 res.right = rect.right + x_off;
1383 res.bottom = rect.bottom + y_off;
1384
1385 return res;
1386}
1387
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001388/* computes the intersection of two rects */
1389hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1390{
1391 hwc_rect_t res;
1392
1393 if(!isValidRect(rect1) || !isValidRect(rect2)){
1394 return (hwc_rect_t){0, 0, 0, 0};
1395 }
1396
1397
1398 res.left = max(rect1.left, rect2.left);
1399 res.top = max(rect1.top, rect2.top);
1400 res.right = min(rect1.right, rect2.right);
1401 res.bottom = min(rect1.bottom, rect2.bottom);
1402
1403 if(!isValidRect(res))
1404 return (hwc_rect_t){0, 0, 0, 0};
1405
1406 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301407}
1408
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001409/* computes the union of two rects */
1410hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1411{
1412 hwc_rect_t res;
1413
1414 if(!isValidRect(rect1)){
1415 return rect2;
1416 }
1417
1418 if(!isValidRect(rect2)){
1419 return rect1;
1420 }
1421
1422 res.left = min(rect1.left, rect2.left);
1423 res.top = min(rect1.top, rect2.top);
1424 res.right = max(rect1.right, rect2.right);
1425 res.bottom = max(rect1.bottom, rect2.bottom);
1426
1427 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301428}
1429
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001430/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1431 * a single rect */
1432hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301433
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001434 hwc_rect_t res = rect1;
1435
1436 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1437 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1438 res.top = rect2.bottom;
1439 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1440 res.bottom = rect2.top;
1441 }
1442 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1443 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1444 res.left = rect2.right;
1445 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1446 res.right = rect2.left;
1447 }
1448 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301449}
1450
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001451void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301452 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301453 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301454 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001455 //If it is opaque see if we can substract this region from below
1456 //layers.
radhakrishna4efbdd62014-11-03 13:19:27 +05301457 if(list->hwLayers[i].blending == HWC_BLENDING_NONE &&
1458 list->hwLayers[i].planeAlpha == 0xFF) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301459 int j= i-1;
1460 hwc_rect_t& topframe =
1461 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1462 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301463 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001464 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1465 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001466 hwc_rect_t bottomCrop =
1467 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001468 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1469 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001470
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001471 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1472 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001473 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001474 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001475 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001476 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001477 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001478 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301479 layer->sourceCropf.left =(float)bottomCrop.left;
1480 layer->sourceCropf.top = (float)bottomCrop.top;
1481 layer->sourceCropf.right = (float)bottomCrop.right;
1482 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001483#ifdef QCOM_BSP
1484 //Update layer dirtyRect
1485 layer->dirtyRect = getIntersection(bottomCrop,
1486 layer->dirtyRect);
1487#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001488 }
1489 }
1490 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301491 }
1492 }
1493 i--;
1494 }
1495}
1496
Naseer Ahmed64b81212013-02-14 10:29:47 -05001497void getNonWormholeRegion(hwc_display_contents_1_t* list,
1498 hwc_rect_t& nwr)
1499{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301500 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001501 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1502 //Initiliaze nwr to first frame
1503 nwr.left = list->hwLayers[0].displayFrame.left;
1504 nwr.top = list->hwLayers[0].displayFrame.top;
1505 nwr.right = list->hwLayers[0].displayFrame.right;
1506 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1507
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301508 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001509 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001510 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001511 }
1512
1513 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001514 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001515}
1516
Saurabh Shah747af1e2013-02-26 10:25:12 -08001517void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001518 if(LIKELY(list)) {
1519 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1520 //Close the acquireFenceFds
1521 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1522 if(list->hwLayers[i].acquireFenceFd >= 0) {
1523 close(list->hwLayers[i].acquireFenceFd);
1524 list->hwLayers[i].acquireFenceFd = -1;
1525 }
1526 }
1527 //Writeback
1528 if(list->outbufAcquireFenceFd >= 0) {
1529 close(list->outbufAcquireFenceFd);
1530 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001531 }
1532 }
1533}
1534
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001535int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001536 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001537 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001538 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001539 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001540 int count = 0;
1541 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001542 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001543 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001544 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001545
1546 struct mdp_buf_sync data;
1547 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001548 data.acq_fen_fd = acquireFd;
1549 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001550 data.retire_fen_fd = &retireFd;
1551 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001552
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001553 char property[PROPERTY_VALUE_MAX];
1554 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1555 if(atoi(property) == 0)
1556 swapzero = true;
1557 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001558
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001559 bool isExtAnimating = false;
1560 if(dpy)
1561 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001562
Saurabh Shah23a813c2013-03-20 16:58:12 -07001563 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001564 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001565 int rotFd = ctx->mRotMgr->getRotDevFd();
1566 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001567 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1568 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1569 if((currRot == NULL) || (currLayer == NULL)) {
1570 continue;
1571 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001572 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001573 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001574 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001575 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001576 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001577 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001578 if(currLayer->acquireFenceFd >= 0) {
1579 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1580 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001581 int ret = 0;
Raj Kamal4b02b742014-10-12 20:51:14 +05301582 if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i)))
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301583 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1584
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001585 if(ret < 0) {
1586 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1587 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001588 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001589 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001590 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001591 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001592 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001593 dup(rotReleaseFd);
1594 //A buffer is free to be used by producer as soon as its copied to
1595 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001596 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001597 rotReleaseFd;
1598 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001599 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001600
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301601 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001602 if(list->outbufAcquireFenceFd >= 0) {
1603 //Writeback output buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301604 if(LIKELY(!swapzero) )
1605 acquireFd[count++] = list->outbufAcquireFenceFd;
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001606 }
1607
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001608 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301609 if(((isAbcInUse(ctx)== true ) ||
1610 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001611 list->hwLayers[i].acquireFenceFd >= 0) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301612 if(LIKELY(!swapzero) ) {
1613 // if ABC is enabled for more than one layer.
1614 // renderBufIndexforABC will work as FB.Hence
1615 // set the acquireFD from fd - which is coming from copybit
1616 if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1617 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1618 acquireFd[count++] = fd;
1619 else
1620 continue;
1621 } else
1622 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1623 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001624 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001625 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Raj Kamal4b02b742014-10-12 20:51:14 +05301626 if(LIKELY(!swapzero) ) {
1627 if(fd >= 0) {
1628 //set the acquireFD from fd - which is coming from c2d
1629 acquireFd[count++] = fd;
1630 // Buffer sync IOCTL should be async when using c2d fence is
1631 // used
1632 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
1633 } else if(list->hwLayers[i].acquireFenceFd >= 0)
1634 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1635 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001636 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001637 }
1638
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001639 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001640 // Acquire c2d fence of Overlap render buffer
Raj Kamal4b02b742014-10-12 20:51:14 +05301641 if(LIKELY(!swapzero) )
1642 acquireFd[count++] = fd;
Sushil Chauhandefd3522014-05-13 18:17:12 -07001643 }
1644
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001645 data.acq_fen_fd_cnt = count;
1646 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001647
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001648 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001649 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001650 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001651 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001652
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001653 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001654 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1655 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301656 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001657 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1658 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001659 close(releaseFd);
1660 releaseFd = -1;
1661 close(retireFd);
1662 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001663 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001664
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001665 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001666 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001667#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001668 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001669#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001670 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001671 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001672 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001673 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001674 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001675 // Release all the app layer fds immediately,
1676 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001677 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001678 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001679#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001680 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301681 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301682
1683 // if ABC is enabled for more than one layer
1684 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1685 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1686 list->hwLayers[i].releaseFenceFd = dup(fd);
1687 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1688 (isAbcInUse(ctx) == false)){
1689 //For Blit, the app layers should be released when the Blit
1690 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301691 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001692 } else
1693#endif
1694 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301695 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1696 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001697 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001698 }
1699 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001700
1701 if(fd >= 0) {
1702 close(fd);
1703 fd = -1;
1704 }
1705
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001706 if (ctx->mCopyBit[dpy]) {
1707 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001708 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1709 else
1710 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1711 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001712
Saurabh Shah23a813c2013-03-20 16:58:12 -07001713 //Signals when MDP finishes reading rotator buffers.
1714 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001715 close(releaseFd);
1716 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001717
Arun Kumar K.R51835182013-11-19 11:20:28 -08001718 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001719 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001720 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001721 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001722 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001723 return ret;
1724}
1725
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001726void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001727 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001728 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001729 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001730 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001731
1732 if(layer->blending == HWC_BLENDING_PREMULT) {
1733 ovutils::setMdpFlags(mdpFlags,
1734 ovutils::OV_MDP_BLEND_FG_PREMULT);
1735 }
1736
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001737 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1738 metadata->interlaced) {
1739 ovutils::setMdpFlags(mdpFlags,
1740 ovutils::OV_MDP_DEINTERLACE);
1741 }
1742
1743 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1744 if(isSecureBuffer(hnd)) {
1745 ovutils::setMdpFlags(mdpFlags,
1746 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Justin Philipd6166602014-08-12 13:42:21 +05301747 ovutils::setMdpFlags(mdpFlags,
1748 ovutils::OV_MDP_SMP_FORCE_ALLOC);
1749 }
1750
1751 if(isProtectedBuffer(hnd)) {
1752 ovutils::setMdpFlags(mdpFlags,
1753 ovutils::OV_MDP_SMP_FORCE_ALLOC);
Saurabh Shahacf10202013-02-26 10:15:15 -08001754 }
1755
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001756 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001757 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001758 ovutils::setMdpFlags(mdpFlags,
1759 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1760 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001761
1762 //Pre-rotation will be used using rotator.
1763 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1764 ovutils::setMdpFlags(mdpFlags,
1765 ovutils::OV_MDP_SOURCE_ROTATED_90);
1766 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001767 //No 90 component and no rot-downscale then flips done by MDP
1768 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001769 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1770 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001771 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1772 }
1773
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001774 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001775 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1776 }
1777 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001778
1779 if(metadata &&
1780 ((metadata->operation & PP_PARAM_HSIC)
1781 || (metadata->operation & PP_PARAM_IGC)
1782 || (metadata->operation & PP_PARAM_SHARP2))) {
1783 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1784 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001785}
1786
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301787int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001788 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001789 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001790
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301791 // Fix alignments for TILED format
1792 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1793 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1794 whf.w = utils::alignup(whf.w, 64);
1795 whf.h = utils::alignup(whf.h, 32);
1796 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001797 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001798
1799 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1800 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001801 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1802 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001803 rot->setCrop(rotCrop);
1804 }
1805
Saurabh Shahacf10202013-02-26 10:15:15 -08001806 rot->setFlags(mdpFlags);
1807 rot->setTransform(orient);
1808 rot->setDownscale(downscale);
1809 if(!rot->commit()) return -1;
1810 return 0;
1811}
1812
Saurabh Shahe2474082013-05-15 16:32:13 -07001813int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001814 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001815 const hwc_rect_t& pos, const MetaData_t *metadata,
1816 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001817 ov->setSource(parg, dest);
1818 ov->setTransform(orient, dest);
1819
1820 int crop_w = crop.right - crop.left;
1821 int crop_h = crop.bottom - crop.top;
1822 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1823 ov->setCrop(dcrop, dest);
1824
1825 int posW = pos.right - pos.left;
1826 int posH = pos.bottom - pos.top;
1827 Dim position(pos.left, pos.top, posW, posH);
1828 ov->setPosition(position, dest);
1829
Saurabh Shah5daeee52013-01-23 16:52:26 +08001830 if (metadata)
1831 ov->setVisualParams(*metadata, dest);
1832
Saurabh Shahacf10202013-02-26 10:15:15 -08001833 if (!ov->commit(dest)) {
1834 return -1;
1835 }
1836 return 0;
1837}
1838
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001839int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1840 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001841 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001842
1843 hwc_rect_t dst = layer->displayFrame;
1844 trimLayer(ctx, dpy, 0, dst, dst);
1845
1846 int w = ctx->dpyAttr[dpy].xres;
1847 int h = ctx->dpyAttr[dpy].yres;
1848 int dst_w = dst.right - dst.left;
1849 int dst_h = dst.bottom - dst.top;
1850 uint32_t color = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001851 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888));
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001852
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001853 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001854 if (layer->blending == HWC_BLENDING_PREMULT)
1855 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1856
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001857 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001858 layer->planeAlpha,
1859 (ovutils::eBlending) getBlending(layer->blending));
1860
1861 // Configure MDP pipe for Color layer
1862 Dim pos(dst.left, dst.top, dst_w, dst_h);
1863 ctx->mOverlay->setSource(parg, dest);
1864 ctx->mOverlay->setColor(color, dest);
1865 ctx->mOverlay->setTransform(0, dest);
1866 ctx->mOverlay->setCrop(pos, dest);
1867 ctx->mOverlay->setPosition(pos, dest);
1868
1869 if (!ctx->mOverlay->commit(dest)) {
1870 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1871 return -1;
1872 }
1873 return 0;
1874}
1875
Saurabh Shahe2474082013-05-15 16:32:13 -07001876void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001877 hwc_rect_t& crop, Rotator *rot) {
1878 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001879 crop.right - crop.left,
1880 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001881 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1882 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001883 //B-family rotator internally could modify destination dimensions if
1884 //downscaling is supported
1885 whf = rot->getDstWhf();
1886 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001887 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001888 //A-family rotator rotates entire buffer irrespective of crop, forcing
1889 //us to recompute the crop based on transform
1890 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1891 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001892 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001893
1894 crop.left = transformedCrop.x;
1895 crop.top = transformedCrop.y;
1896 crop.right = transformedCrop.x + transformedCrop.w;
1897 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001898}
1899
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001900int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1901 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1902 return 0;
1903 }
1904
1905 int downscale = 0;
1906 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1907 hwc_rect_t dst = layer->displayFrame;
1908 private_handle_t *hnd = (private_handle_t *)layer->handle;
1909
1910 if(not hnd) {
1911 return 0;
1912 }
1913
1914 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1915 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1916 && metadata->interlaced;
1917 int transform = layer->transform;
Sushil Chauhan65e26302015-01-14 10:48:57 -08001918 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001919
1920 if(isYuvBuffer(hnd)) {
1921 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1922 ctx->mMDP.version < qdutils::MDSS_V5) {
1923 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1924 crop.bottom - crop.top, dst.right - dst.left,
1925 dst.bottom - dst.top, format, isInterlaced);
1926 } else {
1927 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1928 crop.bottom - crop.top);
1929 Dim pos(dst.left, dst.top, dst.right - dst.left,
1930 dst.bottom - dst.top);
1931 if(transform & HAL_TRANSFORM_ROT_90) {
1932 swap(adjCrop.w, adjCrop.h);
1933 }
1934 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1935 pos.h, format, isInterlaced);
1936 }
1937 }
1938 return downscale;
1939}
1940
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001941bool isZoomModeEnabled(hwc_rect_t crop) {
1942 // This does not work for zooming in top left corner of the image
1943 return(crop.top > 0 || crop.left > 0);
1944}
1945
1946void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1947 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1948 crop.left, crop.top, crop.right, crop.bottom);
1949 if(isZoomModeEnabled(crop)) {
1950 Dim srcCrop(crop.left, crop.top,
1951 crop.right - crop.left,
1952 crop.bottom - crop.top);
1953 int extW = ctx->dpyAttr[dpy].xres;
1954 int extH = ctx->dpyAttr[dpy].yres;
1955 //Crop the original video in order to fit external display aspect ratio
1956 if(srcCrop.w * extH < extW * srcCrop.h) {
1957 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1958 crop.top += offset;
1959 crop.bottom -= offset;
1960 } else {
1961 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1962 crop.left += offset;
1963 crop.right -= offset;
1964 }
1965 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1966 " source crop [%d %d %d %d]", extW, extH, dpy,
1967 crop.left, crop.top, crop.right, crop.bottom);
1968 }
1969}
1970
1971void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1972 hwc_rect_t& dst, int dpy) {
1973 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1974 dst.left, dst.top, dst.right, dst.bottom);
1975 Dim srcCrop(crop.left, crop.top,
1976 crop.right - crop.left,
1977 crop.bottom - crop.top);
1978 int extW = ctx->dpyAttr[dpy].xres;
1979 int extH = ctx->dpyAttr[dpy].yres;
1980 // Set the destination coordinates of external display to full screen,
Ramkumar Radhakrishnan812999a2014-09-11 21:42:07 -07001981 // when zoom in mode is enabled or the ratio between video aspect ratio
1982 // and external display aspect ratio is below the minimum tolerance level
1983 // and above maximum tolerance level
1984 float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h);
1985 float extDisplayAspectRatio = ((float)extW / (float)extH);
1986 float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio;
1987 if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) ||
1988 (isZoomModeEnabled(crop))) {
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001989 dst.left = 0;
1990 dst.top = 0;
1991 dst.right = extW;
1992 dst.bottom = extH;
1993 }
1994 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1995 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
1996 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
1997 crop.left, crop.top, crop.right, crop.bottom);
1998}
1999
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002000void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002001 hwc_rect_t& dst, int dpy) {
2002 updateCropAIVVideoMode(ctx, crop, dpy);
2003 updateDestAIVVideoMode(ctx, crop, dst, dpy);
2004}
2005
Saurabh Shah88e4d272013-09-03 13:31:29 -07002006int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002007 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002008 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002009
2010 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002011
Saurabh Shahacf10202013-02-26 10:15:15 -08002012 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002013 if (layer->flags & HWC_COLOR_FILL) {
2014 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002015 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07002016 }
Saurabh Shahacf10202013-02-26 10:15:15 -08002017 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2018 return -1;
2019 }
2020
Saurabh Shah5daeee52013-01-23 16:52:26 +08002021 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2022
Saurabh Shah62e1d732013-09-17 10:44:05 -07002023 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002024 hwc_rect_t dst = layer->displayFrame;
2025 int transform = layer->transform;
2026 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002027 int rotFlags = ovutils::ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002028 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302029 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002030
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002031 // Handle R/B swap
2032 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2033 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2034 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2035 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2036 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2037 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002038 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002039 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2040 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002041 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08002042 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002043 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002044 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002045
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002046 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002047 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002048 *rot = ctx->mRotMgr->getNext();
2049 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002050 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahcd018352014-11-11 13:54:19 -08002051 BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale,
2052 mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08002053 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002054 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
2055 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002056 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002057 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002058 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002059 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08002060 }
2061
Saurabh Shah76fd6552013-03-14 14:45:38 -07002062 //For the mdp, since either we are pre-rotating or MDP does flips
2063 orient = OVERLAY_TRANSFORM_0;
2064 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002065 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002066 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2067 (ovutils::eBlending) getBlending(layer->blending));
2068
Saurabh Shah5daeee52013-01-23 16:52:26 +08002069 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002070 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
2071 return -1;
2072 }
2073 return 0;
2074}
2075
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002076//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07002077void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002078 private_handle_t *hnd) {
2079 if(cropL.right - cropL.left) {
2080 if(isYuvBuffer(hnd)) {
2081 //Always safe to even down left
2082 ovutils::even_floor(cropL.left);
2083 //If right is even, automatically width is even, since left is
2084 //already even
2085 ovutils::even_floor(cropL.right);
2086 }
2087 //Make sure there are no gaps between left and right splits if the layer
2088 //is spread across BOTH halves
2089 if(cropR.right - cropR.left) {
2090 cropR.left = cropL.right;
2091 }
2092 }
2093
2094 if(cropR.right - cropR.left) {
2095 if(isYuvBuffer(hnd)) {
2096 //Always safe to even down left
2097 ovutils::even_floor(cropR.left);
2098 //If right is even, automatically width is even, since left is
2099 //already even
2100 ovutils::even_floor(cropR.right);
2101 }
2102 }
2103}
2104
Saurabh Shah88e4d272013-09-03 13:31:29 -07002105int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07002106 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002107 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08002108 Rotator **rot) {
2109 private_handle_t *hnd = (private_handle_t *)layer->handle;
2110 if(!hnd) {
2111 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2112 return -1;
2113 }
2114
Saurabh Shah5daeee52013-01-23 16:52:26 +08002115 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2116
Saurabh Shahacf10202013-02-26 10:15:15 -08002117 int hw_w = ctx->dpyAttr[dpy].xres;
2118 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002119 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002120 hwc_rect_t dst = layer->displayFrame;
2121 int transform = layer->transform;
2122 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002123 int rotFlags = ROT_FLAGS_NONE;
Sushil Chauhan65e26302015-01-14 10:48:57 -08002124 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302125 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002126
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002127 // Handle R/B swap
2128 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2129 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2130 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2131 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2132 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2133 }
2134
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002135 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002136 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2137 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002138 }
2139
2140 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002141 ActionSafe, and extorientation features. */
2142 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002143 int downscale = getRotDownscale(ctx, layer);
2144 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002145
2146 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2147 //Enable overfetch
2148 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2149 }
2150
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002151 //Will do something only if feature enabled and conditions suitable
2152 //hollow call otherwise
2153 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2154 overlay::Writeback *wb = overlay::Writeback::getInstance();
2155 whf.format = wb->getOutputFormat();
2156 }
2157
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002158 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002159 (*rot) = ctx->mRotMgr->getNext();
2160 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002161 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002162 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002163 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2164 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002165 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002166 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002167 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002168 rotFlags |= ROT_PREROTATED;
2169 }
2170
2171 eMdpFlags mdpFlagsR = mdpFlagsL;
2172 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2173
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002174 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2175 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002176
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002177 const int lSplit = getLeftSplit(ctx, dpy);
2178
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002179 // Calculate Left rects
2180 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002181 tmp_cropL = crop;
2182 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002183 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002184 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002185 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2186 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002187
2188 // Calculate Right rects
2189 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002190 tmp_cropR = crop;
2191 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002192 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002193 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002194 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2195 }
2196
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002197 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2198
Saurabh Shah94d62362013-07-02 10:58:48 -07002199 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002200 //Not needed if the layer is confined to one half of the screen.
2201 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002202 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2203 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002204 hwc_rect_t new_cropR;
2205 new_cropR.left = tmp_cropL.left;
2206 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2207
2208 hwc_rect_t new_cropL;
2209 new_cropL.left = new_cropR.right;
2210 new_cropL.right = tmp_cropR.right;
2211
2212 tmp_cropL.left = new_cropL.left;
2213 tmp_cropL.right = new_cropL.right;
2214
2215 tmp_cropR.left = new_cropR.left;
2216 tmp_cropR.right = new_cropR.right;
2217
2218 }
2219
Saurabh Shah76fd6552013-03-14 14:45:38 -07002220 //For the mdp, since either we are pre-rotating or MDP does flips
2221 orient = OVERLAY_TRANSFORM_0;
2222 transform = 0;
2223
Saurabh Shahacf10202013-02-26 10:15:15 -08002224 //configure left mixer
2225 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002226 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002227 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2228 (ovutils::eBlending) getBlending(layer->blending));
2229
Saurabh Shahacf10202013-02-26 10:15:15 -08002230 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002231 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002232 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2233 return -1;
2234 }
2235 }
2236
2237 //configure right mixer
2238 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002239 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002240 static_cast<eRotFlags>(rotFlags),
2241 layer->planeAlpha,
2242 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002243 tmp_dstR.right = tmp_dstR.right - lSplit;
2244 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002245 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002246 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002247 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2248 return -1;
2249 }
2250 }
2251
2252 return 0;
2253}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002254
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002255int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer,
2256 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
2257 const eDest& lDest, const eDest& rDest,
2258 Rotator **rot) {
2259 private_handle_t *hnd = (private_handle_t *)layer->handle;
2260 if(!hnd) {
2261 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2262 return -1;
2263 }
2264 //Both pipes are configured to the same mixer
2265 eZorder lz = z;
2266 eZorder rz = (eZorder)(z + 1);
2267
2268 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2269
2270 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
2271 hwc_rect_t dst = layer->displayFrame;
2272 int transform = layer->transform;
2273 eTransform orient = static_cast<eTransform>(transform);
2274 int rotFlags = ROT_FLAGS_NONE;
2275 uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags);
2276 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
2277
2278 int downscale = getRotDownscale(ctx, layer);
2279 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
2280
2281 //XXX: Check if rotation is supported and valid for 3D
2282 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
2283 (*rot) = ctx->mRotMgr->getNext();
2284 if((*rot) == NULL) return -1;
2285 ctx->mLayerRotMap[dpy]->add(layer, *rot);
2286 //Configure rotator for pre-rotation
2287 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2288 ALOGE("%s: configRotator failed!", __FUNCTION__);
2289 return -1;
2290 }
2291 updateSource(orient, whf, crop, *rot);
2292 rotFlags |= ROT_PREROTATED;
2293 }
2294
2295 eMdpFlags mdpFlagsR = mdpFlagsL;
2296
2297 hwc_rect_t cropL = crop, dstL = dst;
2298 hwc_rect_t cropR = crop, dstR = dst;
2299 int hw_w = ctx->dpyAttr[dpy].xres;
2300 int hw_h = ctx->dpyAttr[dpy].yres;
2301
2302 if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R ||
2303 get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) {
2304 // Calculate Left rects
2305 // XXX: This assumes crop.right/2 is the center point of the video
2306 cropL.right = crop.right/2;
2307 dstL.left = dst.left/2;
2308 dstL.right = dst.right/2;
2309
2310 // Calculate Right rects
2311 cropR.left = crop.right/2;
2312 dstR.left = hw_w/2 + dst.left/2;
2313 dstR.right = hw_w/2 + dst.right/2;
2314 } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) {
2315 // Calculate Left rects
2316 cropL.bottom = crop.bottom/2;
2317 dstL.top = dst.top/2;
2318 dstL.bottom = dst.bottom/2;
2319
2320 // Calculate Right rects
2321 cropR.top = crop.bottom/2;
2322 dstR.top = hw_h/2 + dst.top/2;
2323 dstR.bottom = hw_h/2 + dst.bottom/2;
2324 } else {
2325 ALOGE("%s: Unsupported 3D mode ", __FUNCTION__);
2326 return -1;
2327 }
2328
2329 //For the mdp, since either we are pre-rotating or MDP does flips
2330 orient = OVERLAY_TRANSFORM_0;
2331 transform = 0;
2332
2333 //configure left pipe
2334 if(lDest != OV_INVALID) {
2335 PipeArgs pargL(mdpFlagsL, whf, lz,
2336 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2337 (ovutils::eBlending) getBlending(layer->blending));
2338
2339 if(configMdp(ctx->mOverlay, pargL, orient,
2340 cropL, dstL, metadata, lDest) < 0) {
2341 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2342 return -1;
2343 }
2344 }
2345
2346 //configure right pipe
2347 if(rDest != OV_INVALID) {
2348 PipeArgs pargR(mdpFlagsR, whf, rz,
2349 static_cast<eRotFlags>(rotFlags),
2350 layer->planeAlpha,
2351 (ovutils::eBlending) getBlending(layer->blending));
2352 if(configMdp(ctx->mOverlay, pargR, orient,
2353 cropR, dstR, metadata, rDest) < 0) {
2354 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2355 return -1;
2356 }
2357 }
2358
2359 return 0;
2360}
2361
radhakrishnac9a67412013-09-25 17:40:42 +05302362int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2363 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002364 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302365 Rotator **rot) {
2366 private_handle_t *hnd = (private_handle_t *)layer->handle;
2367 if(!hnd) {
2368 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2369 return -1;
2370 }
2371
2372 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2373
radhakrishnac9a67412013-09-25 17:40:42 +05302374 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2375 hwc_rect_t dst = layer->displayFrame;
2376 int transform = layer->transform;
2377 eTransform orient = static_cast<eTransform>(transform);
2378 const int downscale = 0;
2379 int rotFlags = ROT_FLAGS_NONE;
2380 //Splitting only YUV layer on primary panel needs different zorders
2381 //for both layers as both the layers are configured to single mixer
2382 eZorder lz = z;
2383 eZorder rz = (eZorder)(z + 1);
2384
2385 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302386 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302387
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002388 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002389 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2390 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002391 }
2392
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002393 /* Calculate the external display position based on MDP downscale,
2394 ActionSafe, and extorientation features. */
2395 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2396
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002397 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302398 trimLayer(ctx, dpy, transform, crop, dst);
2399
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002400 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302401 (*rot) = ctx->mRotMgr->getNext();
2402 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002403 ctx->mLayerRotMap[dpy]->add(layer, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302404 //Configure rotator for pre-rotation
2405 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2406 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302407 return -1;
2408 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002409 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302410 rotFlags |= ROT_PREROTATED;
2411 }
2412
2413 eMdpFlags mdpFlagsR = mdpFlagsL;
2414 int lSplit = dst.left + (dst.right - dst.left)/2;
2415
2416 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2417 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2418
2419 if(lDest != OV_INVALID) {
2420 tmp_cropL = crop;
2421 tmp_dstL = dst;
2422 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2423 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2424 }
2425 if(rDest != OV_INVALID) {
2426 tmp_cropR = crop;
2427 tmp_dstR = dst;
2428 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2429 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2430 }
2431
2432 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2433
2434 //When buffer is H-flipped, contents of mixer config also needs to swapped
2435 //Not needed if the layer is confined to one half of the screen.
2436 //If rotator has been used then it has also done the flips, so ignore them.
2437 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2438 && rDest != OV_INVALID && (*rot) == NULL) {
2439 hwc_rect_t new_cropR;
2440 new_cropR.left = tmp_cropL.left;
2441 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2442
2443 hwc_rect_t new_cropL;
2444 new_cropL.left = new_cropR.right;
2445 new_cropL.right = tmp_cropR.right;
2446
2447 tmp_cropL.left = new_cropL.left;
2448 tmp_cropL.right = new_cropL.right;
2449
2450 tmp_cropR.left = new_cropR.left;
2451 tmp_cropR.right = new_cropR.right;
2452
2453 }
2454
2455 //For the mdp, since either we are pre-rotating or MDP does flips
2456 orient = OVERLAY_TRANSFORM_0;
2457 transform = 0;
2458
2459 //configure left half
2460 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002461 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302462 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2463 (ovutils::eBlending) getBlending(layer->blending));
2464
2465 if(configMdp(ctx->mOverlay, pargL, orient,
2466 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2467 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2468 return -1;
2469 }
2470 }
2471
2472 //configure right half
2473 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002474 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302475 static_cast<eRotFlags>(rotFlags),
2476 layer->planeAlpha,
2477 (ovutils::eBlending) getBlending(layer->blending));
2478 if(configMdp(ctx->mOverlay, pargR, orient,
2479 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2480 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2481 return -1;
2482 }
2483 }
2484
2485 return 0;
2486}
2487
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002488bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302489 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002490 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002491 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302492 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302493 * in LINE and BLOCK modes for writeback panels.
2494 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002495 if(dpy == HWC_DISPLAY_PRIMARY)
2496 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002497 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302498 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2499 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002500 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002501 return true;
2502}
2503
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002504int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2505 //Default even split for all displays with high res
2506 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2507 if(dpy == HWC_DISPLAY_PRIMARY &&
2508 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2509 //Override if split published by driver for primary
2510 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2511 }
2512 return lSplit;
2513}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002514
Saurabh Shah88e4d272013-09-03 13:31:29 -07002515bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302516 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Jeykumar Sankarandc76ba82015-01-28 14:51:50 -08002517 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002518 return true;
2519 }
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302520 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002521 return true;
2522 }
2523 return false;
2524}
2525
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002526//clear prev layer prop flags and realloc for current frame
2527void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2528 if(ctx->layerProp[dpy]) {
2529 delete[] ctx->layerProp[dpy];
2530 ctx->layerProp[dpy] = NULL;
2531 }
2532 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2533}
2534
Ramakant Singh0def28c2014-03-28 20:43:13 +05302535bool isAbcInUse(hwc_context_t *ctx){
2536 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2537}
2538
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002539void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2540 if (ohnd != NULL && ohnd->base) {
2541 char dumpFilename[PATH_MAX];
2542 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002543 int width = getWidth(ohnd);
2544 int height = getHeight(ohnd);
2545 int format = ohnd->format;
2546 //dummy aligned w & h.
2547 int alW = 0, alH = 0;
2548 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002549 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2550 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002551 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2552 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002553 FILE* fp = fopen(dumpFilename, "w+");
2554 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002555 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002556 fclose(fp);
2557 }
2558 ALOGD("Buffer[%s] Dump to %s: %s",
2559 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2560 }
2561}
2562
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002563bool isGLESComp(hwc_context_t *ctx,
2564 hwc_display_contents_1_t* list) {
2565 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2566 for(int index = 0; index < numAppLayers; index++) {
2567 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2568 if(layer->compositionType == HWC_FRAMEBUFFER)
2569 return true;
2570 }
2571 return false;
2572}
2573
2574void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2575 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002576 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002577 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002578
2579#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002580 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2581 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2582 hint to default if the previous composition is GPU or current GPU
2583 composition is due to idle fallback */
2584 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2585 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2586 if(!gpuHint->mEGLDisplay) {
2587 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2588 return;
2589 }
2590 gpuHint->mEGLContext = eglGetCurrentContext();
2591 if(!gpuHint->mEGLContext) {
2592 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2593 return;
2594 }
2595 }
2596 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002597 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2598 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002599 EGLint attr_list[] = {EGL_GPU_HINT_1,
2600 EGL_GPU_LEVEL_3,
2601 EGL_NONE };
2602 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2603 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2604 gpuHint->mEGLContext, attr_list)) {
2605 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2606 } else {
2607 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002608 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002609 }
2610 } else {
2611 EGLint attr_list[] = {EGL_GPU_HINT_1,
2612 EGL_GPU_LEVEL_0,
2613 EGL_NONE };
2614 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2615 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2616 gpuHint->mEGLContext, attr_list)) {
2617 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2618 } else {
2619 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2620 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002621 if(MDPComp::isIdleFallback()) {
2622 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2623 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002624 }
2625 } else {
2626 /* set the GPU hint flag to default for MDP composition */
2627 EGLint attr_list[] = {EGL_GPU_HINT_1,
2628 EGL_GPU_LEVEL_0,
2629 EGL_NONE };
2630 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2631 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2632 gpuHint->mEGLContext, attr_list)) {
2633 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2634 } else {
2635 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2636 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002637 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002638 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002639#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002640}
2641
Sushil Chauhandefd3522014-05-13 18:17:12 -07002642bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2643 // To be peripheral, 3 boundaries should match.
2644 uint8_t eqBounds = 0;
2645 if (rect1.left == rect2.left)
2646 eqBounds++;
2647 if (rect1.top == rect2.top)
2648 eqBounds++;
2649 if (rect1.right == rect2.right)
2650 eqBounds++;
2651 if (rect1.bottom == rect2.bottom)
2652 eqBounds++;
2653 return (eqBounds == 3);
2654}
2655
Krishna Chaitanya Parimidb992fd2014-10-22 20:50:50 +05302656void processBootAnimCompleted(hwc_context_t *ctx) {
2657 char value[PROPERTY_VALUE_MAX];
2658 int boot_finished = 0, ret = -1;
2659 int (*applyMode)(int) = NULL;
2660 void *modeHandle = NULL;
2661
2662 // Reading property set on boot finish in SF
2663 property_get("service.bootanim.exit", value, "0");
2664 boot_finished = atoi(value);
2665 if (!boot_finished)
2666 return;
2667
2668 modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW);
2669 if (modeHandle) {
2670 *(void **)&applyMode = dlsym(modeHandle, "applyDefaults");
2671 if (applyMode) {
2672 ret = applyMode(HWC_DISPLAY_PRIMARY);
2673 if (ret)
2674 ALOGD("%s: Not able to apply default mode", __FUNCTION__);
2675 } else {
2676 ALOGE("%s: No symbol applyDefaults found", __FUNCTION__);
2677 }
2678 dlclose(modeHandle);
2679 } else {
2680 ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__);
2681 }
2682
2683 ctx->mBootAnimCompleted = true;
2684}
2685
Saurabh Shahcd018352014-11-11 13:54:19 -08002686void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy,
2687 const private_handle_t *hnd,
2688 const hwc_rect_t& crop, const hwc_rect_t& dst,
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002689 const int& transform,const int& downscale,
2690 ovutils::eMdpFlags& mdpFlags) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002691 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302692 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Saurabh Shahcd018352014-11-11 13:54:19 -08002693 if(not mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002694 return;
2695 }
Saurabh Shahcd018352014-11-11 13:54:19 -08002696 //Disabled at runtime
2697 if(not ctx->mBWCEnabled) return;
2698 //BWC not supported with rot-downscale
2699 if(downscale) return;
2700 //Not enabled for secondary displays
2701 if(dpy) return;
2702 //Not enabled for non-video buffers
2703 if(not isYuvBuffer(hnd)) return;
2704
Saurabh Shahb6810df2014-06-17 16:00:22 -07002705 int src_w = crop.right - crop.left;
2706 int src_h = crop.bottom - crop.top;
2707 int dst_w = dst.right - dst.left;
2708 int dst_h = dst.bottom - dst.top;
2709 if(transform & HAL_TRANSFORM_ROT_90) {
2710 swap(src_w, src_h);
2711 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002712 //src width > MAX mixer supported dim
Jeykumar Sankaran39305802014-12-12 17:55:57 -08002713 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002714 return;
2715 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002716 //Decimation necessary, cannot use BWC. H/W requirement.
2717 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002718 uint8_t horzDeci = 0;
2719 uint8_t vertDeci = 0;
2720 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2721 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002722 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002723 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002724
2725 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2726}
2727
Saurabh Shah23a813c2013-03-20 16:58:12 -07002728void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302729 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002730 mLayer[mCount] = layer;
2731 mRot[mCount] = rot;
2732 mCount++;
2733}
2734
2735void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302736 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002737 mLayer[i] = 0;
2738 mRot[i] = 0;
2739 }
2740 mCount = 0;
2741}
2742
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002743void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002744 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002745 reset();
2746}
2747
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302748bool LayerRotMap::isRotCached(uint32_t index) const {
2749 overlay::Rotator* rot = getRot(index);
2750 hwc_layer_1_t* layer = getLayer(index);
2751
2752 if(rot and layer and layer->handle) {
2753 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2754 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2755 }
2756 return false;
2757}
2758
Saurabh Shah23a813c2013-03-20 16:58:12 -07002759void LayerRotMap::setReleaseFd(const int& fence) {
2760 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302761 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2762 /* Ensure that none of the above (Rotator-instance,
2763 * layer and layer-handle) are NULL*/
2764 if(isRotCached(i))
2765 mRot[i]->setPrevBufReleaseFd(dup(fence));
2766 else
2767 mRot[i]->setCurrBufReleaseFd(dup(fence));
2768 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002769 }
2770}
2771
Jeykumar Sankaranaedd1432015-01-15 11:25:03 -08002772hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) {
2773 int lRoiWidth = 0, rRoiWidth = 0;
2774 int half_frame_width = fullFrame.right/2;
2775
2776 hwc_rect lFrame = fullFrame;
2777 hwc_rect rFrame = fullFrame;
2778 lFrame.right = (lFrame.right - lFrame.left)/2;
2779 rFrame.left = lFrame.right;
2780
2781 hwc_rect lRoi = getIntersection(roi, lFrame);
2782 hwc_rect rRoi = getIntersection(roi, rFrame);
2783
2784 lRoiWidth = lRoi.right - lRoi.left;
2785 rRoiWidth = rRoi.right - rRoi.left;
2786
2787 if(lRoiWidth && rRoiWidth) {
2788 if(lRoiWidth < rRoiWidth)
2789 roi.left = half_frame_width - rRoiWidth;
2790 else
2791 roi.right = half_frame_width + lRoiWidth;
2792 }
2793 return roi;
2794}
2795
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002796void resetROI(hwc_context_t *ctx, const int dpy) {
2797 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2798 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
Jeykumar Sankaranf7124b92015-02-26 10:34:35 -08002799
2800 /* When source split is enabled, both the panels are calibrated
2801 * in a single coordinate system. So only one ROI is generated
2802 * for the whole panel extending equally from the midpoint and
2803 * populated for the left side. */
2804 if(!qdutils::MDPVersion::getInstance().isSrcSplit() &&
2805 isDisplaySplit(ctx, dpy)) {
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002806 const int lSplit = getLeftSplit(ctx, dpy);
2807 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2808 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2809 } else {
2810 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2811 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2812 }
2813}
2814
2815hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002816{
2817 if(!isValidRect(roi))
2818 return roi;
2819
2820 struct hwc_rect t_roi = roi;
2821
2822 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2823 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2824 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2825 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2826 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002827 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002828
2829 /* Align to minimum width recommended by the panel */
2830 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2831 if((t_roi.left + MIN_WIDTH) > boundary.right)
2832 t_roi.left = t_roi.right - MIN_WIDTH;
2833 else
2834 t_roi.right = t_roi.left + MIN_WIDTH;
2835 }
2836
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002837 /* Align to minimum height recommended by the panel */
2838 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2839 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2840 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2841 else
2842 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2843 }
2844
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002845 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002846 if(LEFT_ALIGN)
2847 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2848
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002849 if(WIDTH_ALIGN) {
2850 int width = t_roi.right - t_roi.left;
2851 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2852 t_roi.right = t_roi.left + width;
2853
2854 if(t_roi.right > boundary.right) {
2855 t_roi.right = boundary.right;
2856 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002857
2858 if(LEFT_ALIGN)
2859 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002860 }
2861 }
2862
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002863
2864 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002865 if(TOP_ALIGN)
2866 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2867
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002868 if(HEIGHT_ALIGN) {
2869 int height = t_roi.bottom - t_roi.top;
2870 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2871 t_roi.bottom = t_roi.top + height;
2872
2873 if(t_roi.bottom > boundary.bottom) {
2874 t_roi.bottom = boundary.bottom;
2875 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002876
2877 if(TOP_ALIGN)
2878 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002879 }
2880 }
2881
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002882
2883 return t_roi;
2884}
2885
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002886void handle_pause(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002887 if(ctx->dpyAttr[dpy].connected) {
2888 ctx->mDrawLock.lock();
2889 ctx->dpyAttr[dpy].isActive = true;
2890 ctx->dpyAttr[dpy].isPause = true;
2891 ctx->mDrawLock.unlock();
2892 ctx->proc->invalidate(ctx->proc);
2893
2894 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2895 * 2 / 1000);
2896
2897 // At this point all the pipes used by External have been
2898 // marked as UNSET.
2899 ctx->mDrawLock.lock();
2900 // Perform commit to unstage the pipes.
2901 if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2902 ALOGE("%s: display commit fail! for %d dpy",
2903 __FUNCTION__, dpy);
2904 }
2905 ctx->mDrawLock.unlock();
2906 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002907 }
2908 return;
2909}
2910
2911void handle_resume(hwc_context_t* ctx, int dpy) {
Arun Kumar K.R33888f52014-10-09 15:56:33 -07002912 if(ctx->dpyAttr[dpy].connected) {
2913 ctx->mDrawLock.lock();
2914 ctx->dpyAttr[dpy].isConfiguring = true;
2915 ctx->dpyAttr[dpy].isActive = true;
2916 ctx->mDrawLock.unlock();
2917 ctx->proc->invalidate(ctx->proc);
2918
2919 usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
2920 * 2 / 1000);
2921
2922 //At this point external has all the pipes it would need.
2923 ctx->mDrawLock.lock();
2924 ctx->dpyAttr[dpy].isPause = false;
2925 ctx->mDrawLock.unlock();
2926 ctx->proc->invalidate(ctx->proc);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002927 }
2928 return;
2929}
2930
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002931void clearPipeResources(hwc_context_t* ctx, int dpy) {
2932 if(ctx->mOverlay) {
2933 ctx->mOverlay->configBegin();
2934 ctx->mOverlay->configDone();
2935 }
2936 if(ctx->mRotMgr) {
2937 ctx->mRotMgr->clear();
2938 }
2939 // Call a display commit to ensure that pipes and associated
2940 // fd's are cleaned up.
2941 if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) {
2942 ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy);
2943 }
2944}
2945
2946// Handles online events when HDMI is the primary display. In particular,
2947// online events for hdmi connected before AND after boot up and HWC init.
2948void handle_online(hwc_context_t* ctx, int dpy) {
2949 // Close the current fd if it was opened earlier on when HWC
2950 // was initialized.
2951 if (ctx->dpyAttr[dpy].fd >= 0) {
2952 close(ctx->dpyAttr[dpy].fd);
2953 ctx->dpyAttr[dpy].fd = -1;
2954 }
2955 // TODO: If HDMI is connected after the display has booted up,
2956 // and the best configuration is different from the default
2957 // then we need to deal with this appropriately.
Arun Kumar K.R205df772015-02-20 18:45:58 -08002958 int error = ctx->mHDMIDisplay->configure();
2959 if (error < 0) {
2960 ALOGE("Error opening FrameBuffer");
2961 return;
2962 }
Tatenda Chipeperekwad80b6172014-09-23 11:29:37 -07002963 updateDisplayInfo(ctx, dpy);
2964 initCompositionResources(ctx, dpy);
2965 ctx->dpyAttr[dpy].connected = true;
2966}
2967
2968// Handles offline events for HDMI. This can be used for offline events
2969// initiated by the HDMI driver and the CEC framework.
2970void handle_offline(hwc_context_t* ctx, int dpy) {
2971 destroyCompositionResources(ctx, dpy);
2972 // Clear all pipe resources and call a display commit to ensure
2973 // that all the fd's are closed. This will ensure that the HDMI
2974 // core turns off and that we receive an event the next time the
2975 // cable is connected.
2976 if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) {
2977 clearPipeResources(ctx, dpy);
2978 }
2979 ctx->mHDMIDisplay->teardown();
2980 resetDisplayInfo(ctx, dpy);
2981 ctx->dpyAttr[dpy].connected = false;
2982 ctx->dpyAttr[dpy].isActive = false;
2983}
2984
Naseer Ahmed6bbd0a12015-01-23 11:57:10 -05002985int convertS3DFormatToMode(int s3DFormat) {
2986 int ret;
2987 switch(s3DFormat) {
2988 case HAL_3D_SIDE_BY_SIDE_L_R:
2989 case HAL_3D_SIDE_BY_SIDE_R_L:
2990 ret = HDMI_S3D_SIDE_BY_SIDE;
2991 break;
2992 case HAL_3D_TOP_BOTTOM:
2993 ret = HDMI_S3D_TOP_AND_BOTTOM;
2994 break;
2995 default:
2996 ret = HDMI_S3D_NONE;
2997 }
2998 return ret;
2999}
3000
3001bool needs3DComposition(hwc_context_t* ctx, int dpy) {
3002 return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected &&
3003 ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE);
3004}
3005
3006void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) {
3007 if (ctx->dpyAttr[dpy].s3dMode != s3dMode) {
3008 ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode);
3009 if(ctx->mHDMIDisplay->configure3D(s3dMode)) {
3010 ctx->dpyAttr[dpy].s3dMode = s3dMode;
3011 }
3012 }
3013}
3014
3015bool displaySupports3D(hwc_context_t* ctx, int dpy) {
3016 return ((dpy == HWC_DISPLAY_EXTERNAL) ||
3017 ((dpy == HWC_DISPLAY_PRIMARY) &&
3018 ctx->mHDMIDisplay->isHDMIPrimaryDisplay()));
3019}
3020
3021
Saurabh Shahacf10202013-02-26 10:15:15 -08003022};//namespace qhwc