blob: dcc7687a6745d3640ee86c9e55910d00787b7100 [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 Radhakrishnan9d7bc312014-08-13 19:38:13 -0700967 ctx->mAIVVideoMode[dpy] = 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 Radhakrishnan9d7bc312014-08-13 19:38:13 -0700977 if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) {
978 ctx->mAIVVideoMode[dpy] = true;
979 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700980 if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) {
981 ctx->listStats[dpy].isDisplayAnimating = true;
982 }
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -0700983 if(isSecureDisplayBuffer(hnd)) {
984 ctx->listStats[dpy].secureUI = true;
985 }
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700986#endif
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700987 // continue if number of app layers exceeds MAX_NUM_APP_LAYERS
988 if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS)
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -0700989 continue;
Jeykumar Sankarancf537002013-01-21 21:19:15 -0800990
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700991 //reset yuv indices
992 ctx->listStats[dpy].yuvIndices[i] = -1;
radhakrishnac9a67412013-09-25 17:40:42 +0530993 ctx->listStats[dpy].yuv4k2kIndices[i] = -1;
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -0700994
Saurabh Shah8028e3b2013-10-15 12:27:59 -0700995 if (isSecureBuffer(hnd)) {
996 ctx->listStats[dpy].isSecurePresent = true;
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -0700997 if(not isYuvBuffer(hnd)) {
998 // cache secureRGB layer parameters like we cache for YUV layers
999 int& secureRGBCount = ctx->listStats[dpy].secureRGBCount;
1000 ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i;
1001 secureRGBCount++;
1002 }
Saurabh Shah8028e3b2013-10-15 12:27:59 -07001003 }
1004
Ramkumar Radhakrishnan26bdee92013-06-20 16:56:56 -07001005 if (isSkipLayer(&list->hwLayers[i])) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001006 ctx->listStats[dpy].skipCount++;
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001007 }
1008
1009 if (UNLIKELY(isYuvBuffer(hnd))) {
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001010 int& yuvCount = ctx->listStats[dpy].yuvCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301011 ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i;
Jeykumar Sankarancf537002013-01-21 21:19:15 -08001012 yuvCount++;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001013
Raj Kamal389d6e32014-08-04 14:43:24 +05301014 if(UNLIKELY(isYUVSplitNeeded(hnd))){
radhakrishnac9a67412013-09-25 17:40:42 +05301015 int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount;
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301016 ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i;
radhakrishnac9a67412013-09-25 17:40:42 +05301017 yuv4k2kCount++;
1018 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001019 }
Sravan Kumar D.V.Nb5ed0292013-03-15 08:51:16 +05301020 if(layer->blending == HWC_BLENDING_PREMULT)
1021 ctx->listStats[dpy].preMultipliedAlpha = true;
Jeykumar Sankaran7535aba2013-02-04 11:03:09 -08001022
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001023#ifdef DYNAMIC_FPS
1024 if (dpy == HWC_DISPLAY_PRIMARY && mdpHw.isDynFpsSupported()) {
1025 //dyn fps: get refreshrate from metadata
1026 //Support multiple refresh rates if they are same
1027 //else set to default
1028 MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
1029 if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
1030 // Valid refreshRate in metadata and within the range
1031 uint32_t rate = roundOff(mdata->refreshrate);
1032 if((rate >= mdpHw.getMinFpsSupported() &&
1033 rate <= mdpHw.getMaxFpsSupported())) {
1034 if (!refreshRate) {
1035 refreshRate = rate;
1036 } else if(refreshRate != rate) {
1037 // multiple refreshrate requests, set to default
1038 refreshRate = ctx->dpyAttr[dpy].refreshRate;
1039 }
1040 }
1041 }
1042 }
1043#endif
Naseer Ahmed29a26812012-06-14 00:56:20 -07001044 }
Ping Li9404e2a2013-04-24 16:36:03 -04001045 if(ctx->listStats[dpy].yuvCount > 0) {
1046 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1047 if (atoi(property) != 1) {
1048 property_set("hw.cabl.yuv", "1");
1049 }
1050 }
1051 } else {
1052 if (property_get("hw.cabl.yuv", property, NULL) > 0) {
1053 if (atoi(property) != 0) {
1054 property_set("hw.cabl.yuv", "0");
1055 }
1056 }
1057 }
Saurabh Shahd4e65852013-06-17 11:33:53 -07001058
1059 //The marking of video begin/end is useful on some targets where we need
1060 //to have a padding round to be able to shift pipes across mixers.
1061 if(prevYuvCount != ctx->listStats[dpy].yuvCount) {
1062 ctx->mVideoTransFlag = true;
1063 }
Raj Kamal9ed3d6b2014-02-07 16:15:17 +05301064
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001065 if(dpy == HWC_DISPLAY_PRIMARY) {
1066 ctx->mAD->markDoable(ctx, list);
Arun Kumar K.Ra727a882014-08-20 17:14:26 -07001067 //Store the requested fresh rate
1068 ctx->listStats[dpy].refreshRateRequest = refreshRate ?
1069 refreshRate : ctx->dpyAttr[dpy].refreshRate;
Saurabh Shaha9da08f2013-07-03 13:27:53 -07001070 }
Naseer Ahmed29a26812012-06-14 00:56:20 -07001071}
1072
Naseer Ahmed018e5452012-12-03 14:46:15 -05001073
Saurabh Shah68107422013-07-09 11:12:42 -07001074static void calc_cut(double& leftCutRatio, double& topCutRatio,
1075 double& rightCutRatio, double& bottomCutRatio, int orient) {
Saurabh Shah27c1d652012-08-14 19:30:28 -07001076 if(orient & HAL_TRANSFORM_FLIP_H) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001077 swap(leftCutRatio, rightCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001078 }
1079 if(orient & HAL_TRANSFORM_FLIP_V) {
Saurabh Shah541b59d2012-10-11 11:08:12 -07001080 swap(topCutRatio, bottomCutRatio);
Saurabh Shah27c1d652012-08-14 19:30:28 -07001081 }
1082 if(orient & HAL_TRANSFORM_ROT_90) {
1083 //Anti clock swapping
Saurabh Shah68107422013-07-09 11:12:42 -07001084 double tmpCutRatio = leftCutRatio;
Saurabh Shah541b59d2012-10-11 11:08:12 -07001085 leftCutRatio = topCutRatio;
1086 topCutRatio = rightCutRatio;
1087 rightCutRatio = bottomCutRatio;
1088 bottomCutRatio = tmpCutRatio;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001089 }
1090}
1091
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001092bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) {
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001093 if((ctx->mMDP.version < qdutils::MDSS_V5) &&
1094 (ctx->mMDP.version > qdutils::MDP_V3_0) &&
1095 ctx->mSecuring) {
1096 return true;
1097 }
Jeykumar Sankaran85977e32013-02-25 17:06:08 -08001098 if (isSecureModePolicy(ctx->mMDP.version)) {
1099 private_handle_t *hnd = (private_handle_t *)layer->handle;
1100 if(ctx->mSecureMode) {
1101 if (! isSecureBuffer(hnd)) {
1102 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...",
1103 __FUNCTION__);
1104 return true;
1105 }
1106 } else {
1107 if (isSecureBuffer(hnd)) {
1108 ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...",
1109 __FUNCTION__);
1110 return true;
1111 }
1112 }
1113 }
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001114 return false;
1115}
1116
Sushil Chauhan2515abf2013-01-08 16:40:05 -08001117bool isSecureModePolicy(int mdpVersion) {
1118 if (mdpVersion < qdutils::MDSS_V5)
1119 return true;
1120 else
1121 return false;
1122}
Naseer Ahmed54821fe2012-11-28 18:44:38 -05001123
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001124bool isRotatorSupportedFormat(private_handle_t *hnd) {
1125 // Following rotator src formats are supported by mdp driver
1126 // TODO: Add more formats in future, if mdp driver adds support
1127 switch(hnd->format) {
1128 case HAL_PIXEL_FORMAT_RGBA_8888:
1129 case HAL_PIXEL_FORMAT_RGB_565:
1130 case HAL_PIXEL_FORMAT_RGB_888:
1131 case HAL_PIXEL_FORMAT_BGRA_8888:
1132 return true;
1133 default:
1134 return false;
1135 }
1136 return false;
1137}
1138
1139bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) {
1140 // Rotate layers, if it is YUV type or rendered by CPU and not
1141 // for the MDP versions below MDP5
1142 if((isCPURendered(hnd) && isRotatorSupportedFormat(hnd) &&
1143 !ctx->mMDP.version < qdutils::MDSS_V5)
1144 || isYuvBuffer(hnd)) {
1145 return true;
1146 }
1147 return false;
1148}
1149
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001150// returns true if Action safe dimensions are set and target supports Actionsafe
1151bool isActionSafePresent(hwc_context_t *ctx, int dpy) {
1152 // if external supports underscan, do nothing
1153 // it will be taken care in the driver
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001154 // Disable Action safe for 8974 due to HW limitation for downscaling
1155 // layers with overlapped region
1156 // Disable Actionsafe for non HDMI displays.
1157 if(!(dpy == HWC_DISPLAY_EXTERNAL) ||
1158 qdutils::MDPVersion::getInstance().is8x74v2() ||
Tatenda Chipeperekwaaf2c0042014-09-17 12:55:01 -07001159 ctx->mHDMIDisplay->isCEUnderscanSupported()) {
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001160 return false;
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08001161 }
Ramkumar Radhakrishnan4af1ef02013-12-12 11:53:08 -08001162
1163 char value[PROPERTY_VALUE_MAX];
1164 // Read action safe properties
1165 property_get("persist.sys.actionsafe.width", value, "0");
1166 ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value);
1167 property_get("persist.sys.actionsafe.height", value, "0");
1168 ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value);
1169
1170 if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) {
1171 //No action safe ratio set, return
1172 return false;
1173 }
1174 return true;
1175}
1176
Naseer Ahmed522ce662013-03-18 20:14:05 -04001177int getBlending(int blending) {
1178 switch(blending) {
1179 case HWC_BLENDING_NONE:
1180 return overlay::utils::OVERLAY_BLENDING_OPAQUE;
1181 case HWC_BLENDING_PREMULT:
1182 return overlay::utils::OVERLAY_BLENDING_PREMULT;
1183 case HWC_BLENDING_COVERAGE :
1184 default:
1185 return overlay::utils::OVERLAY_BLENDING_COVERAGE;
1186 }
1187}
1188
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001189//Crops source buffer against destination and FB boundaries
1190void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst,
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001191 const hwc_rect_t& scissor, int orient) {
1192
Saurabh Shah27c1d652012-08-14 19:30:28 -07001193 int& crop_l = crop.left;
1194 int& crop_t = crop.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001195 int& crop_r = crop.right;
1196 int& crop_b = crop.bottom;
1197 int crop_w = crop.right - crop.left;
1198 int crop_h = crop.bottom - crop.top;
1199
Saurabh Shah27c1d652012-08-14 19:30:28 -07001200 int& dst_l = dst.left;
1201 int& dst_t = dst.top;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001202 int& dst_r = dst.right;
1203 int& dst_b = dst.bottom;
Saurabh Shah27c1d652012-08-14 19:30:28 -07001204 int dst_w = abs(dst.right - dst.left);
1205 int dst_h = abs(dst.bottom - dst.top);
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001206
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001207 const int& sci_l = scissor.left;
1208 const int& sci_t = scissor.top;
1209 const int& sci_r = scissor.right;
1210 const int& sci_b = scissor.bottom;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001211
Saurabh Shah68107422013-07-09 11:12:42 -07001212 double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0,
1213 bottomCutRatio = 0.0;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001214
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001215 if(dst_l < sci_l) {
Saurabh Shah68107422013-07-09 11:12:42 -07001216 leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001217 dst_l = sci_l;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001218 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001219
1220 if(dst_r > sci_r) {
Saurabh Shah68107422013-07-09 11:12:42 -07001221 rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001222 dst_r = sci_r;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001223 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001224
1225 if(dst_t < sci_t) {
Saurabh Shah68107422013-07-09 11:12:42 -07001226 topCutRatio = (double)(sci_t - dst_t) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001227 dst_t = sci_t;
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001228 }
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001229
1230 if(dst_b > sci_b) {
Saurabh Shah68107422013-07-09 11:12:42 -07001231 bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h;
Jeykumar Sankaranb551ce42013-01-10 16:26:48 -08001232 dst_b = sci_b;
Naseer Ahmed29a26812012-06-14 00:56:20 -07001233 }
Saurabh Shah27c1d652012-08-14 19:30:28 -07001234
Saurabh Shah541b59d2012-10-11 11:08:12 -07001235 calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient);
Dileep Kumar Reddi39e79bf2014-03-06 11:56:10 +05301236 crop_l += (int)round((double)crop_w * leftCutRatio);
1237 crop_t += (int)round((double)crop_h * topCutRatio);
1238 crop_r -= (int)round((double)crop_w * rightCutRatio);
1239 crop_b -= (int)round((double)crop_h * bottomCutRatio);
Naseer Ahmed29a26812012-06-14 00:56:20 -07001240}
Naseer Ahmedf48aef62012-07-20 09:05:53 -07001241
Prabhanjan Kandula9bd5f642013-09-25 17:00:36 +05301242bool areLayersIntersecting(const hwc_layer_1_t* layer1,
1243 const hwc_layer_1_t* layer2) {
1244 hwc_rect_t irect = getIntersection(layer1->displayFrame,
1245 layer2->displayFrame);
1246 return isValidRect(irect);
1247}
1248
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08001249bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2)
1250{
1251 return ((rect1.left == rect2.left) && (rect1.top == rect2.top) &&
1252 (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom));
1253}
1254
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001255bool isValidRect(const hwc_rect& rect)
1256{
1257 return ((rect.bottom > rect.top) && (rect.right > rect.left)) ;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301258}
1259
Ramakant Singh21cec722014-03-07 19:11:45 +05301260bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) {
1261 if(lhs.left == rhs.left && lhs.top == rhs.top &&
1262 lhs.right == rhs.right && lhs.bottom == rhs.bottom )
1263 return true ;
1264 return false;
1265}
1266
Jeykumar Sankaran71e597c2014-05-07 16:23:14 -07001267hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off)
1268{
1269 hwc_rect_t res;
1270
1271 if(!isValidRect(rect))
1272 return (hwc_rect_t){0, 0, 0, 0};
1273
1274 res.left = rect.left + x_off;
1275 res.top = rect.top + y_off;
1276 res.right = rect.right + x_off;
1277 res.bottom = rect.bottom + y_off;
1278
1279 return res;
1280}
1281
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001282/* computes the intersection of two rects */
1283hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2)
1284{
1285 hwc_rect_t res;
1286
1287 if(!isValidRect(rect1) || !isValidRect(rect2)){
1288 return (hwc_rect_t){0, 0, 0, 0};
1289 }
1290
1291
1292 res.left = max(rect1.left, rect2.left);
1293 res.top = max(rect1.top, rect2.top);
1294 res.right = min(rect1.right, rect2.right);
1295 res.bottom = min(rect1.bottom, rect2.bottom);
1296
1297 if(!isValidRect(res))
1298 return (hwc_rect_t){0, 0, 0, 0};
1299
1300 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301301}
1302
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001303/* computes the union of two rects */
1304hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2)
1305{
1306 hwc_rect_t res;
1307
1308 if(!isValidRect(rect1)){
1309 return rect2;
1310 }
1311
1312 if(!isValidRect(rect2)){
1313 return rect1;
1314 }
1315
1316 res.left = min(rect1.left, rect2.left);
1317 res.top = min(rect1.top, rect2.top);
1318 res.right = max(rect1.right, rect2.right);
1319 res.bottom = max(rect1.bottom, rect2.bottom);
1320
1321 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301322}
1323
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001324/* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results
1325 * a single rect */
1326hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301327
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001328 hwc_rect_t res = rect1;
1329
1330 if((rect1.left == rect2.left) && (rect1.right == rect2.right)) {
1331 if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom))
1332 res.top = rect2.bottom;
1333 else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top))
1334 res.bottom = rect2.top;
1335 }
1336 else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) {
1337 if((rect1.left == rect2.left) && (rect2.right <= rect1.right))
1338 res.left = rect2.right;
1339 else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left))
1340 res.right = rect2.left;
1341 }
1342 return res;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301343}
1344
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001345void optimizeLayerRects(const hwc_display_contents_1_t *list) {
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301346 int i= (int)list->numHwLayers-2;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301347 while(i > 0) {
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301348 //see if there is no blending required.
Arun Kumar K.R2aa44c62014-01-21 23:08:28 -08001349 //If it is opaque see if we can substract this region from below
1350 //layers.
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301351 if(list->hwLayers[i].blending == HWC_BLENDING_NONE) {
1352 int j= i-1;
1353 hwc_rect_t& topframe =
1354 (hwc_rect_t&)list->hwLayers[i].displayFrame;
1355 while(j >= 0) {
Prabhanjan Kandula21918db2013-11-26 15:51:58 +05301356 if(!needsScaling(&list->hwLayers[j])) {
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001357 hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j];
1358 hwc_rect_t& bottomframe = layer->displayFrame;
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001359 hwc_rect_t bottomCrop =
1360 integerizeSourceCrop(layer->sourceCropf);
Sushil Chauhanfda00fc2014-03-20 11:08:41 -07001361 int transform = (layer->flags & HWC_COLOR_FILL) ? 0 :
1362 layer->transform;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001363
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001364 hwc_rect_t irect = getIntersection(bottomframe, topframe);
1365 if(isValidRect(irect)) {
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001366 hwc_rect_t dest_rect;
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001367 //if intersection is valid rect, deduct it
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001368 dest_rect = deductRect(bottomframe, irect);
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001369 qhwc::calculate_crop_rects(bottomCrop, bottomframe,
Jeykumar Sankaran1b3da402013-12-04 16:22:34 -08001370 dest_rect, transform);
Jeykumar Sankaran071468b2014-01-14 17:21:49 -08001371 //Update layer sourceCropf
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301372 layer->sourceCropf.left =(float)bottomCrop.left;
1373 layer->sourceCropf.top = (float)bottomCrop.top;
1374 layer->sourceCropf.right = (float)bottomCrop.right;
1375 layer->sourceCropf.bottom = (float)bottomCrop.bottom;
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08001376#ifdef QCOM_BSP
1377 //Update layer dirtyRect
1378 layer->dirtyRect = getIntersection(bottomCrop,
1379 layer->dirtyRect);
1380#endif
Jeykumar Sankaran93943532013-11-08 18:05:11 -08001381 }
1382 }
1383 j--;
Prabhanjan Kandulaa5dc8e92013-09-25 15:20:33 +05301384 }
1385 }
1386 i--;
1387 }
1388}
1389
Naseer Ahmed64b81212013-02-14 10:29:47 -05001390void getNonWormholeRegion(hwc_display_contents_1_t* list,
1391 hwc_rect_t& nwr)
1392{
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301393 size_t last = list->numHwLayers - 1;
Naseer Ahmed64b81212013-02-14 10:29:47 -05001394 hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame;
1395 //Initiliaze nwr to first frame
1396 nwr.left = list->hwLayers[0].displayFrame.left;
1397 nwr.top = list->hwLayers[0].displayFrame.top;
1398 nwr.right = list->hwLayers[0].displayFrame.right;
1399 nwr.bottom = list->hwLayers[0].displayFrame.bottom;
1400
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301401 for (size_t i = 1; i < last; i++) {
Naseer Ahmed64b81212013-02-14 10:29:47 -05001402 hwc_rect_t displayFrame = list->hwLayers[i].displayFrame;
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001403 nwr = getUnion(nwr, displayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001404 }
1405
1406 //Intersect with the framebuffer
Jeykumar Sankaran6a585792013-10-03 11:30:55 -07001407 nwr = getIntersection(nwr, fbDisplayFrame);
Naseer Ahmed64b81212013-02-14 10:29:47 -05001408}
1409
Saurabh Shah3e858eb2012-09-17 16:53:21 -07001410bool isExternalActive(hwc_context_t* ctx) {
1411 return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
Saurabh Shahfc2acbe2012-08-17 19:47:52 -07001412}
1413
Saurabh Shah747af1e2013-02-26 10:25:12 -08001414void closeAcquireFds(hwc_display_contents_1_t* list) {
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001415 if(LIKELY(list)) {
1416 for(uint32_t i = 0; i < list->numHwLayers; i++) {
1417 //Close the acquireFenceFds
1418 //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
1419 if(list->hwLayers[i].acquireFenceFd >= 0) {
1420 close(list->hwLayers[i].acquireFenceFd);
1421 list->hwLayers[i].acquireFenceFd = -1;
1422 }
1423 }
1424 //Writeback
1425 if(list->outbufAcquireFenceFd >= 0) {
1426 close(list->outbufAcquireFenceFd);
1427 list->outbufAcquireFenceFd = -1;
Saurabh Shah747af1e2013-02-26 10:25:12 -08001428 }
1429 }
1430}
1431
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001432int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
Saurabh Shah23a813c2013-03-20 16:58:12 -07001433 int fd) {
Naseer Ahmed099a6932013-09-09 14:25:20 -04001434 ATRACE_CALL();
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001435 int ret = 0;
Ramkumar Radhakrishnane661f962013-06-05 17:21:38 -07001436 int acquireFd[MAX_NUM_APP_LAYERS];
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001437 int count = 0;
1438 int releaseFd = -1;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001439 int retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001440 int fbFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001441 bool swapzero = false;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001442
1443 struct mdp_buf_sync data;
1444 memset(&data, 0, sizeof(data));
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001445 data.acq_fen_fd = acquireFd;
1446 data.rel_fen_fd = &releaseFd;
Arun Kumar K.R51835182013-11-19 11:20:28 -08001447 data.retire_fen_fd = &retireFd;
1448 data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001449
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001450 char property[PROPERTY_VALUE_MAX];
1451 if(property_get("debug.egl.swapinterval", property, "1") > 0) {
1452 if(atoi(property) == 0)
1453 swapzero = true;
1454 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001455
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001456 bool isExtAnimating = false;
1457 if(dpy)
1458 isExtAnimating = ctx->listStats[dpy].isDisplayAnimating;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001459
Saurabh Shah23a813c2013-03-20 16:58:12 -07001460 //Send acquireFenceFds to rotator
Saurabh Shah23a813c2013-03-20 16:58:12 -07001461 for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) {
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001462 int rotFd = ctx->mRotMgr->getRotDevFd();
1463 int rotReleaseFd = -1;
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001464 overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i);
1465 hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i);
1466 if((currRot == NULL) || (currLayer == NULL)) {
1467 continue;
1468 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001469 struct mdp_buf_sync rotData;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001470 memset(&rotData, 0, sizeof(rotData));
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001471 rotData.acq_fen_fd =
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001472 &currLayer->acquireFenceFd;
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001473 rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001474 rotData.session_id = currRot->getSessId();
Saurabh Shah25c04d32014-05-05 10:16:02 -07001475 if(currLayer->acquireFenceFd >= 0) {
1476 rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session
1477 }
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001478 int ret = 0;
Raj Kamalbd3bdc62014-08-05 18:52:49 +05301479 if(not ctx->mLayerRotMap[dpy]->isRotCached(i))
1480 ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData);
1481
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001482 if(ret < 0) {
1483 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s",
1484 __FUNCTION__, strerror(errno));
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001485 close(rotReleaseFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001486 } else {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001487 close(currLayer->acquireFenceFd);
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001488 //For MDP to wait on.
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001489 currLayer->acquireFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001490 dup(rotReleaseFd);
1491 //A buffer is free to be used by producer as soon as its copied to
1492 //rotator
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -08001493 currLayer->releaseFenceFd =
Saurabh Shahe9b5a8f2013-06-28 11:33:25 -07001494 rotReleaseFd;
1495 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001496 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001497
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301498 //Accumulate acquireFenceFds for MDP Overlays
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08001499 if(list->outbufAcquireFenceFd >= 0) {
1500 //Writeback output buffer
1501 acquireFd[count++] = list->outbufAcquireFenceFd;
1502 }
1503
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001504 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Ramakant Singh0def28c2014-03-28 20:43:13 +05301505 if(((isAbcInUse(ctx)== true ) ||
1506 (list->hwLayers[i].compositionType == HWC_OVERLAY)) &&
Saurabh Shah23a813c2013-03-20 16:58:12 -07001507 list->hwLayers[i].acquireFenceFd >= 0) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001508 if(UNLIKELY(swapzero))
1509 acquireFd[count++] = -1;
Ramakant Singh467759f2014-04-16 11:09:40 +05301510 // if ABC is enabled for more than one layer.
1511 // renderBufIndexforABC will work as FB.Hence
1512 // set the acquireFD from fd - which is coming from copybit
1513 else if(fd >= 0 && (isAbcInUse(ctx) == true)) {
1514 if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i)
1515 acquireFd[count++] = fd;
1516 else
1517 continue;
1518 } else
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001519 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001520 }
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001521 if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
1522 if(UNLIKELY(swapzero))
1523 acquireFd[count++] = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001524 else if(fd >= 0) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001525 //set the acquireFD from fd - which is coming from c2d
1526 acquireFd[count++] = fd;
1527 // Buffer sync IOCTL should be async when using c2d fence is
1528 // used
1529 data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001530 } else if(list->hwLayers[i].acquireFenceFd >= 0)
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001531 acquireFd[count++] = list->hwLayers[i].acquireFenceFd;
1532 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001533 }
1534
Arun Kumar K.Rb2a03b12014-06-03 11:54:10 -07001535 if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) {
Sushil Chauhandefd3522014-05-13 18:17:12 -07001536 // Acquire c2d fence of Overlap render buffer
1537 acquireFd[count++] = fd;
1538 }
1539
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001540 data.acq_fen_fd_cnt = count;
1541 fbFd = ctx->dpyAttr[dpy].fd;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001542
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001543 //Waits for acquire fences, returns a release fence
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001544 if(LIKELY(!swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001545 ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data);
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001546 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001547
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001548 if(ret < 0) {
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001549 ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s",
1550 __FUNCTION__, strerror(errno));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301551 ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu",
Ramkumar Radhakrishnanb32a0bc2013-04-11 17:57:32 -07001552 __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd,
1553 dpy, list->numHwLayers);
Tatenda Chipeperekwaa4550ce2014-06-06 15:25:37 -07001554 close(releaseFd);
1555 releaseFd = -1;
1556 close(retireFd);
1557 retireFd = -1;
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001558 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001559
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001560 for(uint32_t i = 0; i < list->numHwLayers; i++) {
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001561 if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001562#ifdef QCOM_BSP
Terence Hampsonc67b0372013-10-09 11:32:21 -04001563 list->hwLayers[i].compositionType == HWC_BLIT ||
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001564#endif
Arun Kumar K.R361da4f2012-11-28 10:42:59 -08001565 list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001566 //Populate releaseFenceFds.
Saurabh Shah23a813c2013-03-20 16:58:12 -07001567 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001568 list->hwLayers[i].releaseFenceFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001569 } else if(isExtAnimating) {
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001570 // Release all the app layer fds immediately,
1571 // if animation is in progress.
Ramkumar Radhakrishnana70981a2013-08-28 11:33:53 -07001572 list->hwLayers[i].releaseFenceFd = -1;
Naseer Ahmed330a2822014-03-05 11:57:23 -05001573 } else if(list->hwLayers[i].releaseFenceFd < 0 ) {
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001574#ifdef QCOM_BSP
Zohaib Alam1bb65612013-09-28 03:38:20 -04001575 //If rotator has not already populated this field
Ramakant Singh0def28c2014-03-28 20:43:13 +05301576 // & if it's a not VPU layer
Ramakant Singh467759f2014-04-16 11:09:40 +05301577
1578 // if ABC is enabled for more than one layer
1579 if(fd >= 0 && (isAbcInUse(ctx) == true) &&
1580 ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){
1581 list->hwLayers[i].releaseFenceFd = dup(fd);
1582 } else if((list->hwLayers[i].compositionType == HWC_BLIT)&&
1583 (isAbcInUse(ctx) == false)){
1584 //For Blit, the app layers should be released when the Blit
1585 //is complete. This fd was passed from copybit->draw
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301586 list->hwLayers[i].releaseFenceFd = dup(fd);
Saurabh Shah74eff4d2014-03-28 16:33:13 -07001587 } else
1588#endif
1589 {
Balamurugan Thanikachalamf558c862014-01-31 18:23:20 +05301590 list->hwLayers[i].releaseFenceFd = dup(releaseFd);
1591 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001592 }
Kinjal Bhavsar40a1cc52012-10-10 15:52:03 -07001593 }
1594 }
Saurabh Shah747af1e2013-02-26 10:25:12 -08001595
1596 if(fd >= 0) {
1597 close(fd);
1598 fd = -1;
1599 }
1600
Sushil Chauhanfb8845c2014-07-22 12:42:07 -07001601 if (ctx->mCopyBit[dpy]) {
1602 if (!dpy && ctx->mPtorInfo.isActive())
Sushil Chauhandefd3522014-05-13 18:17:12 -07001603 ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd);
1604 else
1605 ctx->mCopyBit[dpy]->setReleaseFd(releaseFd);
1606 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07001607
Saurabh Shah23a813c2013-03-20 16:58:12 -07001608 //Signals when MDP finishes reading rotator buffers.
1609 ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd);
Arun Kumar K.R51835182013-11-19 11:20:28 -08001610 close(releaseFd);
1611 releaseFd = -1;
Saurabh Shah23a813c2013-03-20 16:58:12 -07001612
Arun Kumar K.R51835182013-11-19 11:20:28 -08001613 if(UNLIKELY(swapzero)) {
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001614 list->retireFenceFd = -1;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001615 } else {
Arun Kumar K.R51835182013-11-19 11:20:28 -08001616 list->retireFenceFd = retireFd;
Naseer Ahmed94baddc2012-12-17 18:51:01 -05001617 }
Kinjal Bhavsar2dd04a82012-09-18 18:27:59 -07001618 return ret;
1619}
1620
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001621void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer,
Saurabh Shahacf10202013-02-26 10:15:15 -08001622 ovutils::eMdpFlags &mdpFlags,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001623 int rotDownscale, int transform) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001624 private_handle_t *hnd = (private_handle_t *)layer->handle;
Saurabh Shah220a30c2013-10-29 16:12:12 -07001625 MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
Saurabh Shahacf10202013-02-26 10:15:15 -08001626
1627 if(layer->blending == HWC_BLENDING_PREMULT) {
1628 ovutils::setMdpFlags(mdpFlags,
1629 ovutils::OV_MDP_BLEND_FG_PREMULT);
1630 }
1631
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001632 if(metadata && (metadata->operation & PP_PARAM_INTERLACED) &&
1633 metadata->interlaced) {
1634 ovutils::setMdpFlags(mdpFlags,
1635 ovutils::OV_MDP_DEINTERLACE);
1636 }
1637
1638 // Mark MDP flags with SECURE_OVERLAY_SESSION for driver
1639 if(isSecureBuffer(hnd)) {
1640 ovutils::setMdpFlags(mdpFlags,
1641 ovutils::OV_MDP_SECURE_OVERLAY_SESSION);
Saurabh Shahacf10202013-02-26 10:15:15 -08001642 }
1643
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001644 if(isSecureDisplayBuffer(hnd)) {
Ramkumar Radhakrishnan4ec775f2014-07-23 17:43:18 -07001645 // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver
Ramkumar Radhakrishnanba713382013-08-30 18:41:07 -07001646 ovutils::setMdpFlags(mdpFlags,
1647 ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION);
1648 }
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001649
1650 //Pre-rotation will be used using rotator.
1651 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
1652 ovutils::setMdpFlags(mdpFlags,
1653 ovutils::OV_MDP_SOURCE_ROTATED_90);
1654 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001655 //No 90 component and no rot-downscale then flips done by MDP
1656 //If we use rot then it might as well do flips
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001657 if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) {
1658 if(transform & HWC_TRANSFORM_FLIP_H) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001659 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H);
1660 }
1661
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001662 if(transform & HWC_TRANSFORM_FLIP_V) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001663 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V);
1664 }
1665 }
Saurabh Shah5daeee52013-01-23 16:52:26 +08001666
1667 if(metadata &&
1668 ((metadata->operation & PP_PARAM_HSIC)
1669 || (metadata->operation & PP_PARAM_IGC)
1670 || (metadata->operation & PP_PARAM_SHARP2))) {
1671 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN);
1672 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001673}
1674
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301675int configRotator(Rotator *rot, Whf& whf,
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001676 hwc_rect_t& crop, const eMdpFlags& mdpFlags,
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001677 const eTransform& orient, const int& downscale) {
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001678
Prabhanjan Kandulaa1d83012013-04-23 13:06:02 +05301679 // Fix alignments for TILED format
1680 if(whf.format == MDP_Y_CRCB_H2V2_TILE ||
1681 whf.format == MDP_Y_CBCR_H2V2_TILE) {
1682 whf.w = utils::alignup(whf.w, 64);
1683 whf.h = utils::alignup(whf.h, 32);
1684 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001685 rot->setSource(whf);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001686
1687 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1688 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001689 Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
1690 crop.bottom - crop.top);
Sushil Chauhan1cac8152013-05-08 15:53:51 -07001691 rot->setCrop(rotCrop);
1692 }
1693
Saurabh Shahacf10202013-02-26 10:15:15 -08001694 rot->setFlags(mdpFlags);
1695 rot->setTransform(orient);
1696 rot->setDownscale(downscale);
1697 if(!rot->commit()) return -1;
1698 return 0;
1699}
1700
Saurabh Shahe2474082013-05-15 16:32:13 -07001701int configMdp(Overlay *ov, const PipeArgs& parg,
Saurabh Shahacf10202013-02-26 10:15:15 -08001702 const eTransform& orient, const hwc_rect_t& crop,
Saurabh Shah5daeee52013-01-23 16:52:26 +08001703 const hwc_rect_t& pos, const MetaData_t *metadata,
1704 const eDest& dest) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001705 ov->setSource(parg, dest);
1706 ov->setTransform(orient, dest);
1707
1708 int crop_w = crop.right - crop.left;
1709 int crop_h = crop.bottom - crop.top;
1710 Dim dcrop(crop.left, crop.top, crop_w, crop_h);
1711 ov->setCrop(dcrop, dest);
1712
1713 int posW = pos.right - pos.left;
1714 int posH = pos.bottom - pos.top;
1715 Dim position(pos.left, pos.top, posW, posH);
1716 ov->setPosition(position, dest);
1717
Saurabh Shah5daeee52013-01-23 16:52:26 +08001718 if (metadata)
1719 ov->setVisualParams(*metadata, dest);
1720
Saurabh Shahacf10202013-02-26 10:15:15 -08001721 if (!ov->commit(dest)) {
1722 return -1;
1723 }
1724 return 0;
1725}
1726
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001727int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer,
1728 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001729 const eDest& dest) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001730
1731 hwc_rect_t dst = layer->displayFrame;
1732 trimLayer(ctx, dpy, 0, dst, dst);
1733
1734 int w = ctx->dpyAttr[dpy].xres;
1735 int h = ctx->dpyAttr[dpy].yres;
1736 int dst_w = dst.right - dst.left;
1737 int dst_h = dst.bottom - dst.top;
1738 uint32_t color = layer->transform;
1739 Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888), 0);
1740
Sushil Chauhanf10c5232013-12-19 10:35:54 -08001741 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001742 if (layer->blending == HWC_BLENDING_PREMULT)
1743 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT);
1744
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001745 PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0),
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001746 layer->planeAlpha,
1747 (ovutils::eBlending) getBlending(layer->blending));
1748
1749 // Configure MDP pipe for Color layer
1750 Dim pos(dst.left, dst.top, dst_w, dst_h);
1751 ctx->mOverlay->setSource(parg, dest);
1752 ctx->mOverlay->setColor(color, dest);
1753 ctx->mOverlay->setTransform(0, dest);
1754 ctx->mOverlay->setCrop(pos, dest);
1755 ctx->mOverlay->setPosition(pos, dest);
1756
1757 if (!ctx->mOverlay->commit(dest)) {
1758 ALOGE("%s: Configure color layer failed!", __FUNCTION__);
1759 return -1;
1760 }
1761 return 0;
1762}
1763
Saurabh Shahe2474082013-05-15 16:32:13 -07001764void updateSource(eTransform& orient, Whf& whf,
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001765 hwc_rect_t& crop, Rotator *rot) {
1766 Dim transformedCrop(crop.left, crop.top,
Saurabh Shahacf10202013-02-26 10:15:15 -08001767 crop.right - crop.left,
1768 crop.bottom - crop.top);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001769 if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
1770 qdutils::MDSS_V5) {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001771 //B-family rotator internally could modify destination dimensions if
1772 //downscaling is supported
1773 whf = rot->getDstWhf();
1774 transformedCrop = rot->getDstDimensions();
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001775 } else {
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001776 //A-family rotator rotates entire buffer irrespective of crop, forcing
1777 //us to recompute the crop based on transform
1778 orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
1779 preRotateSource(orient, whf, transformedCrop);
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001780 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001781
1782 crop.left = transformedCrop.x;
1783 crop.top = transformedCrop.y;
1784 crop.right = transformedCrop.x + transformedCrop.w;
1785 crop.bottom = transformedCrop.y + transformedCrop.h;
Saurabh Shahacf10202013-02-26 10:15:15 -08001786}
1787
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001788int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) {
1789 if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) {
1790 return 0;
1791 }
1792
1793 int downscale = 0;
1794 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
1795 hwc_rect_t dst = layer->displayFrame;
1796 private_handle_t *hnd = (private_handle_t *)layer->handle;
1797
1798 if(not hnd) {
1799 return 0;
1800 }
1801
1802 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1803 bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED)
1804 && metadata->interlaced;
1805 int transform = layer->transform;
1806 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
1807
1808 if(isYuvBuffer(hnd)) {
1809 if(ctx->mMDP.version >= qdutils::MDP_V4_2 &&
1810 ctx->mMDP.version < qdutils::MDSS_V5) {
1811 downscale = Rotator::getDownscaleFactor(crop.right - crop.left,
1812 crop.bottom - crop.top, dst.right - dst.left,
1813 dst.bottom - dst.top, format, isInterlaced);
1814 } else {
1815 Dim adjCrop(crop.left, crop.top, crop.right - crop.left,
1816 crop.bottom - crop.top);
1817 Dim pos(dst.left, dst.top, dst.right - dst.left,
1818 dst.bottom - dst.top);
1819 if(transform & HAL_TRANSFORM_ROT_90) {
1820 swap(adjCrop.w, adjCrop.h);
1821 }
1822 downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w,
1823 pos.h, format, isInterlaced);
1824 }
1825 }
1826 return downscale;
1827}
1828
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001829bool isZoomModeEnabled(hwc_rect_t crop) {
1830 // This does not work for zooming in top left corner of the image
1831 return(crop.top > 0 || crop.left > 0);
1832}
1833
1834void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) {
1835 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy,
1836 crop.left, crop.top, crop.right, crop.bottom);
1837 if(isZoomModeEnabled(crop)) {
1838 Dim srcCrop(crop.left, crop.top,
1839 crop.right - crop.left,
1840 crop.bottom - crop.top);
1841 int extW = ctx->dpyAttr[dpy].xres;
1842 int extH = ctx->dpyAttr[dpy].yres;
1843 //Crop the original video in order to fit external display aspect ratio
1844 if(srcCrop.w * extH < extW * srcCrop.h) {
1845 int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2;
1846 crop.top += offset;
1847 crop.bottom -= offset;
1848 } else {
1849 int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2;
1850 crop.left += offset;
1851 crop.right -= offset;
1852 }
1853 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1854 " source crop [%d %d %d %d]", extW, extH, dpy,
1855 crop.left, crop.top, crop.right, crop.bottom);
1856 }
1857}
1858
1859void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop,
1860 hwc_rect_t& dst, int dpy) {
1861 ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy,
1862 dst.left, dst.top, dst.right, dst.bottom);
1863 Dim srcCrop(crop.left, crop.top,
1864 crop.right - crop.left,
1865 crop.bottom - crop.top);
1866 int extW = ctx->dpyAttr[dpy].xres;
1867 int extH = ctx->dpyAttr[dpy].yres;
1868 // Set the destination coordinates of external display to full screen,
1869 // when zoom in mode is enabled or video aspect ratio matches with the
1870 // external display aspect ratio
1871 if((srcCrop.w * extH == extW * srcCrop.h) || (isZoomModeEnabled(crop))) {
1872 dst.left = 0;
1873 dst.top = 0;
1874 dst.right = extW;
1875 dst.bottom = extH;
1876 }
1877 ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified"
1878 " Destination position [%d %d %d %d] Source crop [%d %d %d %d]",
1879 extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom,
1880 crop.left, crop.top, crop.right, crop.bottom);
1881}
1882
1883void updateExtDisplayCoordinates(hwc_context_t *ctx, hwc_rect_t& crop,
1884 hwc_rect_t& dst, int dpy) {
1885 updateCropAIVVideoMode(ctx, crop, dpy);
1886 updateDestAIVVideoMode(ctx, crop, dst, dpy);
1887}
1888
Saurabh Shah88e4d272013-09-03 13:31:29 -07001889int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001890 const int& dpy, eMdpFlags& mdpFlags, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001891 const eDest& dest, Rotator **rot) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001892
1893 private_handle_t *hnd = (private_handle_t *)layer->handle;
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001894
Saurabh Shahacf10202013-02-26 10:15:15 -08001895 if(!hnd) {
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001896 if (layer->flags & HWC_COLOR_FILL) {
1897 // Configure Color layer
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001898 return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest);
Sushil Chauhan897a9c32013-07-18 11:09:55 -07001899 }
Saurabh Shahacf10202013-02-26 10:15:15 -08001900 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1901 return -1;
1902 }
1903
Saurabh Shah5daeee52013-01-23 16:52:26 +08001904 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
1905
Saurabh Shah62e1d732013-09-17 10:44:05 -07001906 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08001907 hwc_rect_t dst = layer->displayFrame;
1908 int transform = layer->transform;
1909 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001910 int rotFlags = ovutils::ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07001911 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05301912 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04001913
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07001914 // Handle R/B swap
1915 if (layer->flags & HWC_FORMAT_RB_SWAP) {
1916 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
1917 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
1918 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
1919 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
1920 }
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07001921 // update source crop and destination position of AIV video layer.
1922 if(ctx->mAIVVideoMode[dpy] && isYuvBuffer(hnd)) {
1923 updateExtDisplayCoordinates(ctx, crop, dst, dpy);
1924 }
Ramkumar Radhakrishnan939a9e72013-12-04 18:30:18 -08001925 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001926 int downscale = getRotDownscale(ctx, layer);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001927 setMdpFlags(ctx, layer, mdpFlags, downscale, transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08001928
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001929 //if 90 component or downscale, use rot
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001930 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001931 *rot = ctx->mRotMgr->getNext();
1932 if(*rot == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07001933 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08001934 // BWC is not tested for other formats So enable it only for YUV format
1935 if(!dpy && isYuvBuffer(hnd))
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001936 BwcPM::setBwc(crop, dst, transform, downscale, mdpFlags);
Saurabh Shahacf10202013-02-26 10:15:15 -08001937 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001938 if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) {
1939 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08001940 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07001941 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07001942 updateSource(orient, whf, crop, *rot);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07001943 rotFlags |= ROT_PREROTATED;
Saurabh Shahacf10202013-02-26 10:15:15 -08001944 }
1945
Saurabh Shah76fd6552013-03-14 14:45:38 -07001946 //For the mdp, since either we are pre-rotating or MDP does flips
1947 orient = OVERLAY_TRANSFORM_0;
1948 transform = 0;
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001949 PipeArgs parg(mdpFlags, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04001950 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
1951 (ovutils::eBlending) getBlending(layer->blending));
1952
Saurabh Shah5daeee52013-01-23 16:52:26 +08001953 if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08001954 ALOGE("%s: commit failed for low res panel", __FUNCTION__);
1955 return -1;
1956 }
1957 return 0;
1958}
1959
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001960//Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even
Sushil Chauhan15a2ea62013-09-04 18:28:36 -07001961void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR,
Saurabh Shahd9e426d2013-08-01 13:35:31 -07001962 private_handle_t *hnd) {
1963 if(cropL.right - cropL.left) {
1964 if(isYuvBuffer(hnd)) {
1965 //Always safe to even down left
1966 ovutils::even_floor(cropL.left);
1967 //If right is even, automatically width is even, since left is
1968 //already even
1969 ovutils::even_floor(cropL.right);
1970 }
1971 //Make sure there are no gaps between left and right splits if the layer
1972 //is spread across BOTH halves
1973 if(cropR.right - cropR.left) {
1974 cropR.left = cropL.right;
1975 }
1976 }
1977
1978 if(cropR.right - cropR.left) {
1979 if(isYuvBuffer(hnd)) {
1980 //Always safe to even down left
1981 ovutils::even_floor(cropR.left);
1982 //If right is even, automatically width is even, since left is
1983 //already even
1984 ovutils::even_floor(cropR.right);
1985 }
1986 }
1987}
1988
Saurabh Shah88e4d272013-09-03 13:31:29 -07001989int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
Ramkumar Radhakrishnan59a11072013-04-15 16:14:49 -07001990 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07001991 const eDest& lDest, const eDest& rDest,
Saurabh Shahacf10202013-02-26 10:15:15 -08001992 Rotator **rot) {
1993 private_handle_t *hnd = (private_handle_t *)layer->handle;
1994 if(!hnd) {
1995 ALOGE("%s: layer handle is NULL", __FUNCTION__);
1996 return -1;
1997 }
1998
Saurabh Shah5daeee52013-01-23 16:52:26 +08001999 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2000
Saurabh Shahacf10202013-02-26 10:15:15 -08002001 int hw_w = ctx->dpyAttr[dpy].xres;
2002 int hw_h = ctx->dpyAttr[dpy].yres;
Saurabh Shah62e1d732013-09-17 10:44:05 -07002003 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);
Saurabh Shahacf10202013-02-26 10:15:15 -08002004 hwc_rect_t dst = layer->displayFrame;
2005 int transform = layer->transform;
2006 eTransform orient = static_cast<eTransform>(transform);
Saurabh Shahacf10202013-02-26 10:15:15 -08002007 int rotFlags = ROT_FLAGS_NONE;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -07002008 uint32_t format = ovutils::getMdpFormat(hnd->format, isTileRendered(hnd));
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302009 Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size);
Zohaib Alam1bb65612013-09-28 03:38:20 -04002010
Sushil Chauhan1f6d68f2013-10-11 11:49:35 -07002011 // Handle R/B swap
2012 if (layer->flags & HWC_FORMAT_RB_SWAP) {
2013 if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888)
2014 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888);
2015 else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888)
2016 whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888);
2017 }
2018
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002019 // update source crop and destination position of AIV video layer.
2020 if(ctx->mAIVVideoMode[dpy] && isYuvBuffer(hnd)) {
2021 updateExtDisplayCoordinates(ctx, crop, dst, dpy);
2022 }
2023
2024 /* Calculate the external display position based on MDP downscale,
Ramkumar Radhakrishnana61a0da2014-03-03 14:46:21 -08002025 ActionSafe, and extorientation features. */
2026 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002027 int downscale = getRotDownscale(ctx, layer);
2028 setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform);
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002029
2030 if(lDest != OV_INVALID && rDest != OV_INVALID) {
2031 //Enable overfetch
2032 setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE);
2033 }
2034
Saurabh Shaha9da08f2013-07-03 13:27:53 -07002035 //Will do something only if feature enabled and conditions suitable
2036 //hollow call otherwise
2037 if(ctx->mAD->prepare(ctx, crop, whf, hnd)) {
2038 overlay::Writeback *wb = overlay::Writeback::getInstance();
2039 whf.format = wb->getOutputFormat();
2040 }
2041
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002042 if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002043 (*rot) = ctx->mRotMgr->getNext();
2044 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002045 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002046 //Configure rotator for pre-rotation
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002047 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2048 ALOGE("%s: configRotator failed!", __FUNCTION__);
Saurabh Shahacf10202013-02-26 10:15:15 -08002049 return -1;
Sushil Chauhan80fc1f92013-04-23 17:30:05 -07002050 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002051 updateSource(orient, whf, crop, *rot);
Saurabh Shahacf10202013-02-26 10:15:15 -08002052 rotFlags |= ROT_PREROTATED;
2053 }
2054
2055 eMdpFlags mdpFlagsR = mdpFlagsL;
2056 setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER);
2057
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002058 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2059 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
Saurabh Shahacf10202013-02-26 10:15:15 -08002060
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002061 const int lSplit = getLeftSplit(ctx, dpy);
2062
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002063 // Calculate Left rects
2064 if(dst.left < lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002065 tmp_cropL = crop;
2066 tmp_dstL = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002067 hwc_rect_t scissor = {0, 0, lSplit, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002068 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002069 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2070 }
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002071
2072 // Calculate Right rects
2073 if(dst.right > lSplit) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002074 tmp_cropR = crop;
2075 tmp_dstR = dst;
Saurabh Shah67a38c32013-06-10 16:23:15 -07002076 hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
Ramkumar Radhakrishnand8559482013-12-05 11:21:44 -08002077 scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
Saurabh Shahacf10202013-02-26 10:15:15 -08002078 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2079 }
2080
Saurabh Shahd9e426d2013-08-01 13:35:31 -07002081 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2082
Saurabh Shah94d62362013-07-02 10:58:48 -07002083 //When buffer is H-flipped, contents of mixer config also needs to swapped
Saurabh Shahacf10202013-02-26 10:15:15 -08002084 //Not needed if the layer is confined to one half of the screen.
2085 //If rotator has been used then it has also done the flips, so ignore them.
Jeykumar Sankaran8b40b432014-05-30 23:26:59 -07002086 if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
2087 (dst.right > lSplit) && (*rot) == NULL) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002088 hwc_rect_t new_cropR;
2089 new_cropR.left = tmp_cropL.left;
2090 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2091
2092 hwc_rect_t new_cropL;
2093 new_cropL.left = new_cropR.right;
2094 new_cropL.right = tmp_cropR.right;
2095
2096 tmp_cropL.left = new_cropL.left;
2097 tmp_cropL.right = new_cropL.right;
2098
2099 tmp_cropR.left = new_cropR.left;
2100 tmp_cropR.right = new_cropR.right;
2101
2102 }
2103
Saurabh Shah76fd6552013-03-14 14:45:38 -07002104 //For the mdp, since either we are pre-rotating or MDP does flips
2105 orient = OVERLAY_TRANSFORM_0;
2106 transform = 0;
2107
Saurabh Shahacf10202013-02-26 10:15:15 -08002108 //configure left mixer
2109 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002110 PipeArgs pargL(mdpFlagsL, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002111 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2112 (ovutils::eBlending) getBlending(layer->blending));
2113
Saurabh Shahacf10202013-02-26 10:15:15 -08002114 if(configMdp(ctx->mOverlay, pargL, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002115 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002116 ALOGE("%s: commit failed for left mixer config", __FUNCTION__);
2117 return -1;
2118 }
2119 }
2120
2121 //configure right mixer
2122 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002123 PipeArgs pargR(mdpFlagsR, whf, z,
Naseer Ahmed522ce662013-03-18 20:14:05 -04002124 static_cast<eRotFlags>(rotFlags),
2125 layer->planeAlpha,
2126 (ovutils::eBlending) getBlending(layer->blending));
Saurabh Shah67a38c32013-06-10 16:23:15 -07002127 tmp_dstR.right = tmp_dstR.right - lSplit;
2128 tmp_dstR.left = tmp_dstR.left - lSplit;
Saurabh Shahacf10202013-02-26 10:15:15 -08002129 if(configMdp(ctx->mOverlay, pargR, orient,
Saurabh Shah5daeee52013-01-23 16:52:26 +08002130 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
Saurabh Shahacf10202013-02-26 10:15:15 -08002131 ALOGE("%s: commit failed for right mixer config", __FUNCTION__);
2132 return -1;
2133 }
2134 }
2135
2136 return 0;
2137}
Arun Kumar K.Ra2978452013-02-07 01:34:24 -08002138
radhakrishnac9a67412013-09-25 17:40:42 +05302139int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
2140 const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z,
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002141 const eDest& lDest, const eDest& rDest,
radhakrishnac9a67412013-09-25 17:40:42 +05302142 Rotator **rot) {
2143 private_handle_t *hnd = (private_handle_t *)layer->handle;
2144 if(!hnd) {
2145 ALOGE("%s: layer handle is NULL", __FUNCTION__);
2146 return -1;
2147 }
2148
2149 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
2150
radhakrishnac9a67412013-09-25 17:40:42 +05302151 hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);;
2152 hwc_rect_t dst = layer->displayFrame;
2153 int transform = layer->transform;
2154 eTransform orient = static_cast<eTransform>(transform);
2155 const int downscale = 0;
2156 int rotFlags = ROT_FLAGS_NONE;
2157 //Splitting only YUV layer on primary panel needs different zorders
2158 //for both layers as both the layers are configured to single mixer
2159 eZorder lz = z;
2160 eZorder rz = (eZorder)(z + 1);
2161
2162 Whf whf(getWidth(hnd), getHeight(hnd),
Praveena Pachipulusud9443c72014-02-17 10:42:28 +05302163 getMdpFormat(hnd->format), (uint32_t)hnd->size);
radhakrishnac9a67412013-09-25 17:40:42 +05302164
Ramkumar Radhakrishnan9d7bc312014-08-13 19:38:13 -07002165 // update source crop and destination position of AIV video layer.
2166 if(ctx->mAIVVideoMode[dpy] && isYuvBuffer(hnd)) {
2167 updateExtDisplayCoordinates(ctx, crop, dst, dpy);
2168 }
2169
Ramkumar Radhakrishnan8ab3f5d2014-02-20 19:37:15 -08002170 /* Calculate the external display position based on MDP downscale,
2171 ActionSafe, and extorientation features. */
2172 calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient);
2173
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002174 setMdpFlags(ctx, layer, mdpFlagsL, 0, transform);
radhakrishnac9a67412013-09-25 17:40:42 +05302175 trimLayer(ctx, dpy, transform, crop, dst);
2176
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002177 if(has90Transform(layer) && isRotationDoable(ctx, hnd)) {
radhakrishnac9a67412013-09-25 17:40:42 +05302178 (*rot) = ctx->mRotMgr->getNext();
2179 if((*rot) == NULL) return -1;
Saurabh Shah39240c92014-03-31 10:31:42 -07002180 ctx->mLayerRotMap[dpy]->add(layer, *rot);
Ramkumar Radhakrishnan9d20b392013-11-15 19:32:47 -08002181 // BWC is not tested for other formats So enable it only for YUV format
2182 if(!dpy && isYuvBuffer(hnd))
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002183 BwcPM::setBwc(crop, dst, transform, downscale, mdpFlagsL);
radhakrishnac9a67412013-09-25 17:40:42 +05302184 //Configure rotator for pre-rotation
2185 if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) {
2186 ALOGE("%s: configRotator failed!", __FUNCTION__);
radhakrishnac9a67412013-09-25 17:40:42 +05302187 return -1;
2188 }
Saurabh Shah8ec9b5e2014-06-30 14:37:17 -07002189 updateSource(orient, whf, crop, *rot);
radhakrishnac9a67412013-09-25 17:40:42 +05302190 rotFlags |= ROT_PREROTATED;
2191 }
2192
2193 eMdpFlags mdpFlagsR = mdpFlagsL;
2194 int lSplit = dst.left + (dst.right - dst.left)/2;
2195
2196 hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0};
2197 hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0};
2198
2199 if(lDest != OV_INVALID) {
2200 tmp_cropL = crop;
2201 tmp_dstL = dst;
2202 hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom };
2203 qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
2204 }
2205 if(rDest != OV_INVALID) {
2206 tmp_cropR = crop;
2207 tmp_dstR = dst;
2208 hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom };
2209 qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0);
2210 }
2211
2212 sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd);
2213
2214 //When buffer is H-flipped, contents of mixer config also needs to swapped
2215 //Not needed if the layer is confined to one half of the screen.
2216 //If rotator has been used then it has also done the flips, so ignore them.
2217 if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
2218 && rDest != OV_INVALID && (*rot) == NULL) {
2219 hwc_rect_t new_cropR;
2220 new_cropR.left = tmp_cropL.left;
2221 new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
2222
2223 hwc_rect_t new_cropL;
2224 new_cropL.left = new_cropR.right;
2225 new_cropL.right = tmp_cropR.right;
2226
2227 tmp_cropL.left = new_cropL.left;
2228 tmp_cropL.right = new_cropL.right;
2229
2230 tmp_cropR.left = new_cropR.left;
2231 tmp_cropR.right = new_cropR.right;
2232
2233 }
2234
2235 //For the mdp, since either we are pre-rotating or MDP does flips
2236 orient = OVERLAY_TRANSFORM_0;
2237 transform = 0;
2238
2239 //configure left half
2240 if(lDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002241 PipeArgs pargL(mdpFlagsL, whf, lz,
radhakrishnac9a67412013-09-25 17:40:42 +05302242 static_cast<eRotFlags>(rotFlags), layer->planeAlpha,
2243 (ovutils::eBlending) getBlending(layer->blending));
2244
2245 if(configMdp(ctx->mOverlay, pargL, orient,
2246 tmp_cropL, tmp_dstL, metadata, lDest) < 0) {
2247 ALOGE("%s: commit failed for left half config", __FUNCTION__);
2248 return -1;
2249 }
2250 }
2251
2252 //configure right half
2253 if(rDest != OV_INVALID) {
Saurabh Shah2c8ad052014-08-15 13:27:46 -07002254 PipeArgs pargR(mdpFlagsR, whf, rz,
radhakrishnac9a67412013-09-25 17:40:42 +05302255 static_cast<eRotFlags>(rotFlags),
2256 layer->planeAlpha,
2257 (ovutils::eBlending) getBlending(layer->blending));
2258 if(configMdp(ctx->mOverlay, pargR, orient,
2259 tmp_cropR, tmp_dstR, metadata, rDest) < 0) {
2260 ALOGE("%s: commit failed for right half config", __FUNCTION__);
2261 return -1;
2262 }
2263 }
2264
2265 return 0;
2266}
2267
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002268bool canUseRotator(hwc_context_t *ctx, int dpy) {
Raj Kamal068f4572014-04-14 16:14:06 +05302269 if(ctx->mOverlay->isDMAMultiplexingSupported() &&
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002270 isSecondaryConnected(ctx) &&
Amara Venkata Mastan Manoj Kumar5cbac942013-08-13 19:00:14 -07002271 !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) {
Raj Kamal068f4572014-04-14 16:14:06 +05302272 /* mdss driver on certain targets support multiplexing of DMA pipe
Raj Kamala8c065f2013-10-22 14:52:45 +05302273 * in LINE and BLOCK modes for writeback panels.
2274 */
Amara Venkata Mastan Manoj Kumar9d373c02013-08-20 14:30:09 -07002275 if(dpy == HWC_DISPLAY_PRIMARY)
2276 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002277 }
Ramakant Singhb4106a12014-10-07 18:06:56 +05302278 if((ctx->mMDP.version == qdutils::MDP_V3_0_4)
2279 ||(ctx->mMDP.version == qdutils::MDP_V3_0_5))
Terence Hampson45c02ef2013-05-17 17:00:11 -04002280 return false;
Saurabh Shahe2474082013-05-15 16:32:13 -07002281 return true;
2282}
2283
Saurabh Shah07a8ca82013-08-06 18:45:42 -07002284int getLeftSplit(hwc_context_t *ctx, const int& dpy) {
2285 //Default even split for all displays with high res
2286 int lSplit = ctx->dpyAttr[dpy].xres / 2;
2287 if(dpy == HWC_DISPLAY_PRIMARY &&
2288 qdutils::MDPVersion::getInstance().getLeftSplit()) {
2289 //Override if split published by driver for primary
2290 lSplit = qdutils::MDPVersion::getInstance().getLeftSplit();
2291 }
2292 return lSplit;
2293}
Saurabh Shah1a03d482013-05-29 13:44:20 -07002294
Saurabh Shah88e4d272013-09-03 13:31:29 -07002295bool isDisplaySplit(hwc_context_t* ctx, int dpy) {
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302296 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
2297 if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002298 return true;
2299 }
2300 //For testing we could split primary via device tree values
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302301 if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) {
Saurabh Shah88e4d272013-09-03 13:31:29 -07002302 return true;
2303 }
2304 return false;
2305}
2306
Ramkumar Radhakrishnan8bb48d32013-12-30 23:11:27 -08002307//clear prev layer prop flags and realloc for current frame
2308void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) {
2309 if(ctx->layerProp[dpy]) {
2310 delete[] ctx->layerProp[dpy];
2311 ctx->layerProp[dpy] = NULL;
2312 }
2313 ctx->layerProp[dpy] = new LayerProp[numAppLayers];
2314}
2315
Ramakant Singh0def28c2014-03-28 20:43:13 +05302316bool isAbcInUse(hwc_context_t *ctx){
2317 return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0);
2318}
2319
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002320void dumpBuffer(private_handle_t *ohnd, char *bufferName) {
2321 if (ohnd != NULL && ohnd->base) {
2322 char dumpFilename[PATH_MAX];
2323 bool bResult = false;
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002324 int width = getWidth(ohnd);
2325 int height = getHeight(ohnd);
2326 int format = ohnd->format;
2327 //dummy aligned w & h.
2328 int alW = 0, alH = 0;
2329 int size = getBufferSizeAndDimensions(width, height, format, alW, alH);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002330 snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw",
2331 bufferName,
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002332 overlay::utils::getFormatString(utils::getMdpFormat(format)),
2333 width, height);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002334 FILE* fp = fopen(dumpFilename, "w+");
2335 if (NULL != fp) {
Tatenda Chipeperekwacb2a2432014-08-06 17:45:58 -07002336 bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp);
Tatenda Chipeperekwa523eac52014-05-29 14:58:39 -07002337 fclose(fp);
2338 }
2339 ALOGD("Buffer[%s] Dump to %s: %s",
2340 bufferName, dumpFilename, bResult ? "Success" : "Fail");
2341 }
2342}
2343
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002344bool isGLESComp(hwc_context_t *ctx,
2345 hwc_display_contents_1_t* list) {
2346 int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers;
2347 for(int index = 0; index < numAppLayers; index++) {
2348 hwc_layer_1_t* layer = &(list->hwLayers[index]);
2349 if(layer->compositionType == HWC_FRAMEBUFFER)
2350 return true;
2351 }
2352 return false;
2353}
2354
2355void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) {
2356 struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002357 if(!gpuHint->mGpuPerfModeEnable || !ctx || !list)
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002358 return;
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002359
2360#ifdef QCOM_BSP
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002361 /* Set the GPU hint flag to high for MIXED/GPU composition only for
2362 first frame after MDP -> GPU/MIXED mode transition. Set the GPU
2363 hint to default if the previous composition is GPU or current GPU
2364 composition is due to idle fallback */
2365 if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) {
2366 gpuHint->mEGLDisplay = eglGetCurrentDisplay();
2367 if(!gpuHint->mEGLDisplay) {
2368 ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__);
2369 return;
2370 }
2371 gpuHint->mEGLContext = eglGetCurrentContext();
2372 if(!gpuHint->mEGLContext) {
2373 ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__);
2374 return;
2375 }
2376 }
2377 if(isGLESComp(ctx, list)) {
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002378 if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU
2379 && !MDPComp::isIdleFallback()) {
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002380 EGLint attr_list[] = {EGL_GPU_HINT_1,
2381 EGL_GPU_LEVEL_3,
2382 EGL_NONE };
2383 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
2384 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2385 gpuHint->mEGLContext, attr_list)) {
2386 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2387 } else {
2388 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3;
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002389 gpuHint->mCompositionState = COMPOSITION_STATE_GPU;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002390 }
2391 } else {
2392 EGLint attr_list[] = {EGL_GPU_HINT_1,
2393 EGL_GPU_LEVEL_0,
2394 EGL_NONE };
2395 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2396 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2397 gpuHint->mEGLContext, attr_list)) {
2398 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2399 } else {
2400 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2401 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002402 if(MDPComp::isIdleFallback()) {
2403 gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK;
2404 }
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002405 }
2406 } else {
2407 /* set the GPU hint flag to default for MDP composition */
2408 EGLint attr_list[] = {EGL_GPU_HINT_1,
2409 EGL_GPU_LEVEL_0,
2410 EGL_NONE };
2411 if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) &&
2412 !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay,
2413 gpuHint->mEGLContext, attr_list)) {
2414 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
2415 } else {
2416 gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0;
2417 }
Ramkumar Radhakrishnan3efce482014-05-28 15:40:17 -07002418 gpuHint->mCompositionState = COMPOSITION_STATE_MDP;
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002419 }
Saurabh Shah74eff4d2014-03-28 16:33:13 -07002420#endif
Ramkumar Radhakrishnanfb822912014-03-14 17:28:14 -07002421}
2422
Sushil Chauhandefd3522014-05-13 18:17:12 -07002423bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) {
2424 // To be peripheral, 3 boundaries should match.
2425 uint8_t eqBounds = 0;
2426 if (rect1.left == rect2.left)
2427 eqBounds++;
2428 if (rect1.top == rect2.top)
2429 eqBounds++;
2430 if (rect1.right == rect2.right)
2431 eqBounds++;
2432 if (rect1.bottom == rect2.bottom)
2433 eqBounds++;
2434 return (eqBounds == 3);
2435}
2436
Saurabh Shahc46cf9d2014-07-02 15:22:34 -07002437void BwcPM::setBwc(const hwc_rect_t& crop, const hwc_rect_t& dst,
2438 const int& transform,const int& downscale,
2439 ovutils::eMdpFlags& mdpFlags) {
2440 //BWC not supported with rot-downscale
2441 if(downscale) return;
2442
Saurabh Shah1a03d482013-05-29 13:44:20 -07002443 //Target doesnt support Bwc
Prabhanjan Kandula5bae9f52014-05-15 16:48:18 +05302444 qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
2445 if(!mdpHw.supportsBWC()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002446 return;
2447 }
Saurabh Shahb6810df2014-06-17 16:00:22 -07002448 int src_w = crop.right - crop.left;
2449 int src_h = crop.bottom - crop.top;
2450 int dst_w = dst.right - dst.left;
2451 int dst_h = dst.bottom - dst.top;
2452 if(transform & HAL_TRANSFORM_ROT_90) {
2453 swap(src_w, src_h);
2454 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002455 //src width > MAX mixer supported dim
Naseer Ahmed9eb5e092014-09-25 13:24:44 -04002456 if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxMixerWidth()) {
Saurabh Shah1a03d482013-05-29 13:44:20 -07002457 return;
2458 }
Saurabh Shah1a03d482013-05-29 13:44:20 -07002459 //Decimation necessary, cannot use BWC. H/W requirement.
2460 if(qdutils::MDPVersion::getInstance().supportsDecimation()) {
Saurabh Shahb6810df2014-06-17 16:00:22 -07002461 uint8_t horzDeci = 0;
2462 uint8_t vertDeci = 0;
2463 ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci,
2464 vertDeci);
Saurabh Shahc5b96dc2013-06-05 13:19:52 -07002465 if(horzDeci || vertDeci) return;
Saurabh Shah1a03d482013-05-29 13:44:20 -07002466 }
2467 //Property
2468 char value[PROPERTY_VALUE_MAX];
2469 property_get("debug.disable.bwc", value, "0");
2470 if(atoi(value)) return;
2471
2472 ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN);
2473}
2474
Saurabh Shah23a813c2013-03-20 16:58:12 -07002475void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) {
Raj Kamal389d6e32014-08-04 14:43:24 +05302476 if(mCount >= RotMgr::MAX_ROT_SESS) return;
Saurabh Shah23a813c2013-03-20 16:58:12 -07002477 mLayer[mCount] = layer;
2478 mRot[mCount] = rot;
2479 mCount++;
2480}
2481
2482void LayerRotMap::reset() {
Raj Kamal389d6e32014-08-04 14:43:24 +05302483 for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) {
Saurabh Shah23a813c2013-03-20 16:58:12 -07002484 mLayer[i] = 0;
2485 mRot[i] = 0;
2486 }
2487 mCount = 0;
2488}
2489
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002490void LayerRotMap::clear() {
Saurabh Shah7a606842013-12-11 14:36:04 -08002491 RotMgr::getInstance()->markUnusedTop(mCount);
Saurabh Shahda5b3ce2013-11-26 10:48:06 -08002492 reset();
2493}
2494
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302495bool LayerRotMap::isRotCached(uint32_t index) const {
2496 overlay::Rotator* rot = getRot(index);
2497 hwc_layer_1_t* layer = getLayer(index);
2498
2499 if(rot and layer and layer->handle) {
2500 private_handle_t *hnd = (private_handle_t *)(layer->handle);
2501 return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset)));
2502 }
2503 return false;
2504}
2505
Saurabh Shah23a813c2013-03-20 16:58:12 -07002506void LayerRotMap::setReleaseFd(const int& fence) {
2507 for(uint32_t i = 0; i < mCount; i++) {
Raj Kamalbd3bdc62014-08-05 18:52:49 +05302508 if(mRot[i] and mLayer[i] and mLayer[i]->handle) {
2509 /* Ensure that none of the above (Rotator-instance,
2510 * layer and layer-handle) are NULL*/
2511 if(isRotCached(i))
2512 mRot[i]->setPrevBufReleaseFd(dup(fence));
2513 else
2514 mRot[i]->setCurrBufReleaseFd(dup(fence));
2515 }
Saurabh Shah23a813c2013-03-20 16:58:12 -07002516 }
2517}
2518
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002519void resetROI(hwc_context_t *ctx, const int dpy) {
2520 const int fbXRes = (int)ctx->dpyAttr[dpy].xres;
2521 const int fbYRes = (int)ctx->dpyAttr[dpy].yres;
2522 if(isDisplaySplit(ctx, dpy)) {
2523 const int lSplit = getLeftSplit(ctx, dpy);
2524 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes};
2525 ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes};
2526 } else {
2527 ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes};
2528 ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0};
2529 }
2530}
2531
2532hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary)
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002533{
2534 if(!isValidRect(roi))
2535 return roi;
2536
2537 struct hwc_rect t_roi = roi;
2538
2539 const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign();
2540 const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign();
2541 const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign();
2542 const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign();
2543 const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth();
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002544 const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight();
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002545
2546 /* Align to minimum width recommended by the panel */
2547 if((t_roi.right - t_roi.left) < MIN_WIDTH) {
2548 if((t_roi.left + MIN_WIDTH) > boundary.right)
2549 t_roi.left = t_roi.right - MIN_WIDTH;
2550 else
2551 t_roi.right = t_roi.left + MIN_WIDTH;
2552 }
2553
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002554 /* Align to minimum height recommended by the panel */
2555 if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) {
2556 if((t_roi.top + MIN_HEIGHT) > boundary.bottom)
2557 t_roi.top = t_roi.bottom - MIN_HEIGHT;
2558 else
2559 t_roi.bottom = t_roi.top + MIN_HEIGHT;
2560 }
2561
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002562 /* Align left and width to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002563 if(LEFT_ALIGN)
2564 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
2565
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002566 if(WIDTH_ALIGN) {
2567 int width = t_roi.right - t_roi.left;
2568 width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN);
2569 t_roi.right = t_roi.left + width;
2570
2571 if(t_roi.right > boundary.right) {
2572 t_roi.right = boundary.right;
2573 t_roi.left = t_roi.right - width;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002574
2575 if(LEFT_ALIGN)
2576 t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002577 }
2578 }
2579
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002580
2581 /* Align top and height to meet panel restrictions */
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002582 if(TOP_ALIGN)
2583 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
2584
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002585 if(HEIGHT_ALIGN) {
2586 int height = t_roi.bottom - t_roi.top;
2587 height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN);
2588 t_roi.bottom = t_roi.top + height;
2589
2590 if(t_roi.bottom > boundary.bottom) {
2591 t_roi.bottom = boundary.bottom;
2592 t_roi.top = t_roi.bottom - height;
Jeykumar Sankaran6c7eeac2013-11-18 11:19:45 -08002593
2594 if(TOP_ALIGN)
2595 t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN);
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002596 }
2597 }
2598
Jeykumar Sankaran7c852382014-02-26 18:26:58 -08002599
2600 return t_roi;
2601}
2602
Manoj Kumar AVM9591a5e2014-08-21 22:50:21 -07002603void handle_pause(hwc_context_t* ctx, int dpy) {
2604 if(ctx->mHWCVirtual) {
2605 ctx->mHWCVirtual->pause(ctx, dpy);
2606 }
2607 return;
2608}
2609
2610void handle_resume(hwc_context_t* ctx, int dpy) {
2611 if(ctx->mHWCVirtual) {
2612 ctx->mHWCVirtual->resume(ctx, dpy);
2613 }
2614 return;
2615}
2616
Saurabh Shahacf10202013-02-26 10:15:15 -08002617};//namespace qhwc