blob: 7e77d956d86a208c22651fad3213cdfa4b73d6fe [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>
Saurabh Shah86c17292013-02-08 15:24:13 -080047
48using namespace qClient;
49using namespace qService;
50using namespace android;
Saurabh Shahacf10202013-02-26 10:15:15 -080051using namespace overlay;
52using namespace overlay::utils;
53namespace ovutils = overlay::utils;
Saurabh Shah86c17292013-02-08 15:24:13 -080054
Saurabh Shah74eff4d2014-03-28 16:33:13 -070055#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070056#ifdef __cplusplus
57extern "C" {
58#endif
59
60EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx,
61 EGLint *attrib_list);
62#define EGL_GPU_HINT_1 0x32D0
63#define EGL_GPU_HINT_2 0x32D1
64
65#define EGL_GPU_LEVEL_0 0x0
66#define EGL_GPU_LEVEL_1 0x1
67#define EGL_GPU_LEVEL_2 0x2
68#define EGL_GPU_LEVEL_3 0x3
69#define EGL_GPU_LEVEL_4 0x4
70#define EGL_GPU_LEVEL_5 0x5
71
72#ifdef __cplusplus
73}
74#endif
Saurabh Shah74eff4d2014-03-28 16:33:13 -070075#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -070076
Ramakant Singh98c533c2014-09-30 19:01:54 +053077#define PROP_DEFAULT_APPBUFFER "ro.sf.default_app_buffer"
78#define MAX_RAM_SIZE 512*1024*1024
79#define qHD_WIDTH 540
80
81
Naseer Ahmed29a26812012-06-14 00:56:20 -070082namespace qhwc {
Naseer Ahmed72cf9762012-07-21 12:17:13 -070083
Arun Kumar K.Ra727a882014-08-20 17:14:26 -070084//Std refresh rates for digital videos- 24p, 30p and 48p
85uint32_t stdRefreshRates[] = { 30, 24, 48 };
86
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053087bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres)
88{
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +053089 return !((xres > qdutils::MDPVersion::getInstance().getMaxMixerWidth() &&
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053090 !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) ||
91 (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES));
92}
93
Praveena Pachipulusu49d62062014-06-06 19:22:23 +053094void changeResolution(hwc_context_t *ctx, int xres_orig, int yres_orig,
95 int width, int height) {
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053096 //Store original display resolution.
Dileep Kumar Reddie351d842014-03-25 10:39:21 +053097 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_orig;
98 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_orig;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +053099 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = false;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530100 char property[PROPERTY_VALUE_MAX] = {'\0'};
101 char *yptr = NULL;
102 if (property_get("debug.hwc.fbsize", property, NULL) > 0) {
103 yptr = strcasestr(property,"x");
Dileep Kumar Reddie351d842014-03-25 10:39:21 +0530104 int xres_new = atoi(property);
105 int yres_new = atoi(yptr + 1);
106 if (isValidResolution(ctx,xres_new,yres_new) &&
107 xres_new != xres_orig && yres_new != yres_orig) {
108 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_new;
109 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_new;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530110 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true;
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530111
112 //Caluculate DPI according to changed resolution.
113 float xdpi = ((float)xres_new * 25.4f) / (float)width;
114 float ydpi = ((float)yres_new * 25.4f) / (float)height;
115 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
116 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530117 }
118 }
119}
120
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700121// Initialize hdmi display attributes based on
122// hdmi display class state
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700123void updateDisplayInfo(hwc_context_t* ctx, int dpy) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700124 ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd();
125 ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth();
126 ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight();
127 ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode();
128 ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod();
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700129 ctx->mViewFrame[dpy].left = 0;
130 ctx->mViewFrame[dpy].top = 0;
131 ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres;
132 ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres;
133}
134
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700135// Reset hdmi display attributes and list stats structures
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700136void resetDisplayInfo(hwc_context_t* ctx, int dpy) {
137 memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy]));
138 memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy]));
139 // We reset the fd to -1 here but External display class is responsible
140 // for it when the display is disconnected. This is handled as part of
141 // EXTERNAL_OFFLINE event.
142 ctx->dpyAttr[dpy].fd = -1;
143}
144
145// Initialize composition resources
146void initCompositionResources(hwc_context_t* ctx, int dpy) {
147 ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy);
148 ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy);
149}
150
151void destroyCompositionResources(hwc_context_t* ctx, int dpy) {
152 if(ctx->mFBUpdate[dpy]) {
153 delete ctx->mFBUpdate[dpy];
154 ctx->mFBUpdate[dpy] = NULL;
155 }
156 if(ctx->mMDPComp[dpy]) {
157 delete ctx->mMDPComp[dpy];
158 ctx->mMDPComp[dpy] = NULL;
159 }
160}
161
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800162static int openFramebufferDevice(hwc_context_t *ctx)
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700163{
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800164 struct fb_fix_screeninfo finfo;
165 struct fb_var_screeninfo info;
166
167 int fb_fd = openFb(HWC_DISPLAY_PRIMARY);
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530168 if(fb_fd < 0) {
169 ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno));
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800170 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530171 }
172
173 if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) {
174 ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__,
175 strerror(errno));
176 close(fb_fd);
177 return -errno;
178 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800179
180 if (int(info.width) <= 0 || int(info.height) <= 0) {
181 // the driver doesn't return that information
182 // default to 160 dpi
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530183 info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f);
184 info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700185 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800186
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530187 float xdpi = ((float)info.xres * 25.4f) / (float)info.width;
188 float ydpi = ((float)info.yres * 25.4f) / (float)info.height;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800189
190#ifdef MSMFB_METADATA_GET
191 struct msmfb_metadata metadata;
192 memset(&metadata, 0 , sizeof(metadata));
193 metadata.op = metadata_op_frame_rate;
194
195 if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) {
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530196 ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__,
197 strerror(errno));
198 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800199 return -errno;
200 }
201
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530202 float fps = (float)metadata.data.panel_frame_rate;
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800203#else
204 //XXX: Remove reserved field usage on all baselines
205 //The reserved[3] field is used to store FPS by the driver.
206 float fps = info.reserved[3] & 0xFF;
207#endif
208
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530209 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
210 ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__,
211 strerror(errno));
212 close(fb_fd);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800213 return -errno;
Sravan Kumar D.V.N78f51e72013-04-16 10:24:55 +0530214 }
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800215
216 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd;
217 //xres, yres may not be 32 aligned
218 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8);
219 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres;
220 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres;
221 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi;
222 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700223 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps;
224 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530225 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period =
226 (uint32_t)(1000000000l / fps);
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800227
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530228 //To change resolution of primary display
Praveena Pachipulusu49d62062014-06-06 19:22:23 +0530229 changeResolution(ctx, info.xres, info.yres, info.width, info.height);
Dileep Kumar Reddibf2678b2014-01-29 15:33:32 +0530230
Naseer Ahmed22616d92013-05-15 17:20:26 -0400231 //Unblank primary on first boot
232 if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) {
233 ALOGE("%s: Failed to unblank display", __FUNCTION__);
234 return -errno;
235 }
236 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true;
237
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800238 return 0;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700239}
240
Ramakant Singh98c533c2014-09-30 19:01:54 +0530241static void changeDefaultAppBufferCount() {
242 struct sysinfo info;
243 unsigned long int ramSize = 0;
244 if (!sysinfo(&info)) {
245 ramSize = info.totalram ;
246 }
247 int fb_fd = -1;
248 struct fb_var_screeninfo sInfo ={0};
249 fb_fd = open("/dev/graphics/fb0", O_RDONLY);
250 if (fb_fd >=0) {
251 ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo);
252 close(fb_fd);
253 }
254 if ((ramSize && ramSize < MAX_RAM_SIZE) &&
255 (sInfo.xres && sInfo.xres <= qHD_WIDTH )) {
256 property_set(PROP_DEFAULT_APPBUFFER, "2");
257 }
258}
259
Naseer Ahmed29a26812012-06-14 00:56:20 -0700260void initContext(hwc_context_t *ctx)
261{
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700262 openFramebufferDevice(ctx);
Raj kamal59fea562014-04-01 16:52:19 +0530263 char value[PROPERTY_VALUE_MAX];
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700264 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion();
265 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay();
266 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800267 overlay::Overlay::initOverlay();
268 ctx->mOverlay = overlay::Overlay::getInstance();
Saurabh Shah7a606842013-12-11 14:36:04 -0800269 ctx->mRotMgr = RotMgr::getInstance();
Sushil Chauhan07a2c762013-03-06 15:36:49 -0800270
Ramakant Singh98c533c2014-09-30 19:01:54 +0530271 //default_app_buffer for ferrum
272 if (ctx->mMDP.version == qdutils::MDP_V3_0_5) {
273 changeDefaultAppBufferCount();
274 }
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700275 // Initialize composition objects for the primary display
276 initCompositionResources(ctx, HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800277
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800278 // Check if the target supports copybit compostion (dyn/mdp) to
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800279 // decide if we need to open the copybit module.
280 int compositionType =
281 qdutils::QCCompositionType::getInstance().getCompositionType();
282
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800283 // Only MDP copybit is used
284 if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN |
285 qdutils::COMPOSITION_TYPE_MDP)) &&
Ramakant Singhb4106a12014-10-07 18:06:56 +0530286 ((qdutils::MDPVersion::getInstance().getMDPVersion() ==
287 qdutils::MDP_V3_0_4) ||
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800288 (qdutils::MDPVersion::getInstance().getMDPVersion() ==
Ramakant Singhb4106a12014-10-07 18:06:56 +0530289 qdutils::MDP_V3_0_5))) {
Arun Kumar K.R9fc89972014-01-02 17:01:02 -0800290 ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx,
291 HWC_DISPLAY_PRIMARY);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800292 }
293
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700294 ctx->mHDMIDisplay = new HDMIDisplay();
295 // Send the primary resolution to the hdmi display class
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700296 // to be used for MDP scaling functionality
297 uint32_t priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
298 uint32_t priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700299 ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH);
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -0700300 ctx->mHWCVirtual = new HWCVirtualVDS();
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700301 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false;
302 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false;
303 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false;
304 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700305 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false;
306 ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false;
307 ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false;
Jeykumar Sankaran85977e32013-02-25 17:06:08 -0800308
Jeykumar Sankaran27dee262013-08-01 17:09:54 -0700309 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true;
Arun Kumar K.R81f3f2e2014-06-23 14:03:12 -0700310 //Initialize the primary display viewFrame info
311 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0;
312 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0;
313 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right =
314 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
315 ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom =
316 (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
Raj kamal59fea562014-04-01 16:52:19 +0530317
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700318 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700319 ctx->mHwcDebug[i] = new HwcDebug(i);
Saurabh Shah23a813c2013-03-20 16:58:12 -0700320 ctx->mLayerRotMap[i] = new LayerRotMap();
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700321 ctx->mAnimationState[i] = ANIMATION_STOPPED;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800322 ctx->dpyAttr[i].mActionSafePresent = false;
323 ctx->dpyAttr[i].mAsWidthRatio = 0;
324 ctx->dpyAttr[i].mAsHeightRatio = 0;
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700325 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700326
Raj Kamal9ed3d6b2014-02-07 16:15:17 +0530327 for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
328 ctx->mPrevHwLayerCount[i] = 0;
329 }
330
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500331 MDPComp::init(ctx);
Saurabh Shahc4f1fa62013-09-03 13:12:14 -0700332 ctx->mAD = new AssertiveDisplay(ctx);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700333
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400334 ctx->vstate.enable = false;
Naseer Ahmed56601cd2013-03-05 11:34:14 -0500335 ctx->vstate.fakevsync = false;
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700336 ctx->mExtOrientation = 0;
Raj Kamal52b4fdb2014-01-27 19:35:13 +0530337 ctx->numActiveDisplays = 1;
Saurabh Shah86c17292013-02-08 15:24:13 -0800338
339 //Right now hwc starts the service but anybody could do it, or it could be
340 //independent process as well.
341 QService::init();
342 sp<IQClient> client = new QClient(ctx);
Charles Bindab39382014-06-30 10:34:30 -0700343 android::sp<qService::IQService> qservice_sp = interface_cast<IQService>(
Saurabh Shah86c17292013-02-08 15:24:13 -0800344 defaultServiceManager()->getService(
Charles Bindab39382014-06-30 10:34:30 -0700345 String16("display.qservice")));
346 if (qservice_sp.get()) {
347 qservice_sp->connect(client);
348 } else {
349 ALOGE("%s: Failed to acquire service pointer", __FUNCTION__);
350 return ;
351 }
Saurabh Shah86c17292013-02-08 15:24:13 -0800352
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -0700353 // Initialize device orientation to its default orientation
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700354 ctx->deviceOrientation = 0;
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700355 ctx->mBufferMirrorMode = false;
Zohaib Alam1bb65612013-09-28 03:38:20 -0400356
Ramakant Singh0def28c2014-03-28 20:43:13 +0530357 ctx->enableABC = false;
358 property_get("debug.sf.hwc.canUseABC", value, "0");
359 ctx->enableABC = atoi(value) ? true : false;
360
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700361 // Initialize gpu perfomance hint related parameters
362 property_get("sys.hwc.gpu_perf_mode", value, "0");
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700363#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700364 ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false;
365
366 ctx->mGPUHintInfo.mEGLDisplay = NULL;
367 ctx->mGPUHintInfo.mEGLContext = NULL;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -0700368 ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -0700369 ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
Saurabh Shah74eff4d2014-03-28 16:33:13 -0700370#endif
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700371 // Read the system property to determine if windowboxing feature is enabled.
372 ctx->mWindowboxFeature = false;
373 if(property_get("sys.hwc.windowbox_feature", value, "false")
374 && !strcmp(value, "true")) {
375 ctx->mWindowboxFeature = true;
376 }
377
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -0700378 memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo));
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700379 ALOGI("Initializing Qualcomm Hardware Composer");
Naseer Ahmed96c4c952012-07-25 18:27:14 -0700380 ALOGI("MDP version: %d", ctx->mMDP.version);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700381}
382
383void closeContext(hwc_context_t *ctx)
384{
Naseer Ahmed758bfc52012-11-28 17:02:08 -0500385 if(ctx->mOverlay) {
386 delete ctx->mOverlay;
387 ctx->mOverlay = NULL;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700388 }
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700389
Saurabh Shahacf10202013-02-26 10:15:15 -0800390 if(ctx->mRotMgr) {
391 delete ctx->mRotMgr;
392 ctx->mRotMgr = NULL;
393 }
394
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700395 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -0800396 if(ctx->mCopyBit[i]) {
397 delete ctx->mCopyBit[i];
398 ctx->mCopyBit[i] = NULL;
399 }
400 }
401
Jeykumar Sankaranc1f86822013-02-20 18:32:01 -0800402 if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700403 close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd);
404 ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1;
Naseer Ahmed29a26812012-06-14 00:56:20 -0700405 }
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700406
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700407 if(ctx->mHDMIDisplay) {
408 delete ctx->mHDMIDisplay;
409 ctx->mHDMIDisplay = NULL;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700410 }
Naseer Ahmedff4f0252012-10-01 13:03:01 -0400411
Amara Venkata Mastan Manoj Kumar7fb13272013-07-01 13:59:34 -0700412 for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700413 destroyCompositionResources(ctx, i);
414
Ramkumar Radhakrishnand224a1a2013-04-05 17:46:55 -0700415 if(ctx->mHwcDebug[i]) {
416 delete ctx->mHwcDebug[i];
417 ctx->mHwcDebug[i] = NULL;
418 }
Saurabh Shah23a813c2013-03-20 16:58:12 -0700419 if(ctx->mLayerRotMap[i]) {
420 delete ctx->mLayerRotMap[i];
421 ctx->mLayerRotMap[i] = NULL;
422 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800423 }
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -0800424 if(ctx->mHWCVirtual) {
425 delete ctx->mHWCVirtual;
426 ctx->mHWCVirtual = NULL;
427 }
Saurabh Shaha9da08f2013-07-03 13:27:53 -0700428 if(ctx->mAD) {
429 delete ctx->mAD;
430 ctx->mAD = NULL;
431 }
Saurabh Shahcf053c62012-12-13 12:32:55 -0800432
Saurabh Shahcbf7ccc2012-12-19 16:45:51 -0800433
Naseer Ahmed29a26812012-06-14 00:56:20 -0700434}
435
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700436//Helper to roundoff the refreshrates
437static uint32_t roundOff(uint32_t refreshRate) {
438 int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
439 uint32_t rate = refreshRate;
440 for(int i=0; i< count; i++) {
441 if(abs(stdRefreshRates[i] - refreshRate) < 2) {
442 // Most likely used for video, the fps can fluctuate
443 // Ex: b/w 29 and 30 for 30 fps clip
444 rate = stdRefreshRates[i];
445 break;
446 }
447 }
448 return rate;
449}
450
451//Helper func to set the dyn fps
452void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) {
453 //Update only if different
454 if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate)
455 return;
456 const int fbNum = Overlay::getFbForDpy(dpy);
457 char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH];
458 snprintf (sysfsPath, sizeof(sysfsPath),
459 "/sys/class/graphics/fb%d/dynamic_fps", fbNum);
460
461 int fd = open(sysfsPath, O_WRONLY);
462 if(fd >= 0) {
463 char str[64];
464 snprintf(str, sizeof(str), "%d", refreshRate);
465 ssize_t ret = write(fd, str, strlen(str));
466 if(ret < 0) {
467 ALOGE("%s: Failed to write %d with error %s",
468 __FUNCTION__, refreshRate, strerror(errno));
469 } else {
470 ctx->dpyAttr[dpy].dynRefreshRate = refreshRate;
471 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps",
472 __FUNCTION__, refreshRate);
473 }
474 close(fd);
475 } else {
476 ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath,
477 strerror(errno));
478 }
479}
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500480
481void dumpsys_log(android::String8& buf, const char* fmt, ...)
Naseer Ahmed29a26812012-06-14 00:56:20 -0700482{
Naseer Ahmed1d183f52012-11-26 12:35:16 -0500483 va_list varargs;
484 va_start(varargs, fmt);
485 buf.appendFormatV(fmt, varargs);
486 va_end(varargs);
Naseer Ahmed29a26812012-06-14 00:56:20 -0700487}
488
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700489int getExtOrientation(hwc_context_t* ctx) {
490 int extOrient = ctx->mExtOrientation;
491 if(ctx->mBufferMirrorMode)
492 extOrient = getMirrorModeOrientation(ctx);
493 return extOrient;
494}
495
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800496/* Calculates the destination position based on the action safe rectangle */
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700497void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) {
498 // Position
499 int x = rect.left, y = rect.top;
500 int w = rect.right - rect.left;
501 int h = rect.bottom - rect.top;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800502
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800503 if(!ctx->dpyAttr[dpy].mActionSafePresent)
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800504 return;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800505 // Read action safe properties
506 int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio;
507 int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio;
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700508
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800509 float wRatio = 1.0;
510 float hRatio = 1.0;
511 float xRatio = 1.0;
512 float yRatio = 1.0;
513
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700514 uint32_t fbWidth = ctx->dpyAttr[dpy].xres;
515 uint32_t fbHeight = ctx->dpyAttr[dpy].yres;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700516 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
517 // if MDP scaling mode is enabled for external, need to query
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700518 // the actual width and height, as that is the physical w & h
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700519 ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight);
Arun Kumar KR7b7f4012013-10-29 11:53:11 -0700520 }
521
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800522
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700523 // Since external is rotated 90, need to swap width/height
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700524 int extOrient = getExtOrientation(ctx);
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700525
526 if(extOrient & HWC_TRANSFORM_ROT_90)
Arun Kumar K.R82f1d282013-05-17 15:37:31 -0700527 swap(fbWidth, fbHeight);
528
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800529 float asX = 0;
530 float asY = 0;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530531 float asW = (float)fbWidth;
532 float asH = (float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800533
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800534 // based on the action safe ratio, get the Action safe rectangle
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530535 asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f));
536 asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f));
537 asX = ((float)fbWidth - asW) / 2;
538 asY = ((float)fbHeight - asH) / 2;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800539
540 // calculate the position ratio
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530541 xRatio = (float)x/(float)fbWidth;
542 yRatio = (float)y/(float)fbHeight;
543 wRatio = (float)w/(float)fbWidth;
544 hRatio = (float)h/(float)fbHeight;
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800545
546 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530547 x = int((xRatio * asW) + asX);
548 y = int((yRatio * asH) + asY);
549 w = int(wRatio * asW);
550 h = int(hRatio * asH);
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800551
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700552 // Convert it back to hwc_rect_t
553 rect.left = x;
554 rect.top = y;
555 rect.right = w + rect.left;
556 rect.bottom = h + rect.top;
557
Arun Kumar K.Rfeb2d8a2013-02-01 02:53:13 -0800558 return;
559}
560
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700561// This function gets the destination position for Seconday display
562// based on the position and aspect ratio with orientation
563void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
564 hwc_rect_t& inRect, hwc_rect_t& outRect) {
565 // Physical display resolution
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530566 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
567 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700568 //display position(x,y,w,h) in correct aspectratio after rotation
569 int xPos = 0;
570 int yPos = 0;
571 float width = fbWidth;
572 float height = fbHeight;
573 // Width/Height used for calculation, after rotation
574 float actualWidth = fbWidth;
575 float actualHeight = fbHeight;
576
577 float wRatio = 1.0;
578 float hRatio = 1.0;
579 float xRatio = 1.0;
580 float yRatio = 1.0;
581 hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight};
582
583 Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left,
584 inRect.bottom - inRect.top);
585 Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left,
586 outRect.bottom - outRect.top);
587
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530588 Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700589 eTransform extorient = static_cast<eTransform>(extOrientation);
590 // To calculate the destination co-ordinates in the new orientation
591 preRotateSource(extorient, whf, inPos);
592
593 if(extOrientation & HAL_TRANSFORM_ROT_90) {
594 // Swap width/height for input position
595 swapWidthHeight(actualWidth, actualHeight);
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700596 qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight,
597 (int)actualWidth, (int)actualHeight, rect);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700598 xPos = rect.left;
599 yPos = rect.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530600 width = float(rect.right - rect.left);
601 height = float(rect.bottom - rect.top);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700602 }
Shalaj Jaina70b4352014-06-15 13:47:47 -0700603 xRatio = (float)((float)inPos.x/actualWidth);
604 yRatio = (float)((float)inPos.y/actualHeight);
605 wRatio = (float)((float)inPos.w/actualWidth);
606 hRatio = (float)((float)inPos.h/actualHeight);
Ramkumar Radhakrishnandebfc5a2013-12-04 15:15:42 -0800607
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530608 //Calculate the pos9ition...
609 outPos.x = uint32_t((xRatio * width) + (float)xPos);
610 outPos.y = uint32_t((yRatio * height) + (float)yPos);
611 outPos.w = uint32_t(wRatio * width);
612 outPos.h = uint32_t(hRatio * height);
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700613 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d,"
614 "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y,
615 outPos.w, outPos.h);
616
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700617 // For sidesync, the dest fb will be in portrait orientation, and the crop
618 // will be updated to avoid the black side bands, and it will be upscaled
619 // to fit the dest RB, so recalculate
620 // the position based on the new width and height
621 if ((extOrientation & HWC_TRANSFORM_ROT_90) &&
622 isOrientationPortrait(ctx)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800623 hwc_rect_t r = {0, 0, 0, 0};
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700624 //Calculate the position
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530625 xRatio = (float)(outPos.x - xPos)/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700626 // GetaspectRatio -- tricky to get the correct aspect ratio
627 // But we need to do this.
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700628 qdutils::getAspectRatioPosition((int)width, (int)height,
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530629 (int)width,(int)height, r);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700630 xPos = r.left;
631 yPos = r.top;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530632 float tempHeight = float(r.bottom - r.top);
633 yRatio = (float)yPos/height;
634 wRatio = (float)outPos.w/width;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700635 hRatio = tempHeight/height;
636
637 //Map the coordinates back to Framebuffer domain
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530638 outPos.x = uint32_t(xRatio * fbWidth);
639 outPos.y = uint32_t(yRatio * fbHeight);
640 outPos.w = uint32_t(wRatio * fbWidth);
641 outPos.h = uint32_t(hRatio * fbHeight);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700642
643 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in"
644 "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__,
645 outPos.x, outPos.y,
646 outPos.w, outPos.h);
647 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700648 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700649 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700650 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700651 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700652 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
653 extW = ctx->mHWCVirtual->getScalingWidth();
654 extH = ctx->mHWCVirtual->getScalingHeight();
655 }
656 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
657 __FUNCTION__, extW, extH);
658
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530659 fbWidth = (float)ctx->dpyAttr[dpy].xres;
660 fbHeight = (float)ctx->dpyAttr[dpy].yres;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700661 //Calculate the position...
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530662 xRatio = (float)outPos.x/fbWidth;
663 yRatio = (float)outPos.y/fbHeight;
664 wRatio = (float)outPos.w/fbWidth;
665 hRatio = (float)outPos.h/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700666
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530667 outPos.x = uint32_t(xRatio * (float)extW);
668 outPos.y = uint32_t(yRatio * (float)extH);
669 outPos.w = uint32_t(wRatio * (float)extW);
670 outPos.h = uint32_t(hRatio * (float)extH);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700671 }
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700672 // Convert Dim to hwc_rect_t
673 outRect.left = outPos.x;
674 outRect.top = outPos.y;
675 outRect.right = outPos.x + outPos.w;
676 outRect.bottom = outPos.y + outPos.h;
677
678 return;
679}
680
681bool isPrimaryPortrait(hwc_context_t *ctx) {
682 int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
683 int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
684 if(fbWidth < fbHeight) {
685 return true;
686 }
687 return false;
688}
689
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700690bool isOrientationPortrait(hwc_context_t *ctx) {
691 if(isPrimaryPortrait(ctx)) {
692 return !(ctx->deviceOrientation & 0x1);
693 }
694 return (ctx->deviceOrientation & 0x1);
695}
696
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700697void calcExtDisplayPosition(hwc_context_t *ctx,
698 private_handle_t *hnd,
699 int dpy,
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700700 hwc_rect_t& sourceCrop,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700701 hwc_rect_t& displayFrame,
702 int& transform,
703 ovutils::eTransform& orient) {
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700704 // Swap width and height when there is a 90deg transform
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700705 int extOrient = getExtOrientation(ctx);
Raj Kamal068f4572014-04-14 16:14:06 +0530706 if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700707 if(!isYuvBuffer(hnd)) {
708 if(extOrient & HWC_TRANSFORM_ROT_90) {
709 int dstWidth = ctx->dpyAttr[dpy].xres;
710 int dstHeight = ctx->dpyAttr[dpy].yres;;
711 int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres;
712 int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres;
713 if(!isPrimaryPortrait(ctx)) {
714 swap(srcWidth, srcHeight);
715 } // Get Aspect Ratio for external
Tatenda Chipeperekwace8d5c42014-08-13 10:53:49 -0700716 qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth,
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700717 srcHeight, displayFrame);
718 // Crop - this is needed, because for sidesync, the dest fb will
719 // be in portrait orientation, so update the crop to not show the
720 // black side bands.
721 if (isOrientationPortrait(ctx)) {
722 sourceCrop = displayFrame;
723 displayFrame.left = 0;
724 displayFrame.top = 0;
725 displayFrame.right = dstWidth;
726 displayFrame.bottom = dstHeight;
727 }
728 }
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700729 if(ctx->dpyAttr[dpy].mMDPScalingMode) {
Tatenda Chipeperekwa03d5df22014-09-16 18:09:18 -0700730 uint32_t extW = 0, extH = 0;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700731 // if MDP scaling mode is enabled, map the co-ordinates to new
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700732 // domain(downscaled)
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530733 float fbWidth = (float)ctx->dpyAttr[dpy].xres;
734 float fbHeight = (float)ctx->dpyAttr[dpy].yres;
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700735 // query MDP configured attributes
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700736 if(dpy == HWC_DISPLAY_EXTERNAL) {
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -0700737 ctx->mHDMIDisplay->getAttributes(extW, extH);
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700738 } else if(dpy == HWC_DISPLAY_VIRTUAL) {
739 extW = ctx->mHWCVirtual->getScalingWidth();
740 extH = ctx->mHWCVirtual->getScalingHeight();
741 }
742 ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d",
743 __FUNCTION__, extW, extH);
744
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700745 //Calculate the ratio...
746 float wRatio = ((float)extW)/fbWidth;
747 float hRatio = ((float)extH)/fbHeight;
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700748
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700749 //convert Dim to hwc_rect_t
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530750 displayFrame.left = int(wRatio*(float)displayFrame.left);
751 displayFrame.top = int(hRatio*(float)displayFrame.top);
752 displayFrame.right = int(wRatio*(float)displayFrame.right);
753 displayFrame.bottom = int(hRatio*(float)displayFrame.bottom);
Ramkumar Radhakrishnana5c72872014-08-28 19:04:18 -0700754 ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame"
755 " for MDPDownscale feature [%d %d %d %d]",
756 displayFrame.left, displayFrame.top,
757 displayFrame.right, displayFrame.bottom);
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700758 }
759 }else {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -0700760 if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) {
Ramkumar Radhakrishnan66f856c2013-08-21 16:09:47 -0700761 getAspectRatioPosition(ctx, dpy, extOrient,
762 displayFrame, displayFrame);
763 }
764 }
765 // If there is a external orientation set, use that
766 if(extOrient) {
767 transform = extOrient;
768 orient = static_cast<ovutils::eTransform >(extOrient);
769 }
770 // Calculate the actionsafe dimensions for External(dpy = 1 or 2)
771 getActionSafePosition(ctx, dpy, displayFrame);
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700772 }
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700773}
Amara Venkata Mastan Manoj Kumar376d8a82013-03-13 19:18:47 -0700774
Arun Kumar K.Rfb5bfa62013-07-25 03:10:51 -0700775/* Returns the orientation which needs to be set on External for
776 * SideSync/Buffer Mirrormode
777 */
778int getMirrorModeOrientation(hwc_context_t *ctx) {
779 int extOrientation = 0;
780 int deviceOrientation = ctx->deviceOrientation;
781 if(!isPrimaryPortrait(ctx))
782 deviceOrientation = (deviceOrientation + 1) % 4;
783 if (deviceOrientation == 0)
784 extOrientation = HWC_TRANSFORM_ROT_270;
785 else if (deviceOrientation == 1)//90
786 extOrientation = 0;
787 else if (deviceOrientation == 2)//180
788 extOrientation = HWC_TRANSFORM_ROT_90;
789 else if (deviceOrientation == 3)//270
790 extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H;
791
792 return extOrientation;
Arun Kumar K.R5898c652013-07-17 14:20:32 -0700793}
Arun Kumar K.Rffef7482013-04-10 14:17:22 -0700794
Raj kamal59fea562014-04-01 16:52:19 +0530795/* Get External State names */
796const char* getExternalDisplayState(uint32_t external_state) {
797 static const char* externalStates[EXTERNAL_MAXSTATES] = {0};
798 externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE);
799 externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE);
800 externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE);
801 externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME);
802
803 if(external_state >= EXTERNAL_MAXSTATES) {
804 return "EXTERNAL_INVALID";
805 }
806
807 return externalStates[external_state];
808}
809
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530810bool isDownscaleRequired(hwc_layer_1_t const* layer) {
811 hwc_rect_t displayFrame = layer->displayFrame;
812 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
813 int dst_w, dst_h, src_w, src_h;
814 dst_w = displayFrame.right - displayFrame.left;
815 dst_h = displayFrame.bottom - displayFrame.top;
816 src_w = sourceCrop.right - sourceCrop.left;
817 src_h = sourceCrop.bottom - sourceCrop.top;
818
819 if(((src_w > dst_w) || (src_h > dst_h)))
820 return true;
821
822 return false;
823}
824bool needsScaling(hwc_layer_1_t const* layer) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500825 int dst_w, dst_h, src_w, src_h;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500826 hwc_rect_t displayFrame = layer->displayFrame;
Saurabh Shah62e1d732013-09-17 10:44:05 -0700827 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Naseer Ahmed018e5452012-12-03 14:46:15 -0500828
829 dst_w = displayFrame.right - displayFrame.left;
830 dst_h = displayFrame.bottom - displayFrame.top;
Naseer Ahmed018e5452012-12-03 14:46:15 -0500831 src_w = sourceCrop.right - sourceCrop.left;
832 src_h = sourceCrop.bottom - sourceCrop.top;
833
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -0800834 if(((src_w != dst_w) || (src_h != dst_h)))
835 return true;
836
837 return false;
838}
839
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700840// Checks if layer needs scaling with split
841bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer,
842 const int& dpy) {
843
844 int src_width_l, src_height_l;
845 int src_width_r, src_height_r;
846 int dst_width_l, dst_height_l;
847 int dst_width_r, dst_height_r;
848 int hw_w = ctx->dpyAttr[dpy].xres;
849 int hw_h = ctx->dpyAttr[dpy].yres;
850 hwc_rect_t cropL, dstL, cropR, dstR;
851 const int lSplit = getLeftSplit(ctx, dpy);
Saurabh Shah62e1d732013-09-17 10:44:05 -0700852 hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700853 hwc_rect_t displayFrame = layer->displayFrame;
854 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700855
856 cropL = sourceCrop;
857 dstL = displayFrame;
858 hwc_rect_t scissorL = { 0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800859 scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700860 qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0);
861
862 cropR = sourceCrop;
863 dstR = displayFrame;
864 hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800865 scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR);
Sushil Chauhan15a2ea62013-09-04 18:28:36 -0700866 qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0);
867
868 // Sanitize Crop to stitch
869 sanitizeSourceCrop(cropL, cropR, hnd);
870
871 // Calculate the left dst
872 dst_width_l = dstL.right - dstL.left;
873 dst_height_l = dstL.bottom - dstL.top;
874 src_width_l = cropL.right - cropL.left;
875 src_height_l = cropL.bottom - cropL.top;
876
877 // check if there is any scaling on the left
878 if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l)))
879 return true;
880
881 // Calculate the right dst
882 dst_width_r = dstR.right - dstR.left;
883 dst_height_r = dstR.bottom - dstR.top;
884 src_width_r = cropR.right - cropR.left;
885 src_height_r = cropR.bottom - cropR.top;
886
887 // check if there is any scaling on the right
888 if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r)))
889 return true;
890
891 return false;
892}
893
Prabhanjan Kandula21918db2013-11-26 15:51:58 +0530894bool isAlphaScaled(hwc_layer_1_t const* layer) {
895 if(needsScaling(layer) && isAlphaPresent(layer)) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530896 return true;
897 }
898 return false;
899}
900
901bool isAlphaPresent(hwc_layer_1_t const* layer) {
902 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400903 if(hnd) {
904 int format = hnd->format;
905 switch(format) {
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530906 case HAL_PIXEL_FORMAT_RGBA_8888:
907 case HAL_PIXEL_FORMAT_BGRA_8888:
908 // In any more formats with Alpha go here..
Naseer Ahmed018e5452012-12-03 14:46:15 -0500909 return true;
Sravan Kumar D.V.N075ef002013-03-20 05:22:26 +0530910 default : return false;
Naseer Ahmed7a4287c2013-03-26 18:11:41 -0400911 }
Naseer Ahmed018e5452012-12-03 14:46:15 -0500912 }
913 return false;
914}
915
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700916static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform,
917 hwc_rect_t& crop, hwc_rect_t& dst) {
918 int hw_w = ctx->dpyAttr[dpy].xres;
919 int hw_h = ctx->dpyAttr[dpy].yres;
920 if(dst.left < 0 || dst.top < 0 ||
921 dst.right > hw_w || dst.bottom > hw_h) {
922 hwc_rect_t scissor = {0, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -0800923 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700924 qhwc::calculate_crop_rects(crop, dst, scissor, transform);
925 }
926}
927
928static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list,
929 const int& dpy) {
930 for(uint32_t i = 0; i < list->numHwLayers - 1; i++) {
931 hwc_layer_1_t *layer = &list->hwLayers[i];
932 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700933 int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 :
934 list->hwLayers[i].transform;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700935 trimLayer(ctx, dpy,
Sushil Chauhanfda00fc2014-03-20 11:08:41 -0700936 transform,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700937 (hwc_rect_t&)crop,
938 (hwc_rect_t&)list->hwLayers[i].displayFrame);
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530939 layer->sourceCropf.left = (float)crop.left;
940 layer->sourceCropf.right = (float)crop.right;
941 layer->sourceCropf.top = (float)crop.top;
942 layer->sourceCropf.bottom = (float)crop.bottom;
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700943 }
944}
945
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700946void setListStats(hwc_context_t *ctx,
Saurabh Shahd9ff30b2013-10-03 16:37:06 -0700947 hwc_display_contents_1_t *list, int dpy) {
Saurabh Shahd4e65852013-06-17 11:33:53 -0700948 const int prevYuvCount = ctx->listStats[dpy].yuvCount;
949 memset(&ctx->listStats[dpy], 0, sizeof(ListStats));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +0530950 ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1;
951 ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700952 ctx->listStats[dpy].skipCount = 0;
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +0530953 ctx->listStats[dpy].preMultipliedAlpha = false;
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700954 ctx->listStats[dpy].isSecurePresent = false;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800955 ctx->listStats[dpy].yuvCount = 0;
Ping Li9404e2a2013-04-24 16:36:03 -0400956 char property[PROPERTY_VALUE_MAX];
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -0700957 ctx->listStats[dpy].isDisplayAnimating = false;
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700958 ctx->listStats[dpy].secureUI = false;
radhakrishnac9a67412013-09-25 17:40:42 +0530959 ctx->listStats[dpy].yuv4k2kCount = 0;
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -0800960 ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy);
Ramakant Singh0def28c2014-03-28 20:43:13 +0530961 ctx->listStats[dpy].renderBufIndexforABC = -1;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -0700962 ctx->listStats[dpy].secureRGBCount = 0;
Arun Kumar K.Ra727a882014-08-20 17:14:26 -0700963 ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate;
964 uint32_t refreshRate = 0;
965 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700966
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -0700967 ctx->listStats[dpy].mAIVVideoMode = false;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -0800968 resetROI(ctx, dpy);
969
Sushil Chauhanf68d0df2014-04-09 09:15:37 -0700970 trimList(ctx, list, dpy);
971 optimizeLayerRects(list);
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700972 for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) {
Naseer Ahmed018e5452012-12-03 14:46:15 -0500973 hwc_layer_1_t const* layer = &list->hwLayers[i];
974 private_handle_t *hnd = (private_handle_t *)layer->handle;
Naseer Ahmedf48aef62012-07-20 09:05:53 -0700975
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700976#ifdef QCOM_BSP
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -0700977 // Window boxing feature is applicable obly for external display, So
978 // enable mAIVVideoMode only for external display
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700979 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -0700980 ctx->listStats[dpy].mAIVVideoMode = true;
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -0700981 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700982 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
983 ctx->listStats[dpy].isDisplayAnimating = true;
984 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700985 if(isSecureDisplayBuffer(hnd)) {
986 ctx->listStats[dpy].secureUI = true;
987 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700988#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700989 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
990 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700991 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800992
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700993 //reset yuv indices
994 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +0530995 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700996
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700997 if (isSecureBuffer(hnd)) {
998 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -0700999 if(not isYuvBuffer(hnd)) {
1000 // cache secureRGB layer parameters like we cache for YUV layers
1001 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1002 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1003 secureRGBCount++;
1004 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001005 }
1006
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001007 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001008 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001009 }
1010
1011 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001012 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301013 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001014 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001015
Raj Kamal389d6e32014-08-04 14:43:24 +05301016 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301017 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301018 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301019 yuv4k2kCount++;
1020 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001021 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301022 if(layer->blending == HWC_BLENDING_PREMULT)
1023 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001024
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001025#ifdef DYNAMIC_FPS
1026 if (dpy == HWC_DISPLAY_PRIMARY && mdpHw.isDynFpsSupported()) {
1027 //dyn fps: get refreshrate from metadata
1028 //Support multiple refresh rates if they are same
1029 //else set to default
1030 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1031 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1032 // Valid refreshRate in metadata and within the range
1033 uint32_t rate = roundOff(mdata->refreshrate);
1034 if((rate >= mdpHw.getMinFpsSupported() &&
1035 rate <= mdpHw.getMaxFpsSupported())) {
1036 if (!refreshRate) {
1037 refreshRate = rate;
1038 } else if(refreshRate != rate) {
1039 // multiple refreshrate requests, set to default
1040 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1041 }
1042 }
1043 }
1044 }
1045#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001046 }
Ping Li9404e2a2013-04-24 16:36:03 -04001047 if(ctx->listStats[dpy].yuvCount > 0) {
1048 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1049 if (atoi(property) != 1) {
1050 property_set("hw.cabl.yuv", "1");
1051 }
1052 }
1053 } else {
1054 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1055 if (atoi(property) != 0) {
1056 property_set("hw.cabl.yuv", "0");
1057 }
1058 }
1059 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001060
1061 //The marking of video begin/end is useful on some targets where we need
1062 //to have a padding round to be able to shift pipes across mixers.
1063 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1064 ctx->mVideoTransFlag = true;
1065 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301066
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001067 if(dpy == HWC_DISPLAY_PRIMARY) {
1068 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001069 //Store the requested fresh rate
1070 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1071 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001072 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001073}
1074
Naseer Ahmed018e5452012-12-03 14:46:15 -05001075
Saurabh Shah68107422013-07-09 11:12:42 -07001076static void calc_cut(double& leftCutRatio, double& topCutRatio,
1077 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001078 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001079 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001080 }
1081 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001082 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001083 }
1084 if(orient & HAL_TRANSFORM_ROT_90) {
1085 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001086 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001087 leftCutRatio = topCutRatio;
1088 topCutRatio = rightCutRatio;
1089 rightCutRatio = bottomCutRatio;
1090 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001091 }
1092}
1093
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001094bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001095 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1096 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1097 ctx->mSecuring) {
1098 return true;
1099 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001100 if (isSecureModePolicy(ctx->mMDP.version)) {
1101 private_handle_t *hnd = (private_handle_t *)layer->handle;
1102 if(ctx->mSecureMode) {
1103 if (! isSecureBuffer(hnd)) {
1104 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1105 __FUNCTION__);
1106 return true;
1107 }
1108 } else {
1109 if (isSecureBuffer(hnd)) {
1110 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1111 __FUNCTION__);
1112 return true;
1113 }
1114 }
1115 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001116 return false;
1117}
1118
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001119bool isSecureModePolicy(int mdpVersion) {
1120 if (mdpVersion < qdutils::MDSS_V5)
1121 return true;
1122 else
1123 return false;
1124}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001125
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001126bool isRotatorSupportedFormat(private_handle_t *hnd) {
1127 // Following rotator src formats are supported by mdp driver
1128 // TODO: Add more formats in future, if mdp driver adds support
1129 switch(hnd->format) {
1130 case HAL_PIXEL_FORMAT_RGBA_8888:
1131 case HAL_PIXEL_FORMAT_RGB_565:
1132 case HAL_PIXEL_FORMAT_RGB_888:
1133 case HAL_PIXEL_FORMAT_BGRA_8888:
1134 return true;
1135 default:
1136 return false;
1137 }
1138 return false;
1139}
1140
1141bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
1142 // Rotate layers, if it is YUV type or rendered by CPU and not
1143 // for the MDP versions below MDP5
1144 if((isCPURendered(hnd) && isRotatorSupportedFormat(hnd) &&
1145 !ctx->mMDP.version < qdutils::MDSS_V5)
1146 || isYuvBuffer(hnd)) {
1147 return true;
1148 }
1149 return false;
1150}
1151
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001152// returns true if Action safe dimensions are set and target supports Actionsafe
1153bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1154 // if external supports underscan, do nothing
1155 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001156 // Disable Action safe for 8974 due to HW limitation for downscaling
1157 // layers with overlapped region
1158 // Disable Actionsafe for non HDMI displays.
1159 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1160 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001161 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001162 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001163 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001164
1165 char value[PROPERTY_VALUE_MAX];
1166 // Read action safe properties
1167 property_get("persist.sys.actionsafe.width", value, "0");
1168 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1169 property_get("persist.sys.actionsafe.height", value, "0");
1170 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1171
1172 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1173 //No action safe ratio set, return
1174 return false;
1175 }
1176 return true;
1177}
1178
Naseer Ahmed522ce662013-03-18 20:14:05 -04001179int getBlending(int blending) {
1180 switch(blending) {
1181 case HWC_BLENDING_NONE:
1182 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1183 case HWC_BLENDING_PREMULT:
1184 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1185 case HWC_BLENDING_COVERAGE :
1186 default:
1187 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1188 }
1189}
1190
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001191//Crops source buffer against destination and FB boundaries
1192void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001193 const hwc_rect_t& scissor, int orient) {
1194
Saurabh Shah27c1d652012-08-14 19:30:28 -07001195 int& crop_l = crop.left;
1196 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001197 int& crop_r = crop.right;
1198 int& crop_b = crop.bottom;
1199 int crop_w = crop.right - crop.left;
1200 int crop_h = crop.bottom - crop.top;
1201
Saurabh Shah27c1d652012-08-14 19:30:28 -07001202 int& dst_l = dst.left;
1203 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001204 int& dst_r = dst.right;
1205 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001206 int dst_w = abs(dst.right - dst.left);
1207 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001208
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001209 const int& sci_l = scissor.left;
1210 const int& sci_t = scissor.top;
1211 const int& sci_r = scissor.right;
1212 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001213
Saurabh Shah68107422013-07-09 11:12:42 -07001214 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1215 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001216
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001217 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001218 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001219 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001220 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001221
1222 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001223 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001224 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001225 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001226
1227 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001228 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001229 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001230 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001231
1232 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001233 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001234 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001235 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001236
Saurabh Shah541b59d2012-10-11 11:08:12 -07001237 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301238 crop_l += (int)round((double)crop_w * leftCutRatio);
1239 crop_t += (int)round((double)crop_h * topCutRatio);
1240 crop_r -= (int)round((double)crop_w * rightCutRatio);
1241 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001242}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001243
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301244bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1245 const hwc_layer_1_t* layer2) {
1246 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1247 layer2->displayFrame);
1248 return isValidRect(irect);
1249}
1250
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001251bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1252{
1253 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1254 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1255}
1256
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001257bool isValidRect(const hwc_rect& rect)
1258{
1259 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301260}
1261
Ramakant Singh21cec722014-03-07 19:11:45 +05301262bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1263 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1264 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1265 return true ;
1266 return false;
1267}
1268
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001269hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1270{
1271 hwc_rect_t res;
1272
1273 if(!isValidRect(rect))
1274 return (hwc_rect_t){0, 0, 0, 0};
1275
1276 res.left = rect.left + x_off;
1277 res.top = rect.top + y_off;
1278 res.right = rect.right + x_off;
1279 res.bottom = rect.bottom + y_off;
1280
1281 return res;
1282}
1283
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001284/* computes the intersection of two rects */
1285hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1286{
1287 hwc_rect_t res;
1288
1289 if(!isValidRect(rect1) || !isValidRect(rect2)){
1290 return (hwc_rect_t){0, 0, 0, 0};
1291 }
1292
1293
1294 res.left = max(rect1.left, rect2.left);
1295 res.top = max(rect1.top, rect2.top);
1296 res.right = min(rect1.right, rect2.right);
1297 res.bottom = min(rect1.bottom, rect2.bottom);
1298
1299 if(!isValidRect(res))
1300 return (hwc_rect_t){0, 0, 0, 0};
1301
1302 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301303}
1304
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001305/* computes the union of two rects */
1306hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1307{
1308 hwc_rect_t res;
1309
1310 if(!isValidRect(rect1)){
1311 return rect2;
1312 }
1313
1314 if(!isValidRect(rect2)){
1315 return rect1;
1316 }
1317
1318 res.left = min(rect1.left, rect2.left);
1319 res.top = min(rect1.top, rect2.top);
1320 res.right = max(rect1.right, rect2.right);
1321 res.bottom = max(rect1.bottom, rect2.bottom);
1322
1323 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301324}
1325
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001326/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1327 * a single rect */
1328hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301329
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001330 hwc_rect_t res = rect1;
1331
1332 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1333 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1334 res.top = rect2.bottom;
1335 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1336 res.bottom = rect2.top;
1337 }
1338 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1339 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1340 res.left = rect2.right;
1341 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1342 res.right = rect2.left;
1343 }
1344 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301345}
1346
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001347void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301348 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301349 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301350 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001351 //If it is opaque see if we can substract this region from below
1352 //layers.
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301353 if(list->hwLayers[i].blending == HWC_BLENDING_NONE) {
1354 int j= i-1;
1355 hwc_rect_t& topframe =
1356 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1357 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301358 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001359 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1360 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001361 hwc_rect_t bottomCrop =
1362 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001363 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1364 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001365
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001366 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1367 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001368 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001369 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001370 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001371 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001372 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001373 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301374 layer->sourceCropf.left =(float)bottomCrop.left;
1375 layer->sourceCropf.top = (float)bottomCrop.top;
1376 layer->sourceCropf.right = (float)bottomCrop.right;
1377 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001378#ifdef QCOM_BSP
1379 //Update layer dirtyRect
1380 layer->dirtyRect = getIntersection(bottomCrop,
1381 layer->dirtyRect);
1382#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001383 }
1384 }
1385 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301386 }
1387 }
1388 i--;
1389 }
1390}
1391
Naseer Ahmed64b81212013-02-14 10:29:47 -05001392void getNonWormholeRegion(hwc_display_contents_1_t* list,
1393 hwc_rect_t& nwr)
1394{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301395 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001396 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1397 //Initiliaze nwr to first frame
1398 nwr.left = list->hwLayers[0].displayFrame.left;
1399 nwr.top = list->hwLayers[0].displayFrame.top;
1400 nwr.right = list->hwLayers[0].displayFrame.right;
1401 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1402
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301403 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001404 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001405 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001406 }
1407
1408 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001409 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001410}
1411
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001412bool isExternalActive(hwc_context_t* ctx) {
1413 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -07001414}
1415
Saurabh Shah747af1e2013-02-26 10:25:12 -08001416void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001417 if(LIKELY(list)) {
1418 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1419 //Close the acquireFenceFds
1420 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1421 if(list->hwLayers[i].acquireFenceFd >= 0) {
1422 close(list->hwLayers[i].acquireFenceFd);
1423 list->hwLayers[i].acquireFenceFd = -1;
1424 }
1425 }
1426 //Writeback
1427 if(list->outbufAcquireFenceFd >= 0) {
1428 close(list->outbufAcquireFenceFd);
1429 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001430 }
1431 }
1432}
1433
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001434int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001435 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001436 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001437 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001438 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001439 int count = 0;
1440 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001441 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001442 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001443 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001444
1445 struct mdp_buf_sync data;
1446 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001447 data.acq_fen_fd = acquireFd;
1448 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001449 data.retire_fen_fd = &retireFd;
1450 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001451
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001452 char property[PROPERTY_VALUE_MAX];
1453 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1454 if(atoi(property) == 0)
1455 swapzero = true;
1456 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001457
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001458 bool isExtAnimating = false;
1459 if(dpy)
1460 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001461
Saurabh Shah23a813c2013-03-20 16:58:12 -07001462 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001463 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001464 int rotFd = ctx->mRotMgr->getRotDevFd();
1465 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001466 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1467 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1468 if((currRot == NULL) || (currLayer == NULL)) {
1469 continue;
1470 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001471 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001472 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001473 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001474 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001475 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001476 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001477 if(currLayer->acquireFenceFd >= 0) {
1478 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1479 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001480 int ret = 0;
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301481 if(not ctx->mLayerRotMap[dpy]->isRotCached(i))
1482 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1483
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001484 if(ret < 0) {
1485 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1486 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001487 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001488 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001489 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001490 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001491 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001492 dup(rotReleaseFd);
1493 //A buffer is free to be used by producer as soon as its copied to
1494 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001495 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001496 rotReleaseFd;
1497 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001498 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001499
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301500 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001501 if(list->outbufAcquireFenceFd >= 0) {
1502 //Writeback output buffer
1503 acquireFd[count++] = list->outbufAcquireFenceFd;
1504 }
1505
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001506 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301507 if(((isAbcInUse(ctx)== true ) ||
1508 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001509 list->hwLayers[i].acquireFenceFd >= 0) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001510 if(UNLIKELY(swapzero))
1511 acquireFd[count++] = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +05301512 // if ABC is enabled for more than one layer.
1513 // renderBufIndexforABC will work as FB.Hence
1514 // set the acquireFD from fd - which is coming from copybit
1515 else if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1516 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1517 acquireFd[count++] = fd;
1518 else
1519 continue;
1520 } else
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001521 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001522 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001523 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
1524 if(UNLIKELY(swapzero))
1525 acquireFd[count++] = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001526 else if(fd >= 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001527 //set the acquireFD from fd - which is coming from c2d
1528 acquireFd[count++] = fd;
1529 // Buffer sync IOCTL should be async when using c2d fence is
1530 // used
1531 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001532 } else if(list->hwLayers[i].acquireFenceFd >= 0)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001533 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1534 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001535 }
1536
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001537 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001538 // Acquire c2d fence of Overlap render buffer
1539 acquireFd[count++] = fd;
1540 }
1541
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001542 data.acq_fen_fd_cnt = count;
1543 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001544
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001545 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001546 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001547 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001548 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001549
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001550 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001551 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1552 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301553 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001554 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1555 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001556 close(releaseFd);
1557 releaseFd = -1;
1558 close(retireFd);
1559 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001560 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001561
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001562 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001563 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001564#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001565 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001566#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001567 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001568 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001569 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001570 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001571 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001572 // Release all the app layer fds immediately,
1573 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001574 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001575 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001576#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001577 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301578 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301579
1580 // if ABC is enabled for more than one layer
1581 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1582 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1583 list->hwLayers[i].releaseFenceFd = dup(fd);
1584 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1585 (isAbcInUse(ctx) == false)){
1586 //For Blit, the app layers should be released when the Blit
1587 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301588 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001589 } else
1590#endif
1591 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301592 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1593 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001594 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001595 }
1596 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001597
1598 if(fd >= 0) {
1599 close(fd);
1600 fd = -1;
1601 }
1602
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001603 if (ctx->mCopyBit[dpy]) {
1604 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001605 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1606 else
1607 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1608 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001609
Saurabh Shah23a813c2013-03-20 16:58:12 -07001610 //Signals when MDP finishes reading rotator buffers.
1611 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001612 close(releaseFd);
1613 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001614
Arun Kumar K.R51835182013-11-19 11:20:28 -08001615 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001616 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001617 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001618 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001619 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001620 return ret;
1621}
1622
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001623void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001624 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001625 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001626 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001627 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001628
1629 if(layer->blending == HWC_BLENDING_PREMULT) {
1630 ovutils::setMdpFlags(mdpFlags,
1631 ovutils::OV_MDP_BLEND_FG_PREMULT);
1632 }
1633
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001634 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1635 metadata->interlaced) {
1636 ovutils::setMdpFlags(mdpFlags,
1637 ovutils::OV_MDP_DEINTERLACE);
1638 }
1639
1640 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1641 if(isSecureBuffer(hnd)) {
1642 ovutils::setMdpFlags(mdpFlags,
1643 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Saurabh Shahacf10202013-02-26 10:15:15 -08001644 }
1645
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001646 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001647 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001648 ovutils::setMdpFlags(mdpFlags,
1649 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1650 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001651
1652 //Pre-rotation will be used using rotator.
1653 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1654 ovutils::setMdpFlags(mdpFlags,
1655 ovutils::OV_MDP_SOURCE_ROTATED_90);
1656 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001657 //No 90 component and no rot-downscale then flips done by MDP
1658 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001659 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1660 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001661 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1662 }
1663
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001664 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001665 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1666 }
1667 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001668
1669 if(metadata &&
1670 ((metadata->operation & PP_PARAM_HSIC)
1671 || (metadata->operation & PP_PARAM_IGC)
1672 || (metadata->operation & PP_PARAM_SHARP2))) {
1673 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1674 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001675}
1676
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301677int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001678 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001679 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001680
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301681 // Fix alignments for TILED format
1682 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1683 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1684 whf.w = utils::alignup(whf.w, 64);
1685 whf.h = utils::alignup(whf.h, 32);
1686 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001687 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001688
1689 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1690 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001691 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1692 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001693 rot->setCrop(rotCrop);
1694 }
1695
Saurabh Shahacf10202013-02-26 10:15:15 -08001696 rot->setFlags(mdpFlags);
1697 rot->setTransform(orient);
1698 rot->setDownscale(downscale);
1699 if(!rot->commit()) return -1;
1700 return 0;
1701}
1702
Saurabh Shahe2474082013-05-15 16:32:13 -07001703int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001704 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001705 const hwc_rect_t& pos, const MetaData_t *metadata,
1706 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001707 ov->setSource(parg, dest);
1708 ov->setTransform(orient, dest);
1709
1710 int crop_w = crop.right - crop.left;
1711 int crop_h = crop.bottom - crop.top;
1712 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1713 ov->setCrop(dcrop, dest);
1714
1715 int posW = pos.right - pos.left;
1716 int posH = pos.bottom - pos.top;
1717 Dim position(pos.left, pos.top, posW, posH);
1718 ov->setPosition(position, dest);
1719
Saurabh Shah5daeee52013-01-23 16:52:26 +08001720 if (metadata)
1721 ov->setVisualParams(*metadata, dest);
1722
Saurabh Shahacf10202013-02-26 10:15:15 -08001723 if (!ov->commit(dest)) {
1724 return -1;
1725 }
1726 return 0;
1727}
1728
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001729int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1730 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001731 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001732
1733 hwc_rect_t dst = layer->displayFrame;
1734 trimLayer(ctx, dpy, 0, dst, dst);
1735
1736 int w = ctx->dpyAttr[dpy].xres;
1737 int h = ctx->dpyAttr[dpy].yres;
1738 int dst_w = dst.right - dst.left;
1739 int dst_h = dst.bottom - dst.top;
1740 uint32_t color = layer->transform;
1741 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888), 0);
1742
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001743 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001744 if (layer->blending == HWC_BLENDING_PREMULT)
1745 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1746
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001747 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001748 layer->planeAlpha,
1749 (ovutils::eBlending) getBlending(layer->blending));
1750
1751 // Configure MDP pipe for Color layer
1752 Dim pos(dst.left, dst.top, dst_w, dst_h);
1753 ctx->mOverlay->setSource(parg, dest);
1754 ctx->mOverlay->setColor(color, dest);
1755 ctx->mOverlay->setTransform(0, dest);
1756 ctx->mOverlay->setCrop(pos, dest);
1757 ctx->mOverlay->setPosition(pos, dest);
1758
1759 if (!ctx->mOverlay->commit(dest)) {
1760 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1761 return -1;
1762 }
1763 return 0;
1764}
1765
Saurabh Shahe2474082013-05-15 16:32:13 -07001766void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001767 hwc_rect_t& crop, Rotator *rot) {
1768 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001769 crop.right - crop.left,
1770 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001771 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1772 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001773 //B-family rotator internally could modify destination dimensions if
1774 //downscaling is supported
1775 whf = rot->getDstWhf();
1776 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001777 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001778 //A-family rotator rotates entire buffer irrespective of crop, forcing
1779 //us to recompute the crop based on transform
1780 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1781 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001782 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001783
1784 crop.left = transformedCrop.x;
1785 crop.top = transformedCrop.y;
1786 crop.right = transformedCrop.x + transformedCrop.w;
1787 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001788}
1789
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001790int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1791 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1792 return 0;
1793 }
1794
1795 int downscale = 0;
1796 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1797 hwc_rect_t dst = layer->displayFrame;
1798 private_handle_t *hnd = (private_handle_t *)layer->handle;
1799
1800 if(not hnd) {
1801 return 0;
1802 }
1803
1804 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1805 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1806 && metadata->interlaced;
1807 int transform = layer->transform;
1808 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1809
1810 if(isYuvBuffer(hnd)) {
1811 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1812 ctx->mMDP.version < qdutils::MDSS_V5) {
1813 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1814 crop.bottom - crop.top, dst.right - dst.left,
1815 dst.bottom - dst.top, format, isInterlaced);
1816 } else {
1817 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1818 crop.bottom - crop.top);
1819 Dim pos(dst.left, dst.top, dst.right - dst.left,
1820 dst.bottom - dst.top);
1821 if(transform & HAL_TRANSFORM_ROT_90) {
1822 swap(adjCrop.w, adjCrop.h);
1823 }
1824 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1825 pos.h, format, isInterlaced);
1826 }
1827 }
1828 return downscale;
1829}
1830
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001831bool isZoomModeEnabled(hwc_rect_t crop) {
1832 // This does not work for zooming in top left corner of the image
1833 return(crop.top > 0 || crop.left > 0);
1834}
1835
1836void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1837 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1838 crop.left, crop.top, crop.right, crop.bottom);
1839 if(isZoomModeEnabled(crop)) {
1840 Dim srcCrop(crop.left, crop.top,
1841 crop.right - crop.left,
1842 crop.bottom - crop.top);
1843 int extW = ctx->dpyAttr[dpy].xres;
1844 int extH = ctx->dpyAttr[dpy].yres;
1845 //Crop the original video in order to fit external display aspect ratio
1846 if(srcCrop.w * extH < extW * srcCrop.h) {
1847 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1848 crop.top += offset;
1849 crop.bottom -= offset;
1850 } else {
1851 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1852 crop.left += offset;
1853 crop.right -= offset;
1854 }
1855 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1856 " source crop [%d %d %d %d]", extW, extH, dpy,
1857 crop.left, crop.top, crop.right, crop.bottom);
1858 }
1859}
1860
1861void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1862 hwc_rect_t& dst, int dpy) {
1863 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1864 dst.left, dst.top, dst.right, dst.bottom);
1865 Dim srcCrop(crop.left, crop.top,
1866 crop.right - crop.left,
1867 crop.bottom - crop.top);
1868 int extW = ctx->dpyAttr[dpy].xres;
1869 int extH = ctx->dpyAttr[dpy].yres;
1870 // Set the destination coordinates of external display to full screen,
1871 // when zoom in mode is enabled or video aspect ratio matches with the
1872 // external display aspect ratio
1873 if((srcCrop.w * extH == extW * srcCrop.h) || (isZoomModeEnabled(crop))) {
1874 dst.left = 0;
1875 dst.top = 0;
1876 dst.right = extW;
1877 dst.bottom = extH;
1878 }
1879 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1880 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
1881 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
1882 crop.left, crop.top, crop.right, crop.bottom);
1883}
1884
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001885void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001886 hwc_rect_t& dst, int dpy) {
1887 updateCropAIVVideoMode(ctx, crop, dpy);
1888 updateDestAIVVideoMode(ctx, crop, dst, dpy);
1889}
1890
Saurabh Shah88e4d272013-09-03 13:31:29 -07001891int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001892 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001893 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001894
1895 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001896
Saurabh Shahacf10202013-02-26 10:15:15 -08001897 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001898 if (layer->flags & HWC_COLOR_FILL) {
1899 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001900 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001901 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001902 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1903 return -1;
1904 }
1905
Saurabh Shah5daeee52013-01-23 16:52:26 +08001906 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1907
Saurabh Shah62e1d732013-09-17 10:44:05 -07001908 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001909 hwc_rect_t dst = layer->displayFrame;
1910 int transform = layer->transform;
1911 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001912 int rotFlags = ovutils::ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07001913 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301914 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04001915
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001916 // Handle R/B swap
1917 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1918 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1919 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1920 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1921 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1922 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001923 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07001924 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
1925 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001926 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08001927 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001928 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001929 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001930
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001931 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001932 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001933 *rot = ctx->mRotMgr->getNext();
1934 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07001935 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001936 // BWC is not tested for other formats So enable it only for YUV format
1937 if(!dpy && isYuvBuffer(hnd))
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001938 BwcPM::setBwc(crop, dst, transform, downscale, mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08001939 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001940 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
1941 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001942 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001943 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001944 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001945 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08001946 }
1947
Saurabh Shah76fd6552013-03-14 14:45:38 -07001948 //For the mdp, since either we are pre-rotating or MDP does flips
1949 orient = OVERLAY_TRANSFORM_0;
1950 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001951 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001952 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1953 (ovutils::eBlending) getBlending(layer->blending));
1954
Saurabh Shah5daeee52013-01-23 16:52:26 +08001955 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001956 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
1957 return -1;
1958 }
1959 return 0;
1960}
1961
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001962//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001963void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001964 private_handle_t *hnd) {
1965 if(cropL.right - cropL.left) {
1966 if(isYuvBuffer(hnd)) {
1967 //Always safe to even down left
1968 ovutils::even_floor(cropL.left);
1969 //If right is even, automatically width is even, since left is
1970 //already even
1971 ovutils::even_floor(cropL.right);
1972 }
1973 //Make sure there are no gaps between left and right splits if the layer
1974 //is spread across BOTH halves
1975 if(cropR.right - cropR.left) {
1976 cropR.left = cropL.right;
1977 }
1978 }
1979
1980 if(cropR.right - cropR.left) {
1981 if(isYuvBuffer(hnd)) {
1982 //Always safe to even down left
1983 ovutils::even_floor(cropR.left);
1984 //If right is even, automatically width is even, since left is
1985 //already even
1986 ovutils::even_floor(cropR.right);
1987 }
1988 }
1989}
1990
Saurabh Shah88e4d272013-09-03 13:31:29 -07001991int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001992 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001993 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08001994 Rotator **rot) {
1995 private_handle_t *hnd = (private_handle_t *)layer->handle;
1996 if(!hnd) {
1997 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1998 return -1;
1999 }
2000
Saurabh Shah5daeee52013-01-23 16:52:26 +08002001 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2002
Saurabh Shahacf10202013-02-26 10:15:15 -08002003 int hw_w = ctx->dpyAttr[dpy].xres;
2004 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002005 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002006 hwc_rect_t dst = layer->displayFrame;
2007 int transform = layer->transform;
2008 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002009 int rotFlags = ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07002010 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302011 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002012
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002013 // Handle R/B swap
2014 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2015 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2016 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2017 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2018 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2019 }
2020
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002021 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002022 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2023 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002024 }
2025
2026 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002027 ActionSafe, and extorientation features. */
2028 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002029 int downscale = getRotDownscale(ctx, layer);
2030 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002031
2032 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2033 //Enable overfetch
2034 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2035 }
2036
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002037 //Will do something only if feature enabled and conditions suitable
2038 //hollow call otherwise
2039 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2040 overlay::Writeback *wb = overlay::Writeback::getInstance();
2041 whf.format = wb->getOutputFormat();
2042 }
2043
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002044 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002045 (*rot) = ctx->mRotMgr->getNext();
2046 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002047 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002048 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002049 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2050 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002051 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002052 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002053 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002054 rotFlags |= ROT_PREROTATED;
2055 }
2056
2057 eMdpFlags mdpFlagsR = mdpFlagsL;
2058 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2059
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002060 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2061 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002062
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002063 const int lSplit = getLeftSplit(ctx, dpy);
2064
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002065 // Calculate Left rects
2066 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002067 tmp_cropL = crop;
2068 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002069 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002070 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002071 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2072 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002073
2074 // Calculate Right rects
2075 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002076 tmp_cropR = crop;
2077 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002078 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002079 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002080 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2081 }
2082
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002083 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2084
Saurabh Shah94d62362013-07-02 10:58:48 -07002085 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002086 //Not needed if the layer is confined to one half of the screen.
2087 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002088 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2089 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002090 hwc_rect_t new_cropR;
2091 new_cropR.left = tmp_cropL.left;
2092 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2093
2094 hwc_rect_t new_cropL;
2095 new_cropL.left = new_cropR.right;
2096 new_cropL.right = tmp_cropR.right;
2097
2098 tmp_cropL.left = new_cropL.left;
2099 tmp_cropL.right = new_cropL.right;
2100
2101 tmp_cropR.left = new_cropR.left;
2102 tmp_cropR.right = new_cropR.right;
2103
2104 }
2105
Saurabh Shah76fd6552013-03-14 14:45:38 -07002106 //For the mdp, since either we are pre-rotating or MDP does flips
2107 orient = OVERLAY_TRANSFORM_0;
2108 transform = 0;
2109
Saurabh Shahacf10202013-02-26 10:15:15 -08002110 //configure left mixer
2111 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002112 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002113 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2114 (ovutils::eBlending) getBlending(layer->blending));
2115
Saurabh Shahacf10202013-02-26 10:15:15 -08002116 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002117 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002118 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2119 return -1;
2120 }
2121 }
2122
2123 //configure right mixer
2124 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002125 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002126 static_cast<eRotFlags>(rotFlags),
2127 layer->planeAlpha,
2128 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002129 tmp_dstR.right = tmp_dstR.right - lSplit;
2130 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002131 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002132 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002133 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2134 return -1;
2135 }
2136 }
2137
2138 return 0;
2139}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002140
radhakrishnac9a67412013-09-25 17:40:42 +05302141int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2142 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002143 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302144 Rotator **rot) {
2145 private_handle_t *hnd = (private_handle_t *)layer->handle;
2146 if(!hnd) {
2147 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2148 return -1;
2149 }
2150
2151 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2152
radhakrishnac9a67412013-09-25 17:40:42 +05302153 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2154 hwc_rect_t dst = layer->displayFrame;
2155 int transform = layer->transform;
2156 eTransform orient = static_cast<eTransform>(transform);
2157 const int downscale = 0;
2158 int rotFlags = ROT_FLAGS_NONE;
2159 //Splitting only YUV layer on primary panel needs different zorders
2160 //for both layers as both the layers are configured to single mixer
2161 eZorder lz = z;
2162 eZorder rz = (eZorder)(z + 1);
2163
2164 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302165 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302166
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002167 // update source crop and destination position of AIV video layer.
Ramkumar Radhakrishnanb33f4902014-10-03 16:46:35 -07002168 if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) {
2169 updateCoordinates(ctx, crop, dst, dpy);
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002170 }
2171
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002172 /* Calculate the external display position based on MDP downscale,
2173 ActionSafe, and extorientation features. */
2174 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2175
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002176 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302177 trimLayer(ctx, dpy, transform, crop, dst);
2178
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002179 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302180 (*rot) = ctx->mRotMgr->getNext();
2181 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002182 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002183 // BWC is not tested for other formats So enable it only for YUV format
2184 if(!dpy && isYuvBuffer(hnd))
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002185 BwcPM::setBwc(crop, dst, transform, downscale, mdpFlagsL);
radhakrishnac9a67412013-09-25 17:40:42 +05302186 //Configure rotator for pre-rotation
2187 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2188 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302189 return -1;
2190 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002191 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302192 rotFlags |= ROT_PREROTATED;
2193 }
2194
2195 eMdpFlags mdpFlagsR = mdpFlagsL;
2196 int lSplit = dst.left + (dst.right - dst.left)/2;
2197
2198 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2199 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2200
2201 if(lDest != OV_INVALID) {
2202 tmp_cropL = crop;
2203 tmp_dstL = dst;
2204 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2205 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2206 }
2207 if(rDest != OV_INVALID) {
2208 tmp_cropR = crop;
2209 tmp_dstR = dst;
2210 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2211 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2212 }
2213
2214 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2215
2216 //When buffer is H-flipped, contents of mixer config also needs to swapped
2217 //Not needed if the layer is confined to one half of the screen.
2218 //If rotator has been used then it has also done the flips, so ignore them.
2219 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2220 && rDest != OV_INVALID && (*rot) == NULL) {
2221 hwc_rect_t new_cropR;
2222 new_cropR.left = tmp_cropL.left;
2223 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2224
2225 hwc_rect_t new_cropL;
2226 new_cropL.left = new_cropR.right;
2227 new_cropL.right = tmp_cropR.right;
2228
2229 tmp_cropL.left = new_cropL.left;
2230 tmp_cropL.right = new_cropL.right;
2231
2232 tmp_cropR.left = new_cropR.left;
2233 tmp_cropR.right = new_cropR.right;
2234
2235 }
2236
2237 //For the mdp, since either we are pre-rotating or MDP does flips
2238 orient = OVERLAY_TRANSFORM_0;
2239 transform = 0;
2240
2241 //configure left half
2242 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002243 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302244 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2245 (ovutils::eBlending) getBlending(layer->blending));
2246
2247 if(configMdp(ctx->mOverlay, pargL, orient,
2248 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2249 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2250 return -1;
2251 }
2252 }
2253
2254 //configure right half
2255 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002256 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302257 static_cast<eRotFlags>(rotFlags),
2258 layer->planeAlpha,
2259 (ovutils::eBlending) getBlending(layer->blending));
2260 if(configMdp(ctx->mOverlay, pargR, orient,
2261 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2262 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2263 return -1;
2264 }
2265 }
2266
2267 return 0;
2268}
2269
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002270bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302271 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002272 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002273 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302274 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302275 * in LINE and BLOCK modes for writeback panels.
2276 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002277 if(dpy == HWC_DISPLAY_PRIMARY)
2278 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002279 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302280 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2281 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002282 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002283 return true;
2284}
2285
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002286int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2287 //Default even split for all displays with high res
2288 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2289 if(dpy == HWC_DISPLAY_PRIMARY &&
2290 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2291 //Override if split published by driver for primary
2292 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2293 }
2294 return lSplit;
2295}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002296
Saurabh Shah88e4d272013-09-03 13:31:29 -07002297bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302298 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
2299 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002300 return true;
2301 }
2302 //For testing we could split primary via device tree values
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302303 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002304 return true;
2305 }
2306 return false;
2307}
2308
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002309//clear prev layer prop flags and realloc for current frame
2310void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2311 if(ctx->layerProp[dpy]) {
2312 delete[] ctx->layerProp[dpy];
2313 ctx->layerProp[dpy] = NULL;
2314 }
2315 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2316}
2317
Ramakant Singh0def28c2014-03-28 20:43:13 +05302318bool isAbcInUse(hwc_context_t *ctx){
2319 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2320}
2321
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002322void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2323 if (ohnd != NULL && ohnd->base) {
2324 char dumpFilename[PATH_MAX];
2325 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002326 int width = getWidth(ohnd);
2327 int height = getHeight(ohnd);
2328 int format = ohnd->format;
2329 //dummy aligned w & h.
2330 int alW = 0, alH = 0;
2331 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002332 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2333 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002334 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2335 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002336 FILE* fp = fopen(dumpFilename, "w+");
2337 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002338 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002339 fclose(fp);
2340 }
2341 ALOGD("Buffer[%s] Dump to %s: %s",
2342 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2343 }
2344}
2345
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002346bool isGLESComp(hwc_context_t *ctx,
2347 hwc_display_contents_1_t* list) {
2348 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2349 for(int index = 0; index < numAppLayers; index++) {
2350 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2351 if(layer->compositionType == HWC_FRAMEBUFFER)
2352 return true;
2353 }
2354 return false;
2355}
2356
2357void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2358 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002359 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002360 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002361
2362#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002363 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2364 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2365 hint to default if the previous composition is GPU or current GPU
2366 composition is due to idle fallback */
2367 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2368 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2369 if(!gpuHint->mEGLDisplay) {
2370 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2371 return;
2372 }
2373 gpuHint->mEGLContext = eglGetCurrentContext();
2374 if(!gpuHint->mEGLContext) {
2375 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2376 return;
2377 }
2378 }
2379 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002380 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2381 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002382 EGLint attr_list[] = {EGL_GPU_HINT_1,
2383 EGL_GPU_LEVEL_3,
2384 EGL_NONE };
2385 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2386 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2387 gpuHint->mEGLContext, attr_list)) {
2388 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2389 } else {
2390 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002391 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002392 }
2393 } else {
2394 EGLint attr_list[] = {EGL_GPU_HINT_1,
2395 EGL_GPU_LEVEL_0,
2396 EGL_NONE };
2397 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2398 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2399 gpuHint->mEGLContext, attr_list)) {
2400 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2401 } else {
2402 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2403 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002404 if(MDPComp::isIdleFallback()) {
2405 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2406 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002407 }
2408 } else {
2409 /* set the GPU hint flag to default for MDP composition */
2410 EGLint attr_list[] = {EGL_GPU_HINT_1,
2411 EGL_GPU_LEVEL_0,
2412 EGL_NONE };
2413 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2414 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2415 gpuHint->mEGLContext, attr_list)) {
2416 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2417 } else {
2418 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2419 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002420 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002421 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002422#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002423}
2424
Sushil Chauhandefd3522014-05-13 18:17:12 -07002425bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2426 // To be peripheral, 3 boundaries should match.
2427 uint8_t eqBounds = 0;
2428 if (rect1.left == rect2.left)
2429 eqBounds++;
2430 if (rect1.top == rect2.top)
2431 eqBounds++;
2432 if (rect1.right == rect2.right)
2433 eqBounds++;
2434 if (rect1.bottom == rect2.bottom)
2435 eqBounds++;
2436 return (eqBounds == 3);
2437}
2438
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002439void BwcPM::setBwc(const hwc_rect_t& crop, const hwc_rect_t& dst,
2440 const int& transform,const int& downscale,
2441 ovutils::eMdpFlags& mdpFlags) {
2442 //BWC not supported with rot-downscale
2443 if(downscale) return;
2444
Saurabh Shah1a03d482013-05-29 13:44:20 -07002445 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302446 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
2447 if(!mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002448 return;
2449 }
Saurabh Shahb6810df2014-06-17 16:00:22 -07002450 int src_w = crop.right - crop.left;
2451 int src_h = crop.bottom - crop.top;
2452 int dst_w = dst.right - dst.left;
2453 int dst_h = dst.bottom - dst.top;
2454 if(transform & HAL_TRANSFORM_ROT_90) {
2455 swap(src_w, src_h);
2456 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002457 //src width > MAX mixer supported dim
Naseer Ahmed9eb5e092014-09-25 13:24:44 -04002458 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxMixerWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002459 return;
2460 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002461 //Decimation necessary, cannot use BWC. H/W requirement.
2462 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002463 uint8_t horzDeci = 0;
2464 uint8_t vertDeci = 0;
2465 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2466 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002467 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002468 }
2469 //Property
2470 char value[PROPERTY_VALUE_MAX];
2471 property_get("debug.disable.bwc", value, "0");
2472 if(atoi(value)) return;
2473
2474 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2475}
2476
Saurabh Shah23a813c2013-03-20 16:58:12 -07002477void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302478 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002479 mLayer[mCount] = layer;
2480 mRot[mCount] = rot;
2481 mCount++;
2482}
2483
2484void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302485 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002486 mLayer[i] = 0;
2487 mRot[i] = 0;
2488 }
2489 mCount = 0;
2490}
2491
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002492void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002493 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002494 reset();
2495}
2496
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302497bool LayerRotMap::isRotCached(uint32_t index) const {
2498 overlay::Rotator* rot = getRot(index);
2499 hwc_layer_1_t* layer = getLayer(index);
2500
2501 if(rot and layer and layer->handle) {
2502 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2503 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2504 }
2505 return false;
2506}
2507
Saurabh Shah23a813c2013-03-20 16:58:12 -07002508void LayerRotMap::setReleaseFd(const int& fence) {
2509 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302510 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2511 /* Ensure that none of the above (Rotator-instance,
2512 * layer and layer-handle) are NULL*/
2513 if(isRotCached(i))
2514 mRot[i]->setPrevBufReleaseFd(dup(fence));
2515 else
2516 mRot[i]->setCurrBufReleaseFd(dup(fence));
2517 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002518 }
2519}
2520
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002521void resetROI(hwc_context_t *ctx, const int dpy) {
2522 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2523 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
2524 if(isDisplaySplit(ctx, dpy)) {
2525 const int lSplit = getLeftSplit(ctx, dpy);
2526 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2527 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2528 } else {
2529 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2530 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2531 }
2532}
2533
2534hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002535{
2536 if(!isValidRect(roi))
2537 return roi;
2538
2539 struct hwc_rect t_roi = roi;
2540
2541 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2542 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2543 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2544 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2545 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002546 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002547
2548 /* Align to minimum width recommended by the panel */
2549 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2550 if((t_roi.left + MIN_WIDTH) > boundary.right)
2551 t_roi.left = t_roi.right - MIN_WIDTH;
2552 else
2553 t_roi.right = t_roi.left + MIN_WIDTH;
2554 }
2555
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002556 /* Align to minimum height recommended by the panel */
2557 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2558 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2559 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2560 else
2561 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2562 }
2563
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002564 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002565 if(LEFT_ALIGN)
2566 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2567
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002568 if(WIDTH_ALIGN) {
2569 int width = t_roi.right - t_roi.left;
2570 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2571 t_roi.right = t_roi.left + width;
2572
2573 if(t_roi.right > boundary.right) {
2574 t_roi.right = boundary.right;
2575 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002576
2577 if(LEFT_ALIGN)
2578 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002579 }
2580 }
2581
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002582
2583 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002584 if(TOP_ALIGN)
2585 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2586
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002587 if(HEIGHT_ALIGN) {
2588 int height = t_roi.bottom - t_roi.top;
2589 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2590 t_roi.bottom = t_roi.top + height;
2591
2592 if(t_roi.bottom > boundary.bottom) {
2593 t_roi.bottom = boundary.bottom;
2594 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002595
2596 if(TOP_ALIGN)
2597 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002598 }
2599 }
2600
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002601
2602 return t_roi;
2603}
2604
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002605void handle_pause(hwc_context_t* ctx, int dpy) {
2606 if(ctx->mHWCVirtual) {
2607 ctx->mHWCVirtual->pause(ctx, dpy);
2608 }
2609 return;
2610}
2611
2612void handle_resume(hwc_context_t* ctx, int dpy) {
2613 if(ctx->mHWCVirtual) {
2614 ctx->mHWCVirtual->resume(ctx, dpy);
2615 }
2616 return;
2617}
2618
Saurabh Shahacf10202013-02-26 10:15:15 -08002619};//namespace qhwc