Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Zohaib Alam | c9d00cd | 2014-01-24 16:38:32 -0500 | [diff] [blame] | 3 | * Copyright (C) 2012-2014, The Linux Foundation All rights reserved. |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 4 | * |
| 5 | * Not a Contribution, Apache license notifications and license are retained |
| 6 | * for attribution purposes only. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 7 | * |
| 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 Ahmed | 099a693 | 2013-09-09 14:25:20 -0400 | [diff] [blame] | 20 | #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 21 | #define HWC_UTILS_DEBUG 0 |
Saurabh Shah | c5b96dc | 2013-06-05 13:19:52 -0700 | [diff] [blame] | 22 | #include <math.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 23 | #include <sys/ioctl.h> |
Naseer Ahmed | 66e9788 | 2013-03-19 20:42:11 -0400 | [diff] [blame] | 24 | #include <linux/fb.h> |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 25 | #include <binder/IServiceManager.h> |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 26 | #include <EGL/egl.h> |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 27 | #include <cutils/properties.h> |
Naseer Ahmed | 099a693 | 2013-09-09 14:25:20 -0400 | [diff] [blame] | 28 | #include <utils/Trace.h> |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 29 | #include <gralloc_priv.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 30 | #include <overlay.h> |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 31 | #include <overlayRotator.h> |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 32 | #include <overlayWriteback.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 33 | #include "hwc_utils.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 34 | #include "hwc_mdpcomp.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 35 | #include "hwc_fbupdate.h" |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 36 | #include "hwc_ad.h" |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 37 | #include "mdp_version.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 38 | #include "hwc_copybit.h" |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 39 | #include "hwc_dump_layers.h" |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 40 | #include "hdmi.h" |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 41 | #include "hwc_qclient.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 42 | #include "QService.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 43 | #include "comptype.h" |
Ramkumar Radhakrishnan | 8bb48d3 | 2013-12-30 23:11:27 -0800 | [diff] [blame] | 44 | #include "hwc_virtual.h" |
Tatenda Chipeperekwa | a7dd23c | 2014-03-05 13:02:24 -0800 | [diff] [blame] | 45 | #include "qd_utils.h" |
Ramakant Singh | 98c533c | 2014-09-30 19:01:54 +0530 | [diff] [blame] | 46 | #include <sys/sysinfo.h> |
Krishna Chaitanya Parimi | db992fd | 2014-10-22 20:50:50 +0530 | [diff] [blame] | 47 | #include <dlfcn.h> |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 48 | #include <video/msm_hdmi_modes.h> |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 49 | |
| 50 | using namespace qClient; |
| 51 | using namespace qService; |
| 52 | using namespace android; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 53 | using namespace overlay; |
| 54 | using namespace overlay::utils; |
| 55 | namespace ovutils = overlay::utils; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 56 | |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 57 | #ifdef QCOM_BSP |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 58 | #ifdef __cplusplus |
| 59 | extern "C" { |
| 60 | #endif |
| 61 | |
| 62 | EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx, |
| 63 | EGLint *attrib_list); |
| 64 | #define EGL_GPU_HINT_1 0x32D0 |
| 65 | #define EGL_GPU_HINT_2 0x32D1 |
| 66 | |
| 67 | #define EGL_GPU_LEVEL_0 0x0 |
| 68 | #define EGL_GPU_LEVEL_1 0x1 |
| 69 | #define EGL_GPU_LEVEL_2 0x2 |
| 70 | #define EGL_GPU_LEVEL_3 0x3 |
| 71 | #define EGL_GPU_LEVEL_4 0x4 |
| 72 | #define EGL_GPU_LEVEL_5 0x5 |
| 73 | |
| 74 | #ifdef __cplusplus |
| 75 | } |
| 76 | #endif |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 77 | #endif |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 78 | |
Ramakant Singh | b8369bf | 2014-10-29 18:42:43 +0530 | [diff] [blame] | 79 | #define PROP_DEFAULT_APPBUFFER "sf.default.app_buffer_count" |
Ramakant Singh | 98c533c | 2014-09-30 19:01:54 +0530 | [diff] [blame] | 80 | #define MAX_RAM_SIZE 512*1024*1024 |
| 81 | #define qHD_WIDTH 540 |
| 82 | |
| 83 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 84 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 85 | |
Arun Kumar K.R | 053dc50 | 2014-11-13 11:13:43 -0800 | [diff] [blame] | 86 | // Std refresh rates for digital videos- 24p, 30p, 48p and 60p |
| 87 | uint32_t stdRefreshRates[] = { 30, 24, 48, 60 }; |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 88 | |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 89 | bool isValidResolution(hwc_context_t *ctx, uint32_t xres, uint32_t yres) |
| 90 | { |
Jeykumar Sankaran | 3930580 | 2014-12-12 17:55:57 -0800 | [diff] [blame] | 91 | return !((xres > qdutils::MDPVersion::getInstance().getMaxPipeWidth() && |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 92 | !isDisplaySplit(ctx, HWC_DISPLAY_PRIMARY)) || |
| 93 | (xres < MIN_DISPLAY_XRES || yres < MIN_DISPLAY_YRES)); |
| 94 | } |
| 95 | |
Praveena Pachipulusu | 49d6206 | 2014-06-06 19:22:23 +0530 | [diff] [blame] | 96 | void changeResolution(hwc_context_t *ctx, int xres_orig, int yres_orig, |
| 97 | int width, int height) { |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 98 | //Store original display resolution. |
Dileep Kumar Reddi | e351d84 | 2014-03-25 10:39:21 +0530 | [diff] [blame] | 99 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_orig; |
| 100 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_orig; |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 101 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = false; |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 102 | char property[PROPERTY_VALUE_MAX] = {'\0'}; |
| 103 | char *yptr = NULL; |
| 104 | if (property_get("debug.hwc.fbsize", property, NULL) > 0) { |
| 105 | yptr = strcasestr(property,"x"); |
Raj Kamal | 4a44308 | 2014-10-12 21:07:59 +0530 | [diff] [blame] | 106 | if(yptr) { |
| 107 | int xres_new = atoi(property); |
| 108 | int yres_new = atoi(yptr + 1); |
| 109 | if (isValidResolution(ctx,xres_new,yres_new) && |
| 110 | xres_new != xres_orig && yres_new != yres_orig) { |
| 111 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres_new = xres_new; |
| 112 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres_new = yres_new; |
| 113 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].customFBSize = true; |
Praveena Pachipulusu | 49d6206 | 2014-06-06 19:22:23 +0530 | [diff] [blame] | 114 | |
Raj Kamal | 4a44308 | 2014-10-12 21:07:59 +0530 | [diff] [blame] | 115 | //Caluculate DPI according to changed resolution. |
| 116 | float xdpi = ((float)xres_new * 25.4f) / (float)width; |
| 117 | float ydpi = ((float)yres_new * 25.4f) / (float)height; |
| 118 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi; |
| 119 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi; |
| 120 | } |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 125 | // Initialize hdmi display attributes based on |
| 126 | // hdmi display class state |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 127 | void updateDisplayInfo(hwc_context_t* ctx, int dpy) { |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 128 | ctx->dpyAttr[dpy].fd = ctx->mHDMIDisplay->getFd(); |
| 129 | ctx->dpyAttr[dpy].xres = ctx->mHDMIDisplay->getWidth(); |
| 130 | ctx->dpyAttr[dpy].yres = ctx->mHDMIDisplay->getHeight(); |
| 131 | ctx->dpyAttr[dpy].mMDPScalingMode = ctx->mHDMIDisplay->getMDPScalingMode(); |
| 132 | ctx->dpyAttr[dpy].vsync_period = ctx->mHDMIDisplay->getVsyncPeriod(); |
Arun Kumar K.R | 074c9cf | 2014-08-21 18:43:53 -0700 | [diff] [blame] | 133 | //FIXME: for now assume HDMI as secure |
| 134 | //Will need to read the HDCP status from the driver |
| 135 | //and update this accordingly |
| 136 | ctx->dpyAttr[dpy].secure = true; |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 137 | ctx->mViewFrame[dpy].left = 0; |
| 138 | ctx->mViewFrame[dpy].top = 0; |
| 139 | ctx->mViewFrame[dpy].right = ctx->dpyAttr[dpy].xres; |
| 140 | ctx->mViewFrame[dpy].bottom = ctx->dpyAttr[dpy].yres; |
| 141 | } |
| 142 | |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 143 | // Reset hdmi display attributes and list stats structures |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 144 | void resetDisplayInfo(hwc_context_t* ctx, int dpy) { |
| 145 | memset(&(ctx->dpyAttr[dpy]), 0, sizeof(ctx->dpyAttr[dpy])); |
| 146 | memset(&(ctx->listStats[dpy]), 0, sizeof(ctx->listStats[dpy])); |
| 147 | // We reset the fd to -1 here but External display class is responsible |
| 148 | // for it when the display is disconnected. This is handled as part of |
| 149 | // EXTERNAL_OFFLINE event. |
| 150 | ctx->dpyAttr[dpy].fd = -1; |
| 151 | } |
| 152 | |
| 153 | // Initialize composition resources |
| 154 | void initCompositionResources(hwc_context_t* ctx, int dpy) { |
| 155 | ctx->mFBUpdate[dpy] = IFBUpdate::getObject(ctx, dpy); |
| 156 | ctx->mMDPComp[dpy] = MDPComp::getObject(ctx, dpy); |
| 157 | } |
| 158 | |
| 159 | void destroyCompositionResources(hwc_context_t* ctx, int dpy) { |
| 160 | if(ctx->mFBUpdate[dpy]) { |
| 161 | delete ctx->mFBUpdate[dpy]; |
| 162 | ctx->mFBUpdate[dpy] = NULL; |
| 163 | } |
| 164 | if(ctx->mMDPComp[dpy]) { |
| 165 | delete ctx->mMDPComp[dpy]; |
| 166 | ctx->mMDPComp[dpy] = NULL; |
| 167 | } |
| 168 | } |
| 169 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 170 | static int openFramebufferDevice(hwc_context_t *ctx) |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 171 | { |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 172 | struct fb_fix_screeninfo finfo; |
| 173 | struct fb_var_screeninfo info; |
| 174 | |
| 175 | int fb_fd = openFb(HWC_DISPLAY_PRIMARY); |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 176 | if(fb_fd < 0) { |
| 177 | ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno)); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 178 | return -errno; |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) { |
| 182 | ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__, |
| 183 | strerror(errno)); |
| 184 | close(fb_fd); |
| 185 | return -errno; |
| 186 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 187 | |
| 188 | if (int(info.width) <= 0 || int(info.height) <= 0) { |
| 189 | // the driver doesn't return that information |
| 190 | // default to 160 dpi |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 191 | info.width = (int)(((float)info.xres * 25.4f)/160.0f + 0.5f); |
| 192 | info.height = (int)(((float)info.yres * 25.4f)/160.0f + 0.5f); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 193 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 194 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 195 | float xdpi = ((float)info.xres * 25.4f) / (float)info.width; |
| 196 | float ydpi = ((float)info.yres * 25.4f) / (float)info.height; |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 197 | |
| 198 | #ifdef MSMFB_METADATA_GET |
| 199 | struct msmfb_metadata metadata; |
| 200 | memset(&metadata, 0 , sizeof(metadata)); |
| 201 | metadata.op = metadata_op_frame_rate; |
| 202 | |
| 203 | if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) { |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 204 | ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__, |
| 205 | strerror(errno)); |
| 206 | close(fb_fd); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 207 | return -errno; |
| 208 | } |
| 209 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 210 | float fps = (float)metadata.data.panel_frame_rate; |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 211 | #else |
| 212 | //XXX: Remove reserved field usage on all baselines |
| 213 | //The reserved[3] field is used to store FPS by the driver. |
| 214 | float fps = info.reserved[3] & 0xFF; |
| 215 | #endif |
| 216 | |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 217 | if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) { |
| 218 | ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__, |
| 219 | strerror(errno)); |
| 220 | close(fb_fd); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 221 | return -errno; |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 222 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 223 | |
| 224 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd; |
| 225 | //xres, yres may not be 32 aligned |
| 226 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8); |
| 227 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres; |
| 228 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres; |
| 229 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi; |
| 230 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi; |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 231 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].refreshRate = (uint32_t)fps; |
| 232 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].dynRefreshRate = (uint32_t)fps; |
Arun Kumar K.R | 074c9cf | 2014-08-21 18:43:53 -0700 | [diff] [blame] | 233 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].secure = true; |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 234 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = |
| 235 | (uint32_t)(1000000000l / fps); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 236 | |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 237 | //To change resolution of primary display |
Praveena Pachipulusu | 49d6206 | 2014-06-06 19:22:23 +0530 | [diff] [blame] | 238 | changeResolution(ctx, info.xres, info.yres, info.width, info.height); |
Dileep Kumar Reddi | bf2678b | 2014-01-29 15:33:32 +0530 | [diff] [blame] | 239 | |
Naseer Ahmed | 22616d9 | 2013-05-15 17:20:26 -0400 | [diff] [blame] | 240 | //Unblank primary on first boot |
| 241 | if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) { |
| 242 | ALOGE("%s: Failed to unblank display", __FUNCTION__); |
| 243 | return -errno; |
| 244 | } |
| 245 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true; |
| 246 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 247 | return 0; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Ramakant Singh | 98c533c | 2014-09-30 19:01:54 +0530 | [diff] [blame] | 250 | static void changeDefaultAppBufferCount() { |
| 251 | struct sysinfo info; |
| 252 | unsigned long int ramSize = 0; |
| 253 | if (!sysinfo(&info)) { |
| 254 | ramSize = info.totalram ; |
| 255 | } |
| 256 | int fb_fd = -1; |
| 257 | struct fb_var_screeninfo sInfo ={0}; |
| 258 | fb_fd = open("/dev/graphics/fb0", O_RDONLY); |
| 259 | if (fb_fd >=0) { |
| 260 | ioctl(fb_fd, FBIOGET_VSCREENINFO, &sInfo); |
| 261 | close(fb_fd); |
| 262 | } |
| 263 | if ((ramSize && ramSize < MAX_RAM_SIZE) && |
| 264 | (sInfo.xres && sInfo.xres <= qHD_WIDTH )) { |
| 265 | property_set(PROP_DEFAULT_APPBUFFER, "2"); |
| 266 | } |
| 267 | } |
| 268 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 269 | void initContext(hwc_context_t *ctx) |
| 270 | { |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 271 | overlay::Overlay::initOverlay(); |
| 272 | ctx->mHDMIDisplay = new HDMIDisplay(); |
| 273 | uint32_t priW = 0, priH = 0; |
| 274 | // 1. HDMI as Primary |
| 275 | // -If HDMI cable is connected, read display configs from edid data |
| 276 | // -If HDMI cable is not connected then use default data in vscreeninfo |
| 277 | // 2. HDMI as External |
| 278 | // -Initialize HDMI class for use with external display |
| 279 | // -Use vscreeninfo to populate display configs |
| 280 | if(ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) { |
| 281 | int connected = ctx->mHDMIDisplay->getConnectedState(); |
| 282 | if(connected == 1) { |
| 283 | ctx->mHDMIDisplay->configure(); |
| 284 | updateDisplayInfo(ctx, HWC_DISPLAY_PRIMARY); |
| 285 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true; |
| 286 | } else { |
| 287 | openFramebufferDevice(ctx); |
| 288 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = false; |
| 289 | } |
| 290 | } else { |
| 291 | openFramebufferDevice(ctx); |
| 292 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true; |
| 293 | // Send the primary resolution to the hdmi display class |
| 294 | // to be used for MDP scaling functionality |
| 295 | priW = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres; |
| 296 | priH = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres; |
| 297 | ctx->mHDMIDisplay->setPrimaryAttributes(priW, priH); |
| 298 | } |
| 299 | |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 300 | char value[PROPERTY_VALUE_MAX]; |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 301 | ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 302 | ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); |
| 303 | ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 304 | ctx->mOverlay = overlay::Overlay::getInstance(); |
Saurabh Shah | 7a60684 | 2013-12-11 14:36:04 -0800 | [diff] [blame] | 305 | ctx->mRotMgr = RotMgr::getInstance(); |
Saurabh Shah | cd01835 | 2014-11-11 13:54:19 -0800 | [diff] [blame] | 306 | ctx->mBWCEnabled = qdutils::MDPVersion::getInstance().supportsBWC(); |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 307 | |
Ramakant Singh | 98c533c | 2014-09-30 19:01:54 +0530 | [diff] [blame] | 308 | //default_app_buffer for ferrum |
| 309 | if (ctx->mMDP.version == qdutils::MDP_V3_0_5) { |
| 310 | changeDefaultAppBufferCount(); |
| 311 | } |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 312 | // Initialize composition objects for the primary display |
| 313 | initCompositionResources(ctx, HWC_DISPLAY_PRIMARY); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 314 | |
Arun Kumar K.R | 9fc8997 | 2014-01-02 17:01:02 -0800 | [diff] [blame] | 315 | // Check if the target supports copybit compostion (dyn/mdp) to |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 316 | // decide if we need to open the copybit module. |
| 317 | int compositionType = |
| 318 | qdutils::QCCompositionType::getInstance().getCompositionType(); |
| 319 | |
Arun Kumar K.R | 9fc8997 | 2014-01-02 17:01:02 -0800 | [diff] [blame] | 320 | // Only MDP copybit is used |
| 321 | if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN | |
| 322 | qdutils::COMPOSITION_TYPE_MDP)) && |
Ramakant Singh | b4106a1 | 2014-10-07 18:06:56 +0530 | [diff] [blame] | 323 | ((qdutils::MDPVersion::getInstance().getMDPVersion() == |
| 324 | qdutils::MDP_V3_0_4) || |
Arun Kumar K.R | 9fc8997 | 2014-01-02 17:01:02 -0800 | [diff] [blame] | 325 | (qdutils::MDPVersion::getInstance().getMDPVersion() == |
Ramakant Singh | b4106a1 | 2014-10-07 18:06:56 +0530 | [diff] [blame] | 326 | qdutils::MDP_V3_0_5))) { |
Arun Kumar K.R | 9fc8997 | 2014-01-02 17:01:02 -0800 | [diff] [blame] | 327 | ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx, |
| 328 | HWC_DISPLAY_PRIMARY); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 329 | } |
| 330 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 331 | ctx->mHWCVirtual = new HWCVirtualVDS(); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 332 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false; |
| 333 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false; |
| 334 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false; |
| 335 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false; |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 336 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mMDPScalingMode= false; |
| 337 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mMDPScalingMode = false; |
| 338 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mMDPScalingMode = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 339 | |
Arun Kumar K.R | 81f3f2e | 2014-06-23 14:03:12 -0700 | [diff] [blame] | 340 | //Initialize the primary display viewFrame info |
| 341 | ctx->mViewFrame[HWC_DISPLAY_PRIMARY].left = 0; |
| 342 | ctx->mViewFrame[HWC_DISPLAY_PRIMARY].top = 0; |
| 343 | ctx->mViewFrame[HWC_DISPLAY_PRIMARY].right = |
| 344 | (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres; |
| 345 | ctx->mViewFrame[HWC_DISPLAY_PRIMARY].bottom = |
| 346 | (int)ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres; |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 347 | |
Amara Venkata Mastan Manoj Kumar | 7fb1327 | 2013-07-01 13:59:34 -0700 | [diff] [blame] | 348 | for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 349 | ctx->mHwcDebug[i] = new HwcDebug(i); |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 350 | ctx->mLayerRotMap[i] = new LayerRotMap(); |
Ramkumar Radhakrishnan | a70981a | 2013-08-28 11:33:53 -0700 | [diff] [blame] | 351 | ctx->mAnimationState[i] = ANIMATION_STOPPED; |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 352 | ctx->dpyAttr[i].mActionSafePresent = false; |
| 353 | ctx->dpyAttr[i].mAsWidthRatio = 0; |
| 354 | ctx->dpyAttr[i].mAsHeightRatio = 0; |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 355 | ctx->dpyAttr[i].s3dMode = HDMI_S3D_NONE; |
| 356 | ctx->dpyAttr[i].s3dModeForced = false; |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 357 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 358 | |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 359 | //Make sure that the 3D mode is unset at bootup |
| 360 | //This makes sure that the state is accurate on framework reboots |
| 361 | ctx->mHDMIDisplay->configure3D(HDMI_S3D_NONE); |
| 362 | |
Raj Kamal | 9ed3d6b | 2014-02-07 16:15:17 +0530 | [diff] [blame] | 363 | for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
| 364 | ctx->mPrevHwLayerCount[i] = 0; |
| 365 | } |
| 366 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 367 | MDPComp::init(ctx); |
Saurabh Shah | c4f1fa6 | 2013-09-03 13:12:14 -0700 | [diff] [blame] | 368 | ctx->mAD = new AssertiveDisplay(ctx); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 369 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 370 | ctx->vstate.enable = false; |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 371 | ctx->vstate.fakevsync = false; |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 372 | ctx->mExtOrientation = 0; |
Raj Kamal | 52b4fdb | 2014-01-27 19:35:13 +0530 | [diff] [blame] | 373 | ctx->numActiveDisplays = 1; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 374 | |
| 375 | //Right now hwc starts the service but anybody could do it, or it could be |
| 376 | //independent process as well. |
| 377 | QService::init(); |
| 378 | sp<IQClient> client = new QClient(ctx); |
Charles Bin | dab3938 | 2014-06-30 10:34:30 -0700 | [diff] [blame] | 379 | android::sp<qService::IQService> qservice_sp = interface_cast<IQService>( |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 380 | defaultServiceManager()->getService( |
Charles Bin | dab3938 | 2014-06-30 10:34:30 -0700 | [diff] [blame] | 381 | String16("display.qservice"))); |
| 382 | if (qservice_sp.get()) { |
| 383 | qservice_sp->connect(client); |
| 384 | } else { |
| 385 | ALOGE("%s: Failed to acquire service pointer", __FUNCTION__); |
| 386 | return ; |
| 387 | } |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 388 | |
Ramkumar Radhakrishnan | a70981a | 2013-08-28 11:33:53 -0700 | [diff] [blame] | 389 | // Initialize device orientation to its default orientation |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 390 | ctx->deviceOrientation = 0; |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 391 | ctx->mBufferMirrorMode = false; |
Zohaib Alam | 1bb6561 | 2013-09-28 03:38:20 -0400 | [diff] [blame] | 392 | |
Ramkumar Radhakrishnan | 812999a | 2014-09-11 21:42:07 -0700 | [diff] [blame] | 393 | property_get("sys.hwc.windowbox_aspect_ratio_tolerance", value, "0"); |
| 394 | ctx->mAspectRatioToleranceLevel = (((float)atoi(value)) / 100.0f); |
| 395 | |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 396 | ctx->enableABC = false; |
| 397 | property_get("debug.sf.hwc.canUseABC", value, "0"); |
| 398 | ctx->enableABC = atoi(value) ? true : false; |
| 399 | |
Krishna Chaitanya Parimi | db992fd | 2014-10-22 20:50:50 +0530 | [diff] [blame] | 400 | // Initializing boot anim completed check to false |
| 401 | ctx->mBootAnimCompleted = false; |
| 402 | |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 403 | // Initialize gpu perfomance hint related parameters |
| 404 | property_get("sys.hwc.gpu_perf_mode", value, "0"); |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 405 | #ifdef QCOM_BSP |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 406 | ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false; |
| 407 | |
| 408 | ctx->mGPUHintInfo.mEGLDisplay = NULL; |
| 409 | ctx->mGPUHintInfo.mEGLContext = NULL; |
Ramkumar Radhakrishnan | 3efce48 | 2014-05-28 15:40:17 -0700 | [diff] [blame] | 410 | ctx->mGPUHintInfo.mCompositionState = COMPOSITION_STATE_MDP; |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 411 | ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0; |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 412 | #endif |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 413 | // Read the system property to determine if windowboxing feature is enabled. |
| 414 | ctx->mWindowboxFeature = false; |
| 415 | if(property_get("sys.hwc.windowbox_feature", value, "false") |
| 416 | && !strcmp(value, "true")) { |
| 417 | ctx->mWindowboxFeature = true; |
| 418 | } |
| 419 | |
Raj Kamal | 0d53fc6 | 2014-11-25 17:36:36 +0530 | [diff] [blame] | 420 | ctx->mUseMetaDataRefreshRate = true; |
| 421 | if(property_get("persist.metadata_dynfps.disable", value, "false") |
| 422 | && !strcmp(value, "true")) { |
| 423 | ctx->mUseMetaDataRefreshRate = false; |
| 424 | } |
| 425 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 426 | memset(&(ctx->mPtorInfo), 0, sizeof(ctx->mPtorInfo)); |
Arun Kumar K.R | 2225eaa | 2014-12-02 15:52:41 -0800 | [diff] [blame] | 427 | ctx->mHPDEnabled = false; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 428 | ALOGI("Initializing Qualcomm Hardware Composer"); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 429 | ALOGI("MDP version: %d", ctx->mMDP.version); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void closeContext(hwc_context_t *ctx) |
| 433 | { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 434 | if(ctx->mOverlay) { |
| 435 | delete ctx->mOverlay; |
| 436 | ctx->mOverlay = NULL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 437 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 438 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 439 | if(ctx->mRotMgr) { |
| 440 | delete ctx->mRotMgr; |
| 441 | ctx->mRotMgr = NULL; |
| 442 | } |
| 443 | |
Amara Venkata Mastan Manoj Kumar | 7fb1327 | 2013-07-01 13:59:34 -0700 | [diff] [blame] | 444 | for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 445 | if(ctx->mCopyBit[i]) { |
| 446 | delete ctx->mCopyBit[i]; |
| 447 | ctx->mCopyBit[i] = NULL; |
| 448 | } |
| 449 | } |
| 450 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 451 | if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 452 | close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd); |
| 453 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 454 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 455 | |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 456 | if(ctx->mHDMIDisplay) { |
| 457 | delete ctx->mHDMIDisplay; |
| 458 | ctx->mHDMIDisplay = NULL; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 459 | } |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 460 | |
Amara Venkata Mastan Manoj Kumar | 7fb1327 | 2013-07-01 13:59:34 -0700 | [diff] [blame] | 461 | for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 462 | destroyCompositionResources(ctx, i); |
| 463 | |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 464 | if(ctx->mHwcDebug[i]) { |
| 465 | delete ctx->mHwcDebug[i]; |
| 466 | ctx->mHwcDebug[i] = NULL; |
| 467 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 468 | if(ctx->mLayerRotMap[i]) { |
| 469 | delete ctx->mLayerRotMap[i]; |
| 470 | ctx->mLayerRotMap[i] = NULL; |
| 471 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 472 | } |
Ramkumar Radhakrishnan | 8bb48d3 | 2013-12-30 23:11:27 -0800 | [diff] [blame] | 473 | if(ctx->mHWCVirtual) { |
| 474 | delete ctx->mHWCVirtual; |
| 475 | ctx->mHWCVirtual = NULL; |
| 476 | } |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 477 | if(ctx->mAD) { |
| 478 | delete ctx->mAD; |
| 479 | ctx->mAD = NULL; |
| 480 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 481 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 482 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 485 | //Helper to roundoff the refreshrates |
Raj Kamal | 0d53fc6 | 2014-11-25 17:36:36 +0530 | [diff] [blame] | 486 | uint32_t roundOff(uint32_t refreshRate) { |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 487 | int count = (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0])); |
| 488 | uint32_t rate = refreshRate; |
| 489 | for(int i=0; i< count; i++) { |
| 490 | if(abs(stdRefreshRates[i] - refreshRate) < 2) { |
| 491 | // Most likely used for video, the fps can fluctuate |
| 492 | // Ex: b/w 29 and 30 for 30 fps clip |
| 493 | rate = stdRefreshRates[i]; |
| 494 | break; |
| 495 | } |
| 496 | } |
| 497 | return rate; |
| 498 | } |
| 499 | |
| 500 | //Helper func to set the dyn fps |
| 501 | void setRefreshRate(hwc_context_t* ctx, int dpy, uint32_t refreshRate) { |
| 502 | //Update only if different |
| 503 | if(!ctx || refreshRate == ctx->dpyAttr[dpy].dynRefreshRate) |
| 504 | return; |
| 505 | const int fbNum = Overlay::getFbForDpy(dpy); |
| 506 | char sysfsPath[qdutils::MAX_SYSFS_FILE_PATH]; |
| 507 | snprintf (sysfsPath, sizeof(sysfsPath), |
Arun Kumar K.R | ee4e239 | 2015-01-12 18:08:34 -0800 | [diff] [blame] | 508 | "/sys/devices/virtual/graphics/fb%d/dynamic_fps", fbNum); |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 509 | |
| 510 | int fd = open(sysfsPath, O_WRONLY); |
| 511 | if(fd >= 0) { |
| 512 | char str[64]; |
| 513 | snprintf(str, sizeof(str), "%d", refreshRate); |
| 514 | ssize_t ret = write(fd, str, strlen(str)); |
| 515 | if(ret < 0) { |
| 516 | ALOGE("%s: Failed to write %d with error %s", |
| 517 | __FUNCTION__, refreshRate, strerror(errno)); |
| 518 | } else { |
| 519 | ctx->dpyAttr[dpy].dynRefreshRate = refreshRate; |
| 520 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: Wrote %d to dynamic_fps", |
| 521 | __FUNCTION__, refreshRate); |
| 522 | } |
| 523 | close(fd); |
| 524 | } else { |
| 525 | ALOGE("%s: Failed to open %s with error %s", __FUNCTION__, sysfsPath, |
| 526 | strerror(errno)); |
| 527 | } |
| 528 | } |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 529 | |
| 530 | void dumpsys_log(android::String8& buf, const char* fmt, ...) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 531 | { |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 532 | va_list varargs; |
| 533 | va_start(varargs, fmt); |
| 534 | buf.appendFormatV(fmt, varargs); |
| 535 | va_end(varargs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 538 | int getExtOrientation(hwc_context_t* ctx) { |
| 539 | int extOrient = ctx->mExtOrientation; |
| 540 | if(ctx->mBufferMirrorMode) |
| 541 | extOrient = getMirrorModeOrientation(ctx); |
| 542 | return extOrient; |
| 543 | } |
| 544 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 545 | /* Calculates the destination position based on the action safe rectangle */ |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 546 | void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) { |
| 547 | // Position |
| 548 | int x = rect.left, y = rect.top; |
| 549 | int w = rect.right - rect.left; |
| 550 | int h = rect.bottom - rect.top; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 551 | |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 552 | if(!ctx->dpyAttr[dpy].mActionSafePresent) |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 553 | return; |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 554 | // Read action safe properties |
| 555 | int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio; |
| 556 | int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio; |
Arun Kumar K.R | 82f1d28 | 2013-05-17 15:37:31 -0700 | [diff] [blame] | 557 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 558 | float wRatio = 1.0; |
| 559 | float hRatio = 1.0; |
| 560 | float xRatio = 1.0; |
| 561 | float yRatio = 1.0; |
| 562 | |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 563 | uint32_t fbWidth = ctx->dpyAttr[dpy].xres; |
| 564 | uint32_t fbHeight = ctx->dpyAttr[dpy].yres; |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 565 | if(ctx->dpyAttr[dpy].mMDPScalingMode) { |
| 566 | // if MDP scaling mode is enabled for external, need to query |
Arun Kumar KR | 7b7f401 | 2013-10-29 11:53:11 -0700 | [diff] [blame] | 567 | // the actual width and height, as that is the physical w & h |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 568 | ctx->mHDMIDisplay->getAttributes(fbWidth, fbHeight); |
Arun Kumar KR | 7b7f401 | 2013-10-29 11:53:11 -0700 | [diff] [blame] | 569 | } |
| 570 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 571 | |
Arun Kumar K.R | 82f1d28 | 2013-05-17 15:37:31 -0700 | [diff] [blame] | 572 | // Since external is rotated 90, need to swap width/height |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 573 | int extOrient = getExtOrientation(ctx); |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 574 | |
| 575 | if(extOrient & HWC_TRANSFORM_ROT_90) |
Arun Kumar K.R | 82f1d28 | 2013-05-17 15:37:31 -0700 | [diff] [blame] | 576 | swap(fbWidth, fbHeight); |
| 577 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 578 | float asX = 0; |
| 579 | float asY = 0; |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 580 | float asW = (float)fbWidth; |
| 581 | float asH = (float)fbHeight; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 582 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 583 | // based on the action safe ratio, get the Action safe rectangle |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 584 | asW = ((float)fbWidth * (1.0f - (float)asWidthRatio / 100.0f)); |
| 585 | asH = ((float)fbHeight * (1.0f - (float)asHeightRatio / 100.0f)); |
| 586 | asX = ((float)fbWidth - asW) / 2; |
| 587 | asY = ((float)fbHeight - asH) / 2; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 588 | |
| 589 | // calculate the position ratio |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 590 | xRatio = (float)x/(float)fbWidth; |
| 591 | yRatio = (float)y/(float)fbHeight; |
| 592 | wRatio = (float)w/(float)fbWidth; |
| 593 | hRatio = (float)h/(float)fbHeight; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 594 | |
| 595 | //Calculate the position... |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 596 | x = int((xRatio * asW) + asX); |
| 597 | y = int((yRatio * asH) + asY); |
| 598 | w = int(wRatio * asW); |
| 599 | h = int(hRatio * asH); |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 600 | |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 601 | // Convert it back to hwc_rect_t |
| 602 | rect.left = x; |
| 603 | rect.top = y; |
| 604 | rect.right = w + rect.left; |
| 605 | rect.bottom = h + rect.top; |
| 606 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 607 | return; |
| 608 | } |
| 609 | |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 610 | // This function gets the destination position for Seconday display |
| 611 | // based on the position and aspect ratio with orientation |
| 612 | void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation, |
| 613 | hwc_rect_t& inRect, hwc_rect_t& outRect) { |
| 614 | // Physical display resolution |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 615 | float fbWidth = (float)ctx->dpyAttr[dpy].xres; |
| 616 | float fbHeight = (float)ctx->dpyAttr[dpy].yres; |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 617 | //display position(x,y,w,h) in correct aspectratio after rotation |
| 618 | int xPos = 0; |
| 619 | int yPos = 0; |
| 620 | float width = fbWidth; |
| 621 | float height = fbHeight; |
| 622 | // Width/Height used for calculation, after rotation |
| 623 | float actualWidth = fbWidth; |
| 624 | float actualHeight = fbHeight; |
| 625 | |
| 626 | float wRatio = 1.0; |
| 627 | float hRatio = 1.0; |
| 628 | float xRatio = 1.0; |
| 629 | float yRatio = 1.0; |
| 630 | hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight}; |
| 631 | |
| 632 | Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left, |
| 633 | inRect.bottom - inRect.top); |
| 634 | Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left, |
| 635 | outRect.bottom - outRect.top); |
| 636 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 637 | Whf whf((uint32_t)fbWidth, (uint32_t)fbHeight, 0); |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 638 | eTransform extorient = static_cast<eTransform>(extOrientation); |
| 639 | // To calculate the destination co-ordinates in the new orientation |
| 640 | preRotateSource(extorient, whf, inPos); |
| 641 | |
| 642 | if(extOrientation & HAL_TRANSFORM_ROT_90) { |
| 643 | // Swap width/height for input position |
| 644 | swapWidthHeight(actualWidth, actualHeight); |
Tatenda Chipeperekwa | ce8d5c4 | 2014-08-13 10:53:49 -0700 | [diff] [blame] | 645 | qdutils::getAspectRatioPosition((int)fbWidth, (int)fbHeight, |
| 646 | (int)actualWidth, (int)actualHeight, rect); |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 647 | xPos = rect.left; |
| 648 | yPos = rect.top; |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 649 | width = float(rect.right - rect.left); |
| 650 | height = float(rect.bottom - rect.top); |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 651 | } |
Shalaj Jain | a70b435 | 2014-06-15 13:47:47 -0700 | [diff] [blame] | 652 | xRatio = (float)((float)inPos.x/actualWidth); |
| 653 | yRatio = (float)((float)inPos.y/actualHeight); |
| 654 | wRatio = (float)((float)inPos.w/actualWidth); |
| 655 | hRatio = (float)((float)inPos.h/actualHeight); |
Ramkumar Radhakrishnan | debfc5a | 2013-12-04 15:15:42 -0800 | [diff] [blame] | 656 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 657 | //Calculate the pos9ition... |
| 658 | outPos.x = uint32_t((xRatio * width) + (float)xPos); |
| 659 | outPos.y = uint32_t((yRatio * height) + (float)yPos); |
| 660 | outPos.w = uint32_t(wRatio * width); |
| 661 | outPos.h = uint32_t(hRatio * height); |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 662 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d," |
| 663 | "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y, |
| 664 | outPos.w, outPos.h); |
| 665 | |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 666 | // For sidesync, the dest fb will be in portrait orientation, and the crop |
| 667 | // will be updated to avoid the black side bands, and it will be upscaled |
| 668 | // to fit the dest RB, so recalculate |
| 669 | // the position based on the new width and height |
| 670 | if ((extOrientation & HWC_TRANSFORM_ROT_90) && |
| 671 | isOrientationPortrait(ctx)) { |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 672 | hwc_rect_t r = {0, 0, 0, 0}; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 673 | //Calculate the position |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 674 | xRatio = (float)(outPos.x - xPos)/width; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 675 | // GetaspectRatio -- tricky to get the correct aspect ratio |
| 676 | // But we need to do this. |
Tatenda Chipeperekwa | ce8d5c4 | 2014-08-13 10:53:49 -0700 | [diff] [blame] | 677 | qdutils::getAspectRatioPosition((int)width, (int)height, |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 678 | (int)width,(int)height, r); |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 679 | xPos = r.left; |
| 680 | yPos = r.top; |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 681 | float tempHeight = float(r.bottom - r.top); |
| 682 | yRatio = (float)yPos/height; |
| 683 | wRatio = (float)outPos.w/width; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 684 | hRatio = tempHeight/height; |
| 685 | |
| 686 | //Map the coordinates back to Framebuffer domain |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 687 | outPos.x = uint32_t(xRatio * fbWidth); |
| 688 | outPos.y = uint32_t(yRatio * fbHeight); |
| 689 | outPos.w = uint32_t(wRatio * fbWidth); |
| 690 | outPos.h = uint32_t(hRatio * fbHeight); |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 691 | |
| 692 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in" |
| 693 | "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__, |
| 694 | outPos.x, outPos.y, |
| 695 | outPos.w, outPos.h); |
| 696 | } |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 697 | if(ctx->dpyAttr[dpy].mMDPScalingMode) { |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 698 | uint32_t extW = 0, extH = 0; |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 699 | if(dpy == HWC_DISPLAY_EXTERNAL) { |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 700 | ctx->mHDMIDisplay->getAttributes(extW, extH); |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 701 | } else if(dpy == HWC_DISPLAY_VIRTUAL) { |
| 702 | extW = ctx->mHWCVirtual->getScalingWidth(); |
| 703 | extH = ctx->mHWCVirtual->getScalingHeight(); |
| 704 | } |
| 705 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d", |
| 706 | __FUNCTION__, extW, extH); |
| 707 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 708 | fbWidth = (float)ctx->dpyAttr[dpy].xres; |
| 709 | fbHeight = (float)ctx->dpyAttr[dpy].yres; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 710 | //Calculate the position... |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 711 | xRatio = (float)outPos.x/fbWidth; |
| 712 | yRatio = (float)outPos.y/fbHeight; |
| 713 | wRatio = (float)outPos.w/fbWidth; |
| 714 | hRatio = (float)outPos.h/fbHeight; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 715 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 716 | outPos.x = uint32_t(xRatio * (float)extW); |
| 717 | outPos.y = uint32_t(yRatio * (float)extH); |
| 718 | outPos.w = uint32_t(wRatio * (float)extW); |
| 719 | outPos.h = uint32_t(hRatio * (float)extH); |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 720 | } |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 721 | // Convert Dim to hwc_rect_t |
| 722 | outRect.left = outPos.x; |
| 723 | outRect.top = outPos.y; |
| 724 | outRect.right = outPos.x + outPos.w; |
| 725 | outRect.bottom = outPos.y + outPos.h; |
| 726 | |
| 727 | return; |
| 728 | } |
| 729 | |
| 730 | bool isPrimaryPortrait(hwc_context_t *ctx) { |
| 731 | int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres; |
| 732 | int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres; |
| 733 | if(fbWidth < fbHeight) { |
| 734 | return true; |
| 735 | } |
| 736 | return false; |
| 737 | } |
| 738 | |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 739 | bool isOrientationPortrait(hwc_context_t *ctx) { |
| 740 | if(isPrimaryPortrait(ctx)) { |
| 741 | return !(ctx->deviceOrientation & 0x1); |
| 742 | } |
| 743 | return (ctx->deviceOrientation & 0x1); |
| 744 | } |
| 745 | |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 746 | void calcExtDisplayPosition(hwc_context_t *ctx, |
| 747 | private_handle_t *hnd, |
| 748 | int dpy, |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 749 | hwc_rect_t& sourceCrop, |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 750 | hwc_rect_t& displayFrame, |
| 751 | int& transform, |
| 752 | ovutils::eTransform& orient) { |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 753 | // Swap width and height when there is a 90deg transform |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 754 | int extOrient = getExtOrientation(ctx); |
Raj Kamal | 068f457 | 2014-04-14 16:14:06 +0530 | [diff] [blame] | 755 | if(dpy && ctx->mOverlay->isUIScalingOnExternalSupported()) { |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 756 | if(!isYuvBuffer(hnd)) { |
| 757 | if(extOrient & HWC_TRANSFORM_ROT_90) { |
| 758 | int dstWidth = ctx->dpyAttr[dpy].xres; |
| 759 | int dstHeight = ctx->dpyAttr[dpy].yres;; |
| 760 | int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres; |
| 761 | int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres; |
| 762 | if(!isPrimaryPortrait(ctx)) { |
| 763 | swap(srcWidth, srcHeight); |
| 764 | } // Get Aspect Ratio for external |
Tatenda Chipeperekwa | ce8d5c4 | 2014-08-13 10:53:49 -0700 | [diff] [blame] | 765 | qdutils::getAspectRatioPosition(dstWidth, dstHeight, srcWidth, |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 766 | srcHeight, displayFrame); |
| 767 | // Crop - this is needed, because for sidesync, the dest fb will |
| 768 | // be in portrait orientation, so update the crop to not show the |
| 769 | // black side bands. |
| 770 | if (isOrientationPortrait(ctx)) { |
| 771 | sourceCrop = displayFrame; |
| 772 | displayFrame.left = 0; |
| 773 | displayFrame.top = 0; |
| 774 | displayFrame.right = dstWidth; |
| 775 | displayFrame.bottom = dstHeight; |
| 776 | } |
| 777 | } |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 778 | if(ctx->dpyAttr[dpy].mMDPScalingMode) { |
Tatenda Chipeperekwa | 03d5df2 | 2014-09-16 18:09:18 -0700 | [diff] [blame] | 779 | uint32_t extW = 0, extH = 0; |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 780 | // if MDP scaling mode is enabled, map the co-ordinates to new |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 781 | // domain(downscaled) |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 782 | float fbWidth = (float)ctx->dpyAttr[dpy].xres; |
| 783 | float fbHeight = (float)ctx->dpyAttr[dpy].yres; |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 784 | // query MDP configured attributes |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 785 | if(dpy == HWC_DISPLAY_EXTERNAL) { |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 786 | ctx->mHDMIDisplay->getAttributes(extW, extH); |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 787 | } else if(dpy == HWC_DISPLAY_VIRTUAL) { |
| 788 | extW = ctx->mHWCVirtual->getScalingWidth(); |
| 789 | extH = ctx->mHWCVirtual->getScalingHeight(); |
| 790 | } |
| 791 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: Scaling mode extW=%d extH=%d", |
| 792 | __FUNCTION__, extW, extH); |
| 793 | |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 794 | //Calculate the ratio... |
| 795 | float wRatio = ((float)extW)/fbWidth; |
| 796 | float hRatio = ((float)extH)/fbHeight; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 797 | |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 798 | //convert Dim to hwc_rect_t |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 799 | displayFrame.left = int(wRatio*(float)displayFrame.left); |
| 800 | displayFrame.top = int(hRatio*(float)displayFrame.top); |
| 801 | displayFrame.right = int(wRatio*(float)displayFrame.right); |
| 802 | displayFrame.bottom = int(hRatio*(float)displayFrame.bottom); |
Ramkumar Radhakrishnan | a5c7287 | 2014-08-28 19:04:18 -0700 | [diff] [blame] | 803 | ALOGD_IF(DEBUG_MDPDOWNSCALE, "Calculated external display frame" |
| 804 | " for MDPDownscale feature [%d %d %d %d]", |
| 805 | displayFrame.left, displayFrame.top, |
| 806 | displayFrame.right, displayFrame.bottom); |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 807 | } |
| 808 | }else { |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 809 | if(extOrient || ctx->dpyAttr[dpy].mMDPScalingMode) { |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 810 | getAspectRatioPosition(ctx, dpy, extOrient, |
| 811 | displayFrame, displayFrame); |
| 812 | } |
| 813 | } |
| 814 | // If there is a external orientation set, use that |
| 815 | if(extOrient) { |
| 816 | transform = extOrient; |
| 817 | orient = static_cast<ovutils::eTransform >(extOrient); |
| 818 | } |
| 819 | // Calculate the actionsafe dimensions for External(dpy = 1 or 2) |
| 820 | getActionSafePosition(ctx, dpy, displayFrame); |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 821 | } |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 822 | } |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 823 | |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 824 | /* Returns the orientation which needs to be set on External for |
| 825 | * SideSync/Buffer Mirrormode |
| 826 | */ |
| 827 | int getMirrorModeOrientation(hwc_context_t *ctx) { |
| 828 | int extOrientation = 0; |
| 829 | int deviceOrientation = ctx->deviceOrientation; |
| 830 | if(!isPrimaryPortrait(ctx)) |
| 831 | deviceOrientation = (deviceOrientation + 1) % 4; |
| 832 | if (deviceOrientation == 0) |
| 833 | extOrientation = HWC_TRANSFORM_ROT_270; |
| 834 | else if (deviceOrientation == 1)//90 |
| 835 | extOrientation = 0; |
| 836 | else if (deviceOrientation == 2)//180 |
| 837 | extOrientation = HWC_TRANSFORM_ROT_90; |
| 838 | else if (deviceOrientation == 3)//270 |
| 839 | extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H; |
| 840 | |
| 841 | return extOrientation; |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 842 | } |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 843 | |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 844 | /* Get External State names */ |
| 845 | const char* getExternalDisplayState(uint32_t external_state) { |
| 846 | static const char* externalStates[EXTERNAL_MAXSTATES] = {0}; |
| 847 | externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE); |
| 848 | externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE); |
| 849 | externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE); |
| 850 | externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME); |
| 851 | |
| 852 | if(external_state >= EXTERNAL_MAXSTATES) { |
| 853 | return "EXTERNAL_INVALID"; |
| 854 | } |
| 855 | |
| 856 | return externalStates[external_state]; |
| 857 | } |
| 858 | |
Prabhanjan Kandula | 21918db | 2013-11-26 15:51:58 +0530 | [diff] [blame] | 859 | bool isDownscaleRequired(hwc_layer_1_t const* layer) { |
| 860 | hwc_rect_t displayFrame = layer->displayFrame; |
| 861 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
| 862 | int dst_w, dst_h, src_w, src_h; |
| 863 | dst_w = displayFrame.right - displayFrame.left; |
| 864 | dst_h = displayFrame.bottom - displayFrame.top; |
| 865 | src_w = sourceCrop.right - sourceCrop.left; |
| 866 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 867 | |
| 868 | if(((src_w > dst_w) || (src_h > dst_h))) |
| 869 | return true; |
| 870 | |
| 871 | return false; |
| 872 | } |
| 873 | bool needsScaling(hwc_layer_1_t const* layer) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 874 | int dst_w, dst_h, src_w, src_h; |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 875 | hwc_rect_t displayFrame = layer->displayFrame; |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 876 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 877 | |
| 878 | dst_w = displayFrame.right - displayFrame.left; |
| 879 | dst_h = displayFrame.bottom - displayFrame.top; |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 880 | src_w = sourceCrop.right - sourceCrop.left; |
| 881 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 882 | |
Jeykumar Sankaran | 6a33952 | 2014-11-04 16:14:43 -0800 | [diff] [blame] | 883 | if(layer->transform & HWC_TRANSFORM_ROT_90) |
| 884 | swap(src_w, src_h); |
| 885 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 886 | if(((src_w != dst_w) || (src_h != dst_h))) |
| 887 | return true; |
| 888 | |
| 889 | return false; |
| 890 | } |
| 891 | |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 892 | // Checks if layer needs scaling with split |
| 893 | bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer, |
| 894 | const int& dpy) { |
| 895 | |
| 896 | int src_width_l, src_height_l; |
| 897 | int src_width_r, src_height_r; |
| 898 | int dst_width_l, dst_height_l; |
| 899 | int dst_width_r, dst_height_r; |
| 900 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 901 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 902 | hwc_rect_t cropL, dstL, cropR, dstR; |
| 903 | const int lSplit = getLeftSplit(ctx, dpy); |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 904 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 905 | hwc_rect_t displayFrame = layer->displayFrame; |
| 906 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 907 | |
| 908 | cropL = sourceCrop; |
| 909 | dstL = displayFrame; |
| 910 | hwc_rect_t scissorL = { 0, 0, lSplit, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 911 | scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL); |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 912 | qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0); |
| 913 | |
| 914 | cropR = sourceCrop; |
| 915 | dstR = displayFrame; |
| 916 | hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 917 | scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR); |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 918 | qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0); |
| 919 | |
| 920 | // Sanitize Crop to stitch |
| 921 | sanitizeSourceCrop(cropL, cropR, hnd); |
| 922 | |
| 923 | // Calculate the left dst |
| 924 | dst_width_l = dstL.right - dstL.left; |
| 925 | dst_height_l = dstL.bottom - dstL.top; |
| 926 | src_width_l = cropL.right - cropL.left; |
| 927 | src_height_l = cropL.bottom - cropL.top; |
| 928 | |
| 929 | // check if there is any scaling on the left |
| 930 | if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l))) |
| 931 | return true; |
| 932 | |
| 933 | // Calculate the right dst |
| 934 | dst_width_r = dstR.right - dstR.left; |
| 935 | dst_height_r = dstR.bottom - dstR.top; |
| 936 | src_width_r = cropR.right - cropR.left; |
| 937 | src_height_r = cropR.bottom - cropR.top; |
| 938 | |
| 939 | // check if there is any scaling on the right |
| 940 | if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r))) |
| 941 | return true; |
| 942 | |
| 943 | return false; |
| 944 | } |
| 945 | |
Prabhanjan Kandula | 21918db | 2013-11-26 15:51:58 +0530 | [diff] [blame] | 946 | bool isAlphaScaled(hwc_layer_1_t const* layer) { |
| 947 | if(needsScaling(layer) && isAlphaPresent(layer)) { |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 948 | return true; |
| 949 | } |
| 950 | return false; |
| 951 | } |
| 952 | |
| 953 | bool isAlphaPresent(hwc_layer_1_t const* layer) { |
| 954 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | 7a4287c | 2013-03-26 18:11:41 -0400 | [diff] [blame] | 955 | if(hnd) { |
| 956 | int format = hnd->format; |
| 957 | switch(format) { |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 958 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 959 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 960 | // In any more formats with Alpha go here.. |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 961 | return true; |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 962 | default : return false; |
Naseer Ahmed | 7a4287c | 2013-03-26 18:11:41 -0400 | [diff] [blame] | 963 | } |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 964 | } |
| 965 | return false; |
| 966 | } |
| 967 | |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 968 | static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform, |
| 969 | hwc_rect_t& crop, hwc_rect_t& dst) { |
| 970 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 971 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 972 | if(dst.left < 0 || dst.top < 0 || |
| 973 | dst.right > hw_w || dst.bottom > hw_h) { |
| 974 | hwc_rect_t scissor = {0, 0, hw_w, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 975 | scissor = getIntersection(ctx->mViewFrame[dpy], scissor); |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 976 | qhwc::calculate_crop_rects(crop, dst, scissor, transform); |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 981 | const int& dpy) { |
| 982 | for(uint32_t i = 0; i < list->numHwLayers - 1; i++) { |
| 983 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
| 984 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Sushil Chauhan | fda00fc | 2014-03-20 11:08:41 -0700 | [diff] [blame] | 985 | int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 : |
| 986 | list->hwLayers[i].transform; |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 987 | trimLayer(ctx, dpy, |
Sushil Chauhan | fda00fc | 2014-03-20 11:08:41 -0700 | [diff] [blame] | 988 | transform, |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 989 | (hwc_rect_t&)crop, |
| 990 | (hwc_rect_t&)list->hwLayers[i].displayFrame); |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 991 | layer->sourceCropf.left = (float)crop.left; |
| 992 | layer->sourceCropf.right = (float)crop.right; |
| 993 | layer->sourceCropf.top = (float)crop.top; |
| 994 | layer->sourceCropf.bottom = (float)crop.bottom; |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 995 | } |
| 996 | } |
| 997 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 998 | void setListStats(hwc_context_t *ctx, |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 999 | hwc_display_contents_1_t *list, int dpy) { |
Saurabh Shah | d4e6585 | 2013-06-17 11:33:53 -0700 | [diff] [blame] | 1000 | const int prevYuvCount = ctx->listStats[dpy].yuvCount; |
| 1001 | memset(&ctx->listStats[dpy], 0, sizeof(ListStats)); |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1002 | ctx->listStats[dpy].numAppLayers = (int)list->numHwLayers - 1; |
| 1003 | ctx->listStats[dpy].fbLayerIndex = (int)list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 1004 | ctx->listStats[dpy].skipCount = 0; |
Sravan Kumar D.V.N | b5ed029 | 2013-03-15 08:51:16 +0530 | [diff] [blame] | 1005 | ctx->listStats[dpy].preMultipliedAlpha = false; |
Saurabh Shah | 8028e3b | 2013-10-15 12:27:59 -0700 | [diff] [blame] | 1006 | ctx->listStats[dpy].isSecurePresent = false; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 1007 | ctx->listStats[dpy].yuvCount = 0; |
Ping Li | 9404e2a | 2013-04-24 16:36:03 -0400 | [diff] [blame] | 1008 | char property[PROPERTY_VALUE_MAX]; |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1009 | ctx->listStats[dpy].isDisplayAnimating = false; |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 1010 | ctx->listStats[dpy].secureUI = false; |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1011 | ctx->listStats[dpy].yuv4k2kCount = 0; |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 1012 | ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy); |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 1013 | ctx->listStats[dpy].renderBufIndexforABC = -1; |
Ramkumar Radhakrishnan | 4ec775f | 2014-07-23 17:43:18 -0700 | [diff] [blame] | 1014 | ctx->listStats[dpy].secureRGBCount = 0; |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 1015 | ctx->listStats[dpy].refreshRateRequest = ctx->dpyAttr[dpy].refreshRate; |
| 1016 | uint32_t refreshRate = 0; |
| 1017 | qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance(); |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 1018 | int s3dFormat = HAL_NO_3D; |
| 1019 | int s3dLayerCount = 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1020 | |
Ramkumar Radhakrishnan | b33f490 | 2014-10-03 16:46:35 -0700 | [diff] [blame] | 1021 | ctx->listStats[dpy].mAIVVideoMode = false; |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 1022 | resetROI(ctx, dpy); |
| 1023 | |
Sushil Chauhan | f68d0df | 2014-04-09 09:15:37 -0700 | [diff] [blame] | 1024 | trimList(ctx, list, dpy); |
| 1025 | optimizeLayerRects(list); |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 1026 | for (size_t i = 0; i < (size_t)ctx->listStats[dpy].numAppLayers; i++) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 1027 | hwc_layer_1_t const* layer = &list->hwLayers[i]; |
| 1028 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1029 | |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 1030 | #ifdef QCOM_BSP |
Ramkumar Radhakrishnan | b33f490 | 2014-10-03 16:46:35 -0700 | [diff] [blame] | 1031 | // Window boxing feature is applicable obly for external display, So |
| 1032 | // enable mAIVVideoMode only for external display |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 1033 | if(ctx->mWindowboxFeature && dpy && isAIVVideoLayer(layer)) { |
Ramkumar Radhakrishnan | b33f490 | 2014-10-03 16:46:35 -0700 | [diff] [blame] | 1034 | ctx->listStats[dpy].mAIVVideoMode = true; |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 1035 | } |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 1036 | if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) { |
| 1037 | ctx->listStats[dpy].isDisplayAnimating = true; |
| 1038 | } |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 1039 | if(isSecureDisplayBuffer(hnd)) { |
| 1040 | ctx->listStats[dpy].secureUI = true; |
| 1041 | } |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 1042 | #endif |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 1043 | // continue if number of app layers exceeds MAX_NUM_APP_LAYERS |
| 1044 | if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 1045 | continue; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 1046 | |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 1047 | //reset yuv indices |
| 1048 | ctx->listStats[dpy].yuvIndices[i] = -1; |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1049 | ctx->listStats[dpy].yuv4k2kIndices[i] = -1; |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 1050 | |
Saurabh Shah | 8028e3b | 2013-10-15 12:27:59 -0700 | [diff] [blame] | 1051 | if (isSecureBuffer(hnd)) { |
| 1052 | ctx->listStats[dpy].isSecurePresent = true; |
Ramkumar Radhakrishnan | 4ec775f | 2014-07-23 17:43:18 -0700 | [diff] [blame] | 1053 | if(not isYuvBuffer(hnd)) { |
| 1054 | // cache secureRGB layer parameters like we cache for YUV layers |
| 1055 | int& secureRGBCount = ctx->listStats[dpy].secureRGBCount; |
| 1056 | ctx->listStats[dpy].secureRGBIndices[secureRGBCount] = (int)i; |
| 1057 | secureRGBCount++; |
| 1058 | } |
Saurabh Shah | 8028e3b | 2013-10-15 12:27:59 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 1061 | if (isSkipLayer(&list->hwLayers[i])) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 1062 | ctx->listStats[dpy].skipCount++; |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | if (UNLIKELY(isYuvBuffer(hnd))) { |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 1066 | int& yuvCount = ctx->listStats[dpy].yuvCount; |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1067 | ctx->listStats[dpy].yuvIndices[yuvCount] = (int)i; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 1068 | yuvCount++; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1069 | |
Raj Kamal | 389d6e3 | 2014-08-04 14:43:24 +0530 | [diff] [blame] | 1070 | if(UNLIKELY(isYUVSplitNeeded(hnd))){ |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1071 | int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount; |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1072 | ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = (int)i; |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1073 | yuv4k2kCount++; |
| 1074 | } |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 1075 | |
| 1076 | // Gets set if one YUV layer is 3D |
| 1077 | if (displaySupports3D(ctx,dpy)) { |
| 1078 | s3dFormat = get3DFormat(hnd); |
| 1079 | if(s3dFormat != HAL_NO_3D) |
| 1080 | s3dLayerCount++; |
| 1081 | } |
| 1082 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1083 | } |
Sravan Kumar D.V.N | b5ed029 | 2013-03-15 08:51:16 +0530 | [diff] [blame] | 1084 | if(layer->blending == HWC_BLENDING_PREMULT) |
| 1085 | ctx->listStats[dpy].preMultipliedAlpha = true; |
Jeykumar Sankaran | 7535aba | 2013-02-04 11:03:09 -0800 | [diff] [blame] | 1086 | |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 1087 | #ifdef DYNAMIC_FPS |
Raj Kamal | 0d53fc6 | 2014-11-25 17:36:36 +0530 | [diff] [blame] | 1088 | if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){ |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 1089 | //dyn fps: get refreshrate from metadata |
| 1090 | //Support multiple refresh rates if they are same |
| 1091 | //else set to default |
| 1092 | MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL; |
| 1093 | if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) { |
| 1094 | // Valid refreshRate in metadata and within the range |
| 1095 | uint32_t rate = roundOff(mdata->refreshrate); |
| 1096 | if((rate >= mdpHw.getMinFpsSupported() && |
| 1097 | rate <= mdpHw.getMaxFpsSupported())) { |
| 1098 | if (!refreshRate) { |
| 1099 | refreshRate = rate; |
| 1100 | } else if(refreshRate != rate) { |
| 1101 | // multiple refreshrate requests, set to default |
| 1102 | refreshRate = ctx->dpyAttr[dpy].refreshRate; |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | #endif |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1108 | } |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 1109 | |
| 1110 | //Set the TV's 3D mode based on format if it was not forced |
| 1111 | //Only one 3D YUV layer is supported on external |
| 1112 | //If there is more than one 3D YUV layer, the switch to 3D cannot occur. |
| 1113 | if( !ctx->dpyAttr[dpy].s3dModeForced && (s3dLayerCount <= 1)) { |
| 1114 | //XXX: Rapidly going in and out of 3D mode in some cases such |
| 1115 | // as rotation might cause flickers. The OEMs are recommended to disable |
| 1116 | // rotation on HDMI globally or in the app that plays 3D video |
| 1117 | setup3DMode(ctx, dpy, convertS3DFormatToMode(s3dFormat)); |
| 1118 | } |
| 1119 | |
Ping Li | 9404e2a | 2013-04-24 16:36:03 -0400 | [diff] [blame] | 1120 | if(ctx->listStats[dpy].yuvCount > 0) { |
| 1121 | if (property_get("hw.cabl.yuv", property, NULL) > 0) { |
| 1122 | if (atoi(property) != 1) { |
| 1123 | property_set("hw.cabl.yuv", "1"); |
| 1124 | } |
| 1125 | } |
| 1126 | } else { |
| 1127 | if (property_get("hw.cabl.yuv", property, NULL) > 0) { |
| 1128 | if (atoi(property) != 0) { |
| 1129 | property_set("hw.cabl.yuv", "0"); |
| 1130 | } |
| 1131 | } |
| 1132 | } |
Saurabh Shah | d4e6585 | 2013-06-17 11:33:53 -0700 | [diff] [blame] | 1133 | |
| 1134 | //The marking of video begin/end is useful on some targets where we need |
| 1135 | //to have a padding round to be able to shift pipes across mixers. |
| 1136 | if(prevYuvCount != ctx->listStats[dpy].yuvCount) { |
| 1137 | ctx->mVideoTransFlag = true; |
| 1138 | } |
Raj Kamal | 9ed3d6b | 2014-02-07 16:15:17 +0530 | [diff] [blame] | 1139 | |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 1140 | if(dpy == HWC_DISPLAY_PRIMARY) { |
| 1141 | ctx->mAD->markDoable(ctx, list); |
Arun Kumar K.R | a727a88 | 2014-08-20 17:14:26 -0700 | [diff] [blame] | 1142 | //Store the requested fresh rate |
| 1143 | ctx->listStats[dpy].refreshRateRequest = refreshRate ? |
| 1144 | refreshRate : ctx->dpyAttr[dpy].refreshRate; |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 1145 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 1148 | |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 1149 | static void calc_cut(double& leftCutRatio, double& topCutRatio, |
| 1150 | double& rightCutRatio, double& bottomCutRatio, int orient) { |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1151 | if(orient & HAL_TRANSFORM_FLIP_H) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 1152 | swap(leftCutRatio, rightCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1153 | } |
| 1154 | if(orient & HAL_TRANSFORM_FLIP_V) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 1155 | swap(topCutRatio, bottomCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1156 | } |
| 1157 | if(orient & HAL_TRANSFORM_ROT_90) { |
| 1158 | //Anti clock swapping |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 1159 | double tmpCutRatio = leftCutRatio; |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 1160 | leftCutRatio = topCutRatio; |
| 1161 | topCutRatio = rightCutRatio; |
| 1162 | rightCutRatio = bottomCutRatio; |
| 1163 | bottomCutRatio = tmpCutRatio; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1164 | } |
| 1165 | } |
| 1166 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1167 | bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1168 | if((ctx->mMDP.version < qdutils::MDSS_V5) && |
| 1169 | (ctx->mMDP.version > qdutils::MDP_V3_0) && |
| 1170 | ctx->mSecuring) { |
| 1171 | return true; |
| 1172 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1173 | if (isSecureModePolicy(ctx->mMDP.version)) { |
| 1174 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1175 | if(ctx->mSecureMode) { |
| 1176 | if (! isSecureBuffer(hnd)) { |
| 1177 | ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...", |
| 1178 | __FUNCTION__); |
| 1179 | return true; |
| 1180 | } |
| 1181 | } else { |
| 1182 | if (isSecureBuffer(hnd)) { |
| 1183 | ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...", |
| 1184 | __FUNCTION__); |
| 1185 | return true; |
| 1186 | } |
| 1187 | } |
| 1188 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1189 | return false; |
| 1190 | } |
| 1191 | |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 1192 | bool isSecureModePolicy(int mdpVersion) { |
| 1193 | if (mdpVersion < qdutils::MDSS_V5) |
| 1194 | return true; |
| 1195 | else |
| 1196 | return false; |
| 1197 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 1198 | |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 1199 | bool isRotatorSupportedFormat(private_handle_t *hnd) { |
| 1200 | // Following rotator src formats are supported by mdp driver |
| 1201 | // TODO: Add more formats in future, if mdp driver adds support |
Ramkumar Radhakrishnan | 629cbf5 | 2014-10-14 19:36:33 -0700 | [diff] [blame] | 1202 | if(hnd != NULL) { |
| 1203 | switch(hnd->format) { |
| 1204 | case HAL_PIXEL_FORMAT_RGBA_8888: |
Ramkumar Radhakrishnan | b8eb16d | 2014-10-09 13:54:07 -0700 | [diff] [blame] | 1205 | case HAL_PIXEL_FORMAT_RGBA_5551: |
| 1206 | case HAL_PIXEL_FORMAT_RGBA_4444: |
Ramkumar Radhakrishnan | 629cbf5 | 2014-10-14 19:36:33 -0700 | [diff] [blame] | 1207 | case HAL_PIXEL_FORMAT_RGB_565: |
| 1208 | case HAL_PIXEL_FORMAT_RGB_888: |
| 1209 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 1210 | return true; |
| 1211 | default: |
| 1212 | return false; |
| 1213 | } |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 1214 | } |
| 1215 | return false; |
| 1216 | } |
| 1217 | |
| 1218 | bool isRotationDoable(hwc_context_t *ctx, private_handle_t *hnd) { |
Ramkumar Radhakrishnan | 629cbf5 | 2014-10-14 19:36:33 -0700 | [diff] [blame] | 1219 | // Rotate layers, if it is not secure display buffer and not |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 1220 | // for the MDP versions below MDP5 |
Ramkumar Radhakrishnan | 629cbf5 | 2014-10-14 19:36:33 -0700 | [diff] [blame] | 1221 | if((!isSecureDisplayBuffer(hnd) && isRotatorSupportedFormat(hnd) && |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 1222 | !ctx->mMDP.version < qdutils::MDSS_V5) |
| 1223 | || isYuvBuffer(hnd)) { |
| 1224 | return true; |
| 1225 | } |
| 1226 | return false; |
| 1227 | } |
| 1228 | |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 1229 | // returns true if Action safe dimensions are set and target supports Actionsafe |
| 1230 | bool isActionSafePresent(hwc_context_t *ctx, int dpy) { |
| 1231 | // if external supports underscan, do nothing |
| 1232 | // it will be taken care in the driver |
Ramkumar Radhakrishnan | a61a0da | 2014-03-03 14:46:21 -0800 | [diff] [blame] | 1233 | // Disable Action safe for 8974 due to HW limitation for downscaling |
| 1234 | // layers with overlapped region |
| 1235 | // Disable Actionsafe for non HDMI displays. |
| 1236 | if(!(dpy == HWC_DISPLAY_EXTERNAL) || |
| 1237 | qdutils::MDPVersion::getInstance().is8x74v2() || |
Tatenda Chipeperekwa | af2c004 | 2014-09-17 12:55:01 -0700 | [diff] [blame] | 1238 | ctx->mHDMIDisplay->isCEUnderscanSupported()) { |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 1239 | return false; |
Ramkumar Radhakrishnan | a61a0da | 2014-03-03 14:46:21 -0800 | [diff] [blame] | 1240 | } |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 1241 | |
| 1242 | char value[PROPERTY_VALUE_MAX]; |
| 1243 | // Read action safe properties |
| 1244 | property_get("persist.sys.actionsafe.width", value, "0"); |
| 1245 | ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value); |
| 1246 | property_get("persist.sys.actionsafe.height", value, "0"); |
| 1247 | ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value); |
| 1248 | |
| 1249 | if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) { |
| 1250 | //No action safe ratio set, return |
| 1251 | return false; |
| 1252 | } |
| 1253 | return true; |
| 1254 | } |
| 1255 | |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 1256 | int getBlending(int blending) { |
| 1257 | switch(blending) { |
| 1258 | case HWC_BLENDING_NONE: |
| 1259 | return overlay::utils::OVERLAY_BLENDING_OPAQUE; |
| 1260 | case HWC_BLENDING_PREMULT: |
| 1261 | return overlay::utils::OVERLAY_BLENDING_PREMULT; |
| 1262 | case HWC_BLENDING_COVERAGE : |
| 1263 | default: |
| 1264 | return overlay::utils::OVERLAY_BLENDING_COVERAGE; |
| 1265 | } |
| 1266 | } |
| 1267 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1268 | //Crops source buffer against destination and FB boundaries |
| 1269 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1270 | const hwc_rect_t& scissor, int orient) { |
| 1271 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1272 | int& crop_l = crop.left; |
| 1273 | int& crop_t = crop.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1274 | int& crop_r = crop.right; |
| 1275 | int& crop_b = crop.bottom; |
| 1276 | int crop_w = crop.right - crop.left; |
| 1277 | int crop_h = crop.bottom - crop.top; |
| 1278 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1279 | int& dst_l = dst.left; |
| 1280 | int& dst_t = dst.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1281 | int& dst_r = dst.right; |
| 1282 | int& dst_b = dst.bottom; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1283 | int dst_w = abs(dst.right - dst.left); |
| 1284 | int dst_h = abs(dst.bottom - dst.top); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1285 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1286 | const int& sci_l = scissor.left; |
| 1287 | const int& sci_t = scissor.top; |
| 1288 | const int& sci_r = scissor.right; |
| 1289 | const int& sci_b = scissor.bottom; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1290 | |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 1291 | double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0, |
| 1292 | bottomCutRatio = 0.0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1293 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1294 | if(dst_l < sci_l) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 1295 | leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1296 | dst_l = sci_l; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1297 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1298 | |
| 1299 | if(dst_r > sci_r) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 1300 | rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1301 | dst_r = sci_r; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1302 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1303 | |
| 1304 | if(dst_t < sci_t) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 1305 | topCutRatio = (double)(sci_t - dst_t) / (double)dst_h; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1306 | dst_t = sci_t; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1307 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1308 | |
| 1309 | if(dst_b > sci_b) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 1310 | bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 1311 | dst_b = sci_b; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1312 | } |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 1313 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 1314 | calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient); |
Dileep Kumar Reddi | 39e79bf | 2014-03-06 11:56:10 +0530 | [diff] [blame] | 1315 | crop_l += (int)round((double)crop_w * leftCutRatio); |
| 1316 | crop_t += (int)round((double)crop_h * topCutRatio); |
| 1317 | crop_r -= (int)round((double)crop_w * rightCutRatio); |
| 1318 | crop_b -= (int)round((double)crop_h * bottomCutRatio); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1319 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1320 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 1321 | bool areLayersIntersecting(const hwc_layer_1_t* layer1, |
| 1322 | const hwc_layer_1_t* layer2) { |
| 1323 | hwc_rect_t irect = getIntersection(layer1->displayFrame, |
| 1324 | layer2->displayFrame); |
| 1325 | return isValidRect(irect); |
| 1326 | } |
| 1327 | |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 1328 | bool isSameRect(const hwc_rect& rect1, const hwc_rect& rect2) |
| 1329 | { |
| 1330 | return ((rect1.left == rect2.left) && (rect1.top == rect2.top) && |
| 1331 | (rect1.right == rect2.right) && (rect1.bottom == rect2.bottom)); |
| 1332 | } |
| 1333 | |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1334 | bool isValidRect(const hwc_rect& rect) |
| 1335 | { |
| 1336 | return ((rect.bottom > rect.top) && (rect.right > rect.left)) ; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1337 | } |
| 1338 | |
Ramakant Singh | 21cec72 | 2014-03-07 19:11:45 +0530 | [diff] [blame] | 1339 | bool operator ==(const hwc_rect_t& lhs, const hwc_rect_t& rhs) { |
| 1340 | if(lhs.left == rhs.left && lhs.top == rhs.top && |
| 1341 | lhs.right == rhs.right && lhs.bottom == rhs.bottom ) |
| 1342 | return true ; |
| 1343 | return false; |
| 1344 | } |
| 1345 | |
Jeykumar Sankaran | 71e597c | 2014-05-07 16:23:14 -0700 | [diff] [blame] | 1346 | hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off) |
| 1347 | { |
| 1348 | hwc_rect_t res; |
| 1349 | |
| 1350 | if(!isValidRect(rect)) |
| 1351 | return (hwc_rect_t){0, 0, 0, 0}; |
| 1352 | |
| 1353 | res.left = rect.left + x_off; |
| 1354 | res.top = rect.top + y_off; |
| 1355 | res.right = rect.right + x_off; |
| 1356 | res.bottom = rect.bottom + y_off; |
| 1357 | |
| 1358 | return res; |
| 1359 | } |
| 1360 | |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1361 | /* computes the intersection of two rects */ |
| 1362 | hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2) |
| 1363 | { |
| 1364 | hwc_rect_t res; |
| 1365 | |
| 1366 | if(!isValidRect(rect1) || !isValidRect(rect2)){ |
| 1367 | return (hwc_rect_t){0, 0, 0, 0}; |
| 1368 | } |
| 1369 | |
| 1370 | |
| 1371 | res.left = max(rect1.left, rect2.left); |
| 1372 | res.top = max(rect1.top, rect2.top); |
| 1373 | res.right = min(rect1.right, rect2.right); |
| 1374 | res.bottom = min(rect1.bottom, rect2.bottom); |
| 1375 | |
| 1376 | if(!isValidRect(res)) |
| 1377 | return (hwc_rect_t){0, 0, 0, 0}; |
| 1378 | |
| 1379 | return res; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1380 | } |
| 1381 | |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1382 | /* computes the union of two rects */ |
| 1383 | hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2) |
| 1384 | { |
| 1385 | hwc_rect_t res; |
| 1386 | |
| 1387 | if(!isValidRect(rect1)){ |
| 1388 | return rect2; |
| 1389 | } |
| 1390 | |
| 1391 | if(!isValidRect(rect2)){ |
| 1392 | return rect1; |
| 1393 | } |
| 1394 | |
| 1395 | res.left = min(rect1.left, rect2.left); |
| 1396 | res.top = min(rect1.top, rect2.top); |
| 1397 | res.right = max(rect1.right, rect2.right); |
| 1398 | res.bottom = max(rect1.bottom, rect2.bottom); |
| 1399 | |
| 1400 | return res; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1401 | } |
| 1402 | |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1403 | /* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results |
| 1404 | * a single rect */ |
| 1405 | hwc_rect_t deductRect(const hwc_rect_t& rect1, const hwc_rect_t& rect2) { |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1406 | |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1407 | hwc_rect_t res = rect1; |
| 1408 | |
| 1409 | if((rect1.left == rect2.left) && (rect1.right == rect2.right)) { |
| 1410 | if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom)) |
| 1411 | res.top = rect2.bottom; |
| 1412 | else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top)) |
| 1413 | res.bottom = rect2.top; |
| 1414 | } |
| 1415 | else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) { |
| 1416 | if((rect1.left == rect2.left) && (rect2.right <= rect1.right)) |
| 1417 | res.left = rect2.right; |
| 1418 | else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left)) |
| 1419 | res.right = rect2.left; |
| 1420 | } |
| 1421 | return res; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1422 | } |
| 1423 | |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 1424 | void optimizeLayerRects(const hwc_display_contents_1_t *list) { |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1425 | int i= (int)list->numHwLayers-2; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1426 | while(i > 0) { |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1427 | //see if there is no blending required. |
Arun Kumar K.R | 2aa44c6 | 2014-01-21 23:08:28 -0800 | [diff] [blame] | 1428 | //If it is opaque see if we can substract this region from below |
| 1429 | //layers. |
radhakrishna | 4efbdd6 | 2014-11-03 13:19:27 +0530 | [diff] [blame] | 1430 | if(list->hwLayers[i].blending == HWC_BLENDING_NONE && |
| 1431 | list->hwLayers[i].planeAlpha == 0xFF) { |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1432 | int j= i-1; |
| 1433 | hwc_rect_t& topframe = |
| 1434 | (hwc_rect_t&)list->hwLayers[i].displayFrame; |
| 1435 | while(j >= 0) { |
Prabhanjan Kandula | 21918db | 2013-11-26 15:51:58 +0530 | [diff] [blame] | 1436 | if(!needsScaling(&list->hwLayers[j])) { |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1437 | hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j]; |
| 1438 | hwc_rect_t& bottomframe = layer->displayFrame; |
Jeykumar Sankaran | 071468b | 2014-01-14 17:21:49 -0800 | [diff] [blame] | 1439 | hwc_rect_t bottomCrop = |
| 1440 | integerizeSourceCrop(layer->sourceCropf); |
Sushil Chauhan | fda00fc | 2014-03-20 11:08:41 -0700 | [diff] [blame] | 1441 | int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : |
| 1442 | layer->transform; |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1443 | |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1444 | hwc_rect_t irect = getIntersection(bottomframe, topframe); |
| 1445 | if(isValidRect(irect)) { |
Jeykumar Sankaran | 1b3da40 | 2013-12-04 16:22:34 -0800 | [diff] [blame] | 1446 | hwc_rect_t dest_rect; |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1447 | //if intersection is valid rect, deduct it |
Jeykumar Sankaran | 1b3da40 | 2013-12-04 16:22:34 -0800 | [diff] [blame] | 1448 | dest_rect = deductRect(bottomframe, irect); |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1449 | qhwc::calculate_crop_rects(bottomCrop, bottomframe, |
Jeykumar Sankaran | 1b3da40 | 2013-12-04 16:22:34 -0800 | [diff] [blame] | 1450 | dest_rect, transform); |
Jeykumar Sankaran | 071468b | 2014-01-14 17:21:49 -0800 | [diff] [blame] | 1451 | //Update layer sourceCropf |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1452 | layer->sourceCropf.left =(float)bottomCrop.left; |
| 1453 | layer->sourceCropf.top = (float)bottomCrop.top; |
| 1454 | layer->sourceCropf.right = (float)bottomCrop.right; |
| 1455 | layer->sourceCropf.bottom = (float)bottomCrop.bottom; |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 1456 | #ifdef QCOM_BSP |
| 1457 | //Update layer dirtyRect |
| 1458 | layer->dirtyRect = getIntersection(bottomCrop, |
| 1459 | layer->dirtyRect); |
| 1460 | #endif |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | j--; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1464 | } |
| 1465 | } |
| 1466 | i--; |
| 1467 | } |
| 1468 | } |
| 1469 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1470 | void getNonWormholeRegion(hwc_display_contents_1_t* list, |
| 1471 | hwc_rect_t& nwr) |
| 1472 | { |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1473 | size_t last = list->numHwLayers - 1; |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1474 | hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame; |
| 1475 | //Initiliaze nwr to first frame |
| 1476 | nwr.left = list->hwLayers[0].displayFrame.left; |
| 1477 | nwr.top = list->hwLayers[0].displayFrame.top; |
| 1478 | nwr.right = list->hwLayers[0].displayFrame.right; |
| 1479 | nwr.bottom = list->hwLayers[0].displayFrame.bottom; |
| 1480 | |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1481 | for (size_t i = 1; i < last; i++) { |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1482 | hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1483 | nwr = getUnion(nwr, displayFrame); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | //Intersect with the framebuffer |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1487 | nwr = getIntersection(nwr, fbDisplayFrame); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1488 | } |
| 1489 | |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1490 | void closeAcquireFds(hwc_display_contents_1_t* list) { |
Ramkumar Radhakrishnan | 8bb48d3 | 2013-12-30 23:11:27 -0800 | [diff] [blame] | 1491 | if(LIKELY(list)) { |
| 1492 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
| 1493 | //Close the acquireFenceFds |
| 1494 | //HWC_FRAMEBUFFER are -1 already by SF, rest we close. |
| 1495 | if(list->hwLayers[i].acquireFenceFd >= 0) { |
| 1496 | close(list->hwLayers[i].acquireFenceFd); |
| 1497 | list->hwLayers[i].acquireFenceFd = -1; |
| 1498 | } |
| 1499 | } |
| 1500 | //Writeback |
| 1501 | if(list->outbufAcquireFenceFd >= 0) { |
| 1502 | close(list->outbufAcquireFenceFd); |
| 1503 | list->outbufAcquireFenceFd = -1; |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1508 | int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy, |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1509 | int fd) { |
Naseer Ahmed | 099a693 | 2013-09-09 14:25:20 -0400 | [diff] [blame] | 1510 | ATRACE_CALL(); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1511 | int ret = 0; |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 1512 | int acquireFd[MAX_NUM_APP_LAYERS]; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1513 | int count = 0; |
| 1514 | int releaseFd = -1; |
Arun Kumar K.R | 5183518 | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1515 | int retireFd = -1; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1516 | int fbFd = -1; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1517 | bool swapzero = false; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1518 | |
| 1519 | struct mdp_buf_sync data; |
| 1520 | memset(&data, 0, sizeof(data)); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1521 | data.acq_fen_fd = acquireFd; |
| 1522 | data.rel_fen_fd = &releaseFd; |
Arun Kumar K.R | 5183518 | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1523 | data.retire_fen_fd = &retireFd; |
| 1524 | data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1525 | |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1526 | char property[PROPERTY_VALUE_MAX]; |
| 1527 | if(property_get("debug.egl.swapinterval", property, "1") > 0) { |
| 1528 | if(atoi(property) == 0) |
| 1529 | swapzero = true; |
| 1530 | } |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1531 | |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1532 | bool isExtAnimating = false; |
| 1533 | if(dpy) |
| 1534 | isExtAnimating = ctx->listStats[dpy].isDisplayAnimating; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1535 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1536 | //Send acquireFenceFds to rotator |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1537 | for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) { |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1538 | int rotFd = ctx->mRotMgr->getRotDevFd(); |
| 1539 | int rotReleaseFd = -1; |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1540 | overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i); |
| 1541 | hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i); |
| 1542 | if((currRot == NULL) || (currLayer == NULL)) { |
| 1543 | continue; |
| 1544 | } |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1545 | struct mdp_buf_sync rotData; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1546 | memset(&rotData, 0, sizeof(rotData)); |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1547 | rotData.acq_fen_fd = |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1548 | &currLayer->acquireFenceFd; |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1549 | rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1550 | rotData.session_id = currRot->getSessId(); |
Saurabh Shah | 25c04d3 | 2014-05-05 10:16:02 -0700 | [diff] [blame] | 1551 | if(currLayer->acquireFenceFd >= 0) { |
| 1552 | rotData.acq_fen_fd_cnt = 1; //1 ioctl call per rot session |
| 1553 | } |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1554 | int ret = 0; |
Raj Kamal | 4b02b74 | 2014-10-12 20:51:14 +0530 | [diff] [blame] | 1555 | if(LIKELY(!swapzero) and (not ctx->mLayerRotMap[dpy]->isRotCached(i))) |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 1556 | ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData); |
| 1557 | |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1558 | if(ret < 0) { |
| 1559 | ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s", |
| 1560 | __FUNCTION__, strerror(errno)); |
Tatenda Chipeperekwa | a4550ce | 2014-06-06 15:25:37 -0700 | [diff] [blame] | 1561 | close(rotReleaseFd); |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1562 | } else { |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1563 | close(currLayer->acquireFenceFd); |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1564 | //For MDP to wait on. |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1565 | currLayer->acquireFenceFd = |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1566 | dup(rotReleaseFd); |
| 1567 | //A buffer is free to be used by producer as soon as its copied to |
| 1568 | //rotator |
Ramkumar Radhakrishnan | 36bd527 | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1569 | currLayer->releaseFenceFd = |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1570 | rotReleaseFd; |
| 1571 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1572 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1573 | |
Balamurugan Thanikachalam | f558c86 | 2014-01-31 18:23:20 +0530 | [diff] [blame] | 1574 | //Accumulate acquireFenceFds for MDP Overlays |
Ramkumar Radhakrishnan | 8bb48d3 | 2013-12-30 23:11:27 -0800 | [diff] [blame] | 1575 | if(list->outbufAcquireFenceFd >= 0) { |
| 1576 | //Writeback output buffer |
Raj Kamal | 4b02b74 | 2014-10-12 20:51:14 +0530 | [diff] [blame] | 1577 | if(LIKELY(!swapzero) ) |
| 1578 | acquireFd[count++] = list->outbufAcquireFenceFd; |
Ramkumar Radhakrishnan | 8bb48d3 | 2013-12-30 23:11:27 -0800 | [diff] [blame] | 1579 | } |
| 1580 | |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1581 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 1582 | if(((isAbcInUse(ctx)== true ) || |
| 1583 | (list->hwLayers[i].compositionType == HWC_OVERLAY)) && |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1584 | list->hwLayers[i].acquireFenceFd >= 0) { |
Raj Kamal | 4b02b74 | 2014-10-12 20:51:14 +0530 | [diff] [blame] | 1585 | if(LIKELY(!swapzero) ) { |
| 1586 | // if ABC is enabled for more than one layer. |
| 1587 | // renderBufIndexforABC will work as FB.Hence |
| 1588 | // set the acquireFD from fd - which is coming from copybit |
| 1589 | if(fd >= 0 && (isAbcInUse(ctx) == true)) { |
| 1590 | if(ctx->listStats[dpy].renderBufIndexforABC ==(int32_t)i) |
| 1591 | acquireFd[count++] = fd; |
| 1592 | else |
| 1593 | continue; |
| 1594 | } else |
| 1595 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
| 1596 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1597 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1598 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
Raj Kamal | 4b02b74 | 2014-10-12 20:51:14 +0530 | [diff] [blame] | 1599 | if(LIKELY(!swapzero) ) { |
| 1600 | if(fd >= 0) { |
| 1601 | //set the acquireFD from fd - which is coming from c2d |
| 1602 | acquireFd[count++] = fd; |
| 1603 | // Buffer sync IOCTL should be async when using c2d fence is |
| 1604 | // used |
| 1605 | data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT; |
| 1606 | } else if(list->hwLayers[i].acquireFenceFd >= 0) |
| 1607 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
| 1608 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1609 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Arun Kumar K.R | b2a03b1 | 2014-06-03 11:54:10 -0700 | [diff] [blame] | 1612 | if ((fd >= 0) && !dpy && ctx->mPtorInfo.isActive()) { |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 1613 | // Acquire c2d fence of Overlap render buffer |
Raj Kamal | 4b02b74 | 2014-10-12 20:51:14 +0530 | [diff] [blame] | 1614 | if(LIKELY(!swapzero) ) |
| 1615 | acquireFd[count++] = fd; |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1618 | data.acq_fen_fd_cnt = count; |
| 1619 | fbFd = ctx->dpyAttr[dpy].fd; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1620 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1621 | //Waits for acquire fences, returns a release fence |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1622 | if(LIKELY(!swapzero)) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1623 | ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1624 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1625 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1626 | if(ret < 0) { |
Ramkumar Radhakrishnan | b32a0bc | 2013-04-11 17:57:32 -0700 | [diff] [blame] | 1627 | ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s", |
| 1628 | __FUNCTION__, strerror(errno)); |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 1629 | ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%zu", |
Ramkumar Radhakrishnan | b32a0bc | 2013-04-11 17:57:32 -0700 | [diff] [blame] | 1630 | __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd, |
| 1631 | dpy, list->numHwLayers); |
Tatenda Chipeperekwa | a4550ce | 2014-06-06 15:25:37 -0700 | [diff] [blame] | 1632 | close(releaseFd); |
| 1633 | releaseFd = -1; |
| 1634 | close(retireFd); |
| 1635 | retireFd = -1; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1636 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1637 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1638 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1639 | if(list->hwLayers[i].compositionType == HWC_OVERLAY || |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 1640 | #ifdef QCOM_BSP |
Terence Hampson | c67b037 | 2013-10-09 11:32:21 -0400 | [diff] [blame] | 1641 | list->hwLayers[i].compositionType == HWC_BLIT || |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 1642 | #endif |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1643 | list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1644 | //Populate releaseFenceFds. |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1645 | if(UNLIKELY(swapzero)) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1646 | list->hwLayers[i].releaseFenceFd = -1; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1647 | } else if(isExtAnimating) { |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1648 | // Release all the app layer fds immediately, |
| 1649 | // if animation is in progress. |
Ramkumar Radhakrishnan | a70981a | 2013-08-28 11:33:53 -0700 | [diff] [blame] | 1650 | list->hwLayers[i].releaseFenceFd = -1; |
Naseer Ahmed | 330a282 | 2014-03-05 11:57:23 -0500 | [diff] [blame] | 1651 | } else if(list->hwLayers[i].releaseFenceFd < 0 ) { |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 1652 | #ifdef QCOM_BSP |
Zohaib Alam | 1bb6561 | 2013-09-28 03:38:20 -0400 | [diff] [blame] | 1653 | //If rotator has not already populated this field |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 1654 | // & if it's a not VPU layer |
Ramakant Singh | 467759f | 2014-04-16 11:09:40 +0530 | [diff] [blame] | 1655 | |
| 1656 | // if ABC is enabled for more than one layer |
| 1657 | if(fd >= 0 && (isAbcInUse(ctx) == true) && |
| 1658 | ctx->listStats[dpy].renderBufIndexforABC !=(int32_t)i){ |
| 1659 | list->hwLayers[i].releaseFenceFd = dup(fd); |
| 1660 | } else if((list->hwLayers[i].compositionType == HWC_BLIT)&& |
| 1661 | (isAbcInUse(ctx) == false)){ |
| 1662 | //For Blit, the app layers should be released when the Blit |
| 1663 | //is complete. This fd was passed from copybit->draw |
Balamurugan Thanikachalam | f558c86 | 2014-01-31 18:23:20 +0530 | [diff] [blame] | 1664 | list->hwLayers[i].releaseFenceFd = dup(fd); |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 1665 | } else |
| 1666 | #endif |
| 1667 | { |
Balamurugan Thanikachalam | f558c86 | 2014-01-31 18:23:20 +0530 | [diff] [blame] | 1668 | list->hwLayers[i].releaseFenceFd = dup(releaseFd); |
| 1669 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1670 | } |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1671 | } |
| 1672 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1673 | |
| 1674 | if(fd >= 0) { |
| 1675 | close(fd); |
| 1676 | fd = -1; |
| 1677 | } |
| 1678 | |
Sushil Chauhan | fb8845c | 2014-07-22 12:42:07 -0700 | [diff] [blame] | 1679 | if (ctx->mCopyBit[dpy]) { |
| 1680 | if (!dpy && ctx->mPtorInfo.isActive()) |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 1681 | ctx->mCopyBit[dpy]->setReleaseFdSync(releaseFd); |
| 1682 | else |
| 1683 | ctx->mCopyBit[dpy]->setReleaseFd(releaseFd); |
| 1684 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1685 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1686 | //Signals when MDP finishes reading rotator buffers. |
| 1687 | ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd); |
Arun Kumar K.R | 5183518 | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1688 | close(releaseFd); |
| 1689 | releaseFd = -1; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1690 | |
Arun Kumar K.R | 5183518 | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1691 | if(UNLIKELY(swapzero)) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1692 | list->retireFenceFd = -1; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1693 | } else { |
Arun Kumar K.R | 5183518 | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1694 | list->retireFenceFd = retireFd; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1695 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1696 | return ret; |
| 1697 | } |
| 1698 | |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 1699 | void setMdpFlags(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1700 | ovutils::eMdpFlags &mdpFlags, |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1701 | int rotDownscale, int transform) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1702 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Saurabh Shah | 220a30c | 2013-10-29 16:12:12 -0700 | [diff] [blame] | 1703 | MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1704 | |
| 1705 | if(layer->blending == HWC_BLENDING_PREMULT) { |
| 1706 | ovutils::setMdpFlags(mdpFlags, |
| 1707 | ovutils::OV_MDP_BLEND_FG_PREMULT); |
| 1708 | } |
| 1709 | |
Ramkumar Radhakrishnan | 4ec775f | 2014-07-23 17:43:18 -0700 | [diff] [blame] | 1710 | if(metadata && (metadata->operation & PP_PARAM_INTERLACED) && |
| 1711 | metadata->interlaced) { |
| 1712 | ovutils::setMdpFlags(mdpFlags, |
| 1713 | ovutils::OV_MDP_DEINTERLACE); |
| 1714 | } |
| 1715 | |
| 1716 | // Mark MDP flags with SECURE_OVERLAY_SESSION for driver |
| 1717 | if(isSecureBuffer(hnd)) { |
| 1718 | ovutils::setMdpFlags(mdpFlags, |
| 1719 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
Justin Philip | d616660 | 2014-08-12 13:42:21 +0530 | [diff] [blame] | 1720 | ovutils::setMdpFlags(mdpFlags, |
| 1721 | ovutils::OV_MDP_SMP_FORCE_ALLOC); |
| 1722 | } |
| 1723 | |
| 1724 | if(isProtectedBuffer(hnd)) { |
| 1725 | ovutils::setMdpFlags(mdpFlags, |
| 1726 | ovutils::OV_MDP_SMP_FORCE_ALLOC); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 1729 | if(isSecureDisplayBuffer(hnd)) { |
Ramkumar Radhakrishnan | 4ec775f | 2014-07-23 17:43:18 -0700 | [diff] [blame] | 1730 | // Mark MDP flags with SECURE_DISPLAY_OVERLAY_SESSION for driver |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 1731 | ovutils::setMdpFlags(mdpFlags, |
| 1732 | ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION); |
| 1733 | } |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 1734 | |
| 1735 | //Pre-rotation will be used using rotator. |
| 1736 | if(has90Transform(layer) && isRotationDoable(ctx, hnd)) { |
| 1737 | ovutils::setMdpFlags(mdpFlags, |
| 1738 | ovutils::OV_MDP_SOURCE_ROTATED_90); |
| 1739 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1740 | //No 90 component and no rot-downscale then flips done by MDP |
| 1741 | //If we use rot then it might as well do flips |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1742 | if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) { |
| 1743 | if(transform & HWC_TRANSFORM_FLIP_H) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1744 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H); |
| 1745 | } |
| 1746 | |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1747 | if(transform & HWC_TRANSFORM_FLIP_V) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1748 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V); |
| 1749 | } |
| 1750 | } |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1751 | |
| 1752 | if(metadata && |
| 1753 | ((metadata->operation & PP_PARAM_HSIC) |
| 1754 | || (metadata->operation & PP_PARAM_IGC) |
| 1755 | || (metadata->operation & PP_PARAM_SHARP2))) { |
| 1756 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN); |
| 1757 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1758 | } |
| 1759 | |
Prabhanjan Kandula | a1d8301 | 2013-04-23 13:06:02 +0530 | [diff] [blame] | 1760 | int configRotator(Rotator *rot, Whf& whf, |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1761 | hwc_rect_t& crop, const eMdpFlags& mdpFlags, |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1762 | const eTransform& orient, const int& downscale) { |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1763 | |
Prabhanjan Kandula | a1d8301 | 2013-04-23 13:06:02 +0530 | [diff] [blame] | 1764 | // Fix alignments for TILED format |
| 1765 | if(whf.format == MDP_Y_CRCB_H2V2_TILE || |
| 1766 | whf.format == MDP_Y_CBCR_H2V2_TILE) { |
| 1767 | whf.w = utils::alignup(whf.w, 64); |
| 1768 | whf.h = utils::alignup(whf.h, 32); |
| 1769 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1770 | rot->setSource(whf); |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1771 | |
| 1772 | if (qdutils::MDPVersion::getInstance().getMDPVersion() >= |
| 1773 | qdutils::MDSS_V5) { |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 1774 | Dim rotCrop(crop.left, crop.top, crop.right - crop.left, |
| 1775 | crop.bottom - crop.top); |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1776 | rot->setCrop(rotCrop); |
| 1777 | } |
| 1778 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1779 | rot->setFlags(mdpFlags); |
| 1780 | rot->setTransform(orient); |
| 1781 | rot->setDownscale(downscale); |
| 1782 | if(!rot->commit()) return -1; |
| 1783 | return 0; |
| 1784 | } |
| 1785 | |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 1786 | int configMdp(Overlay *ov, const PipeArgs& parg, |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1787 | const eTransform& orient, const hwc_rect_t& crop, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1788 | const hwc_rect_t& pos, const MetaData_t *metadata, |
| 1789 | const eDest& dest) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1790 | ov->setSource(parg, dest); |
| 1791 | ov->setTransform(orient, dest); |
| 1792 | |
| 1793 | int crop_w = crop.right - crop.left; |
| 1794 | int crop_h = crop.bottom - crop.top; |
| 1795 | Dim dcrop(crop.left, crop.top, crop_w, crop_h); |
| 1796 | ov->setCrop(dcrop, dest); |
| 1797 | |
| 1798 | int posW = pos.right - pos.left; |
| 1799 | int posH = pos.bottom - pos.top; |
| 1800 | Dim position(pos.left, pos.top, posW, posH); |
| 1801 | ov->setPosition(position, dest); |
| 1802 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1803 | if (metadata) |
| 1804 | ov->setVisualParams(*metadata, dest); |
| 1805 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1806 | if (!ov->commit(dest)) { |
| 1807 | return -1; |
| 1808 | } |
| 1809 | return 0; |
| 1810 | } |
| 1811 | |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1812 | int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer, |
| 1813 | const int& dpy, eMdpFlags& mdpFlags, eZorder& z, |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 1814 | const eDest& dest) { |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1815 | |
| 1816 | hwc_rect_t dst = layer->displayFrame; |
| 1817 | trimLayer(ctx, dpy, 0, dst, dst); |
| 1818 | |
| 1819 | int w = ctx->dpyAttr[dpy].xres; |
| 1820 | int h = ctx->dpyAttr[dpy].yres; |
| 1821 | int dst_w = dst.right - dst.left; |
| 1822 | int dst_h = dst.bottom - dst.top; |
| 1823 | uint32_t color = layer->transform; |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 1824 | Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888)); |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1825 | |
Sushil Chauhan | f10c523 | 2013-12-19 10:35:54 -0800 | [diff] [blame] | 1826 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL); |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1827 | if (layer->blending == HWC_BLENDING_PREMULT) |
| 1828 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT); |
| 1829 | |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 1830 | PipeArgs parg(mdpFlags, whf, z, static_cast<eRotFlags>(0), |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1831 | layer->planeAlpha, |
| 1832 | (ovutils::eBlending) getBlending(layer->blending)); |
| 1833 | |
| 1834 | // Configure MDP pipe for Color layer |
| 1835 | Dim pos(dst.left, dst.top, dst_w, dst_h); |
| 1836 | ctx->mOverlay->setSource(parg, dest); |
| 1837 | ctx->mOverlay->setColor(color, dest); |
| 1838 | ctx->mOverlay->setTransform(0, dest); |
| 1839 | ctx->mOverlay->setCrop(pos, dest); |
| 1840 | ctx->mOverlay->setPosition(pos, dest); |
| 1841 | |
| 1842 | if (!ctx->mOverlay->commit(dest)) { |
| 1843 | ALOGE("%s: Configure color layer failed!", __FUNCTION__); |
| 1844 | return -1; |
| 1845 | } |
| 1846 | return 0; |
| 1847 | } |
| 1848 | |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 1849 | void updateSource(eTransform& orient, Whf& whf, |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 1850 | hwc_rect_t& crop, Rotator *rot) { |
| 1851 | Dim transformedCrop(crop.left, crop.top, |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1852 | crop.right - crop.left, |
| 1853 | crop.bottom - crop.top); |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1854 | if (qdutils::MDPVersion::getInstance().getMDPVersion() >= |
| 1855 | qdutils::MDSS_V5) { |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 1856 | //B-family rotator internally could modify destination dimensions if |
| 1857 | //downscaling is supported |
| 1858 | whf = rot->getDstWhf(); |
| 1859 | transformedCrop = rot->getDstDimensions(); |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1860 | } else { |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 1861 | //A-family rotator rotates entire buffer irrespective of crop, forcing |
| 1862 | //us to recompute the crop based on transform |
| 1863 | orient = static_cast<eTransform>(ovutils::getMdpOrient(orient)); |
| 1864 | preRotateSource(orient, whf, transformedCrop); |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1865 | } |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 1866 | |
| 1867 | crop.left = transformedCrop.x; |
| 1868 | crop.top = transformedCrop.y; |
| 1869 | crop.right = transformedCrop.x + transformedCrop.w; |
| 1870 | crop.bottom = transformedCrop.y + transformedCrop.h; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1871 | } |
| 1872 | |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 1873 | int getRotDownscale(hwc_context_t *ctx, const hwc_layer_1_t *layer) { |
| 1874 | if(not qdutils::MDPVersion::getInstance().isRotDownscaleEnabled()) { |
| 1875 | return 0; |
| 1876 | } |
| 1877 | |
| 1878 | int downscale = 0; |
| 1879 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
| 1880 | hwc_rect_t dst = layer->displayFrame; |
| 1881 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1882 | |
| 1883 | if(not hnd) { |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
| 1887 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 1888 | bool isInterlaced = metadata && (metadata->operation & PP_PARAM_INTERLACED) |
| 1889 | && metadata->interlaced; |
| 1890 | int transform = layer->transform; |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 1891 | uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags); |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 1892 | |
| 1893 | if(isYuvBuffer(hnd)) { |
| 1894 | if(ctx->mMDP.version >= qdutils::MDP_V4_2 && |
| 1895 | ctx->mMDP.version < qdutils::MDSS_V5) { |
| 1896 | downscale = Rotator::getDownscaleFactor(crop.right - crop.left, |
| 1897 | crop.bottom - crop.top, dst.right - dst.left, |
| 1898 | dst.bottom - dst.top, format, isInterlaced); |
| 1899 | } else { |
| 1900 | Dim adjCrop(crop.left, crop.top, crop.right - crop.left, |
| 1901 | crop.bottom - crop.top); |
| 1902 | Dim pos(dst.left, dst.top, dst.right - dst.left, |
| 1903 | dst.bottom - dst.top); |
| 1904 | if(transform & HAL_TRANSFORM_ROT_90) { |
| 1905 | swap(adjCrop.w, adjCrop.h); |
| 1906 | } |
| 1907 | downscale = Rotator::getDownscaleFactor(adjCrop.w, adjCrop.h, pos.w, |
| 1908 | pos.h, format, isInterlaced); |
| 1909 | } |
| 1910 | } |
| 1911 | return downscale; |
| 1912 | } |
| 1913 | |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 1914 | bool isZoomModeEnabled(hwc_rect_t crop) { |
| 1915 | // This does not work for zooming in top left corner of the image |
| 1916 | return(crop.top > 0 || crop.left > 0); |
| 1917 | } |
| 1918 | |
| 1919 | void updateCropAIVVideoMode(hwc_context_t *ctx, hwc_rect_t& crop, int dpy) { |
| 1920 | ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Source crop [%d %d %d %d]", dpy, |
| 1921 | crop.left, crop.top, crop.right, crop.bottom); |
| 1922 | if(isZoomModeEnabled(crop)) { |
| 1923 | Dim srcCrop(crop.left, crop.top, |
| 1924 | crop.right - crop.left, |
| 1925 | crop.bottom - crop.top); |
| 1926 | int extW = ctx->dpyAttr[dpy].xres; |
| 1927 | int extH = ctx->dpyAttr[dpy].yres; |
| 1928 | //Crop the original video in order to fit external display aspect ratio |
| 1929 | if(srcCrop.w * extH < extW * srcCrop.h) { |
| 1930 | int offset = (srcCrop.h - ((srcCrop.w * extH) / extW)) / 2; |
| 1931 | crop.top += offset; |
| 1932 | crop.bottom -= offset; |
| 1933 | } else { |
| 1934 | int offset = (srcCrop.w - ((extW * srcCrop.h) / extH)) / 2; |
| 1935 | crop.left += offset; |
| 1936 | crop.right -= offset; |
| 1937 | } |
| 1938 | ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified" |
| 1939 | " source crop [%d %d %d %d]", extW, extH, dpy, |
| 1940 | crop.left, crop.top, crop.right, crop.bottom); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | void updateDestAIVVideoMode(hwc_context_t *ctx, hwc_rect_t crop, |
| 1945 | hwc_rect_t& dst, int dpy) { |
| 1946 | ALOGD_IF(HWC_UTILS_DEBUG, "dpy %d Destination position [%d %d %d %d]", dpy, |
| 1947 | dst.left, dst.top, dst.right, dst.bottom); |
| 1948 | Dim srcCrop(crop.left, crop.top, |
| 1949 | crop.right - crop.left, |
| 1950 | crop.bottom - crop.top); |
| 1951 | int extW = ctx->dpyAttr[dpy].xres; |
| 1952 | int extH = ctx->dpyAttr[dpy].yres; |
| 1953 | // Set the destination coordinates of external display to full screen, |
Ramkumar Radhakrishnan | 812999a | 2014-09-11 21:42:07 -0700 | [diff] [blame] | 1954 | // when zoom in mode is enabled or the ratio between video aspect ratio |
| 1955 | // and external display aspect ratio is below the minimum tolerance level |
| 1956 | // and above maximum tolerance level |
| 1957 | float videoAspectRatio = ((float)srcCrop.w / (float)srcCrop.h); |
| 1958 | float extDisplayAspectRatio = ((float)extW / (float)extH); |
| 1959 | float videoToExternalRatio = videoAspectRatio / extDisplayAspectRatio; |
| 1960 | if((fabs(1.0f - videoToExternalRatio) <= ctx->mAspectRatioToleranceLevel) || |
| 1961 | (isZoomModeEnabled(crop))) { |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 1962 | dst.left = 0; |
| 1963 | dst.top = 0; |
| 1964 | dst.right = extW; |
| 1965 | dst.bottom = extH; |
| 1966 | } |
| 1967 | ALOGD_IF(HWC_UTILS_DEBUG, "External Resolution [%d %d] dpy %d Modified" |
| 1968 | " Destination position [%d %d %d %d] Source crop [%d %d %d %d]", |
| 1969 | extW, extH, dpy, dst.left, dst.top, dst.right, dst.bottom, |
| 1970 | crop.left, crop.top, crop.right, crop.bottom); |
| 1971 | } |
| 1972 | |
Ramkumar Radhakrishnan | b33f490 | 2014-10-03 16:46:35 -0700 | [diff] [blame] | 1973 | void updateCoordinates(hwc_context_t *ctx, hwc_rect_t& crop, |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 1974 | hwc_rect_t& dst, int dpy) { |
| 1975 | updateCropAIVVideoMode(ctx, crop, dpy); |
| 1976 | updateDestAIVVideoMode(ctx, crop, dst, dpy); |
| 1977 | } |
| 1978 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1979 | int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1980 | const int& dpy, eMdpFlags& mdpFlags, eZorder& z, |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 1981 | const eDest& dest, Rotator **rot) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1982 | |
| 1983 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1984 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1985 | if(!hnd) { |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1986 | if (layer->flags & HWC_COLOR_FILL) { |
| 1987 | // Configure Color layer |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 1988 | return configColorLayer(ctx, layer, dpy, mdpFlags, z, dest); |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1989 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1990 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 1991 | return -1; |
| 1992 | } |
| 1993 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1994 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 1995 | |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 1996 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1997 | hwc_rect_t dst = layer->displayFrame; |
| 1998 | int transform = layer->transform; |
| 1999 | eTransform orient = static_cast<eTransform>(transform); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2000 | int rotFlags = ovutils::ROT_FLAGS_NONE; |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 2001 | uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags); |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 2002 | Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size); |
Zohaib Alam | 1bb6561 | 2013-09-28 03:38:20 -0400 | [diff] [blame] | 2003 | |
Sushil Chauhan | 1f6d68f | 2013-10-11 11:49:35 -0700 | [diff] [blame] | 2004 | // Handle R/B swap |
| 2005 | if (layer->flags & HWC_FORMAT_RB_SWAP) { |
| 2006 | if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888) |
| 2007 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888); |
| 2008 | else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888) |
| 2009 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888); |
| 2010 | } |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 2011 | // update source crop and destination position of AIV video layer. |
Ramkumar Radhakrishnan | b33f490 | 2014-10-03 16:46:35 -0700 | [diff] [blame] | 2012 | if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) { |
| 2013 | updateCoordinates(ctx, crop, dst, dpy); |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 2014 | } |
Ramkumar Radhakrishnan | 939a9e7 | 2013-12-04 18:30:18 -0800 | [diff] [blame] | 2015 | calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient); |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 2016 | int downscale = getRotDownscale(ctx, layer); |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 2017 | setMdpFlags(ctx, layer, mdpFlags, downscale, transform); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2018 | |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 2019 | //if 90 component or downscale, use rot |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 2020 | if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2021 | *rot = ctx->mRotMgr->getNext(); |
| 2022 | if(*rot == NULL) return -1; |
Saurabh Shah | 39240c9 | 2014-03-31 10:31:42 -0700 | [diff] [blame] | 2023 | ctx->mLayerRotMap[dpy]->add(layer, *rot); |
Saurabh Shah | cd01835 | 2014-11-11 13:54:19 -0800 | [diff] [blame] | 2024 | BwcPM::setBwc(ctx, dpy, hnd, crop, dst, transform, downscale, |
| 2025 | mdpFlags); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2026 | //Configure rotator for pre-rotation |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 2027 | if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) { |
| 2028 | ALOGE("%s: configRotator failed!", __FUNCTION__); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2029 | return -1; |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 2030 | } |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 2031 | updateSource(orient, whf, crop, *rot); |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 2032 | rotFlags |= ROT_PREROTATED; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2033 | } |
| 2034 | |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 2035 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 2036 | orient = OVERLAY_TRANSFORM_0; |
| 2037 | transform = 0; |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 2038 | PipeArgs parg(mdpFlags, whf, z, |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 2039 | static_cast<eRotFlags>(rotFlags), layer->planeAlpha, |
| 2040 | (ovutils::eBlending) getBlending(layer->blending)); |
| 2041 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 2042 | if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2043 | ALOGE("%s: commit failed for low res panel", __FUNCTION__); |
| 2044 | return -1; |
| 2045 | } |
| 2046 | return 0; |
| 2047 | } |
| 2048 | |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 2049 | //Helper to 1) Ensure crops dont have gaps 2) Ensure L and W are even |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 2050 | void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR, |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 2051 | private_handle_t *hnd) { |
| 2052 | if(cropL.right - cropL.left) { |
| 2053 | if(isYuvBuffer(hnd)) { |
| 2054 | //Always safe to even down left |
| 2055 | ovutils::even_floor(cropL.left); |
| 2056 | //If right is even, automatically width is even, since left is |
| 2057 | //already even |
| 2058 | ovutils::even_floor(cropL.right); |
| 2059 | } |
| 2060 | //Make sure there are no gaps between left and right splits if the layer |
| 2061 | //is spread across BOTH halves |
| 2062 | if(cropR.right - cropR.left) { |
| 2063 | cropR.left = cropL.right; |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | if(cropR.right - cropR.left) { |
| 2068 | if(isYuvBuffer(hnd)) { |
| 2069 | //Always safe to even down left |
| 2070 | ovutils::even_floor(cropR.left); |
| 2071 | //If right is even, automatically width is even, since left is |
| 2072 | //already even |
| 2073 | ovutils::even_floor(cropR.right); |
| 2074 | } |
| 2075 | } |
| 2076 | } |
| 2077 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 2078 | int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 2079 | const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z, |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 2080 | const eDest& lDest, const eDest& rDest, |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2081 | Rotator **rot) { |
| 2082 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 2083 | if(!hnd) { |
| 2084 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 2085 | return -1; |
| 2086 | } |
| 2087 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 2088 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 2089 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2090 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 2091 | int hw_h = ctx->dpyAttr[dpy].yres; |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 2092 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2093 | hwc_rect_t dst = layer->displayFrame; |
| 2094 | int transform = layer->transform; |
| 2095 | eTransform orient = static_cast<eTransform>(transform); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2096 | int rotFlags = ROT_FLAGS_NONE; |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 2097 | uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags); |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 2098 | Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size); |
Zohaib Alam | 1bb6561 | 2013-09-28 03:38:20 -0400 | [diff] [blame] | 2099 | |
Sushil Chauhan | 1f6d68f | 2013-10-11 11:49:35 -0700 | [diff] [blame] | 2100 | // Handle R/B swap |
| 2101 | if (layer->flags & HWC_FORMAT_RB_SWAP) { |
| 2102 | if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888) |
| 2103 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888); |
| 2104 | else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888) |
| 2105 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888); |
| 2106 | } |
| 2107 | |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 2108 | // update source crop and destination position of AIV video layer. |
Ramkumar Radhakrishnan | b33f490 | 2014-10-03 16:46:35 -0700 | [diff] [blame] | 2109 | if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) { |
| 2110 | updateCoordinates(ctx, crop, dst, dpy); |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | /* Calculate the external display position based on MDP downscale, |
Ramkumar Radhakrishnan | a61a0da | 2014-03-03 14:46:21 -0800 | [diff] [blame] | 2114 | ActionSafe, and extorientation features. */ |
| 2115 | calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient); |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 2116 | int downscale = getRotDownscale(ctx, layer); |
| 2117 | setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform); |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 2118 | |
| 2119 | if(lDest != OV_INVALID && rDest != OV_INVALID) { |
| 2120 | //Enable overfetch |
| 2121 | setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE); |
| 2122 | } |
| 2123 | |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 2124 | //Will do something only if feature enabled and conditions suitable |
| 2125 | //hollow call otherwise |
| 2126 | if(ctx->mAD->prepare(ctx, crop, whf, hnd)) { |
| 2127 | overlay::Writeback *wb = overlay::Writeback::getInstance(); |
| 2128 | whf.format = wb->getOutputFormat(); |
| 2129 | } |
| 2130 | |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 2131 | if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2132 | (*rot) = ctx->mRotMgr->getNext(); |
| 2133 | if((*rot) == NULL) return -1; |
Saurabh Shah | 39240c9 | 2014-03-31 10:31:42 -0700 | [diff] [blame] | 2134 | ctx->mLayerRotMap[dpy]->add(layer, *rot); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2135 | //Configure rotator for pre-rotation |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 2136 | if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) { |
| 2137 | ALOGE("%s: configRotator failed!", __FUNCTION__); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2138 | return -1; |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 2139 | } |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 2140 | updateSource(orient, whf, crop, *rot); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2141 | rotFlags |= ROT_PREROTATED; |
| 2142 | } |
| 2143 | |
| 2144 | eMdpFlags mdpFlagsR = mdpFlagsL; |
| 2145 | setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER); |
| 2146 | |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 2147 | hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0}; |
| 2148 | hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0}; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2149 | |
Saurabh Shah | 07a8ca8 | 2013-08-06 18:45:42 -0700 | [diff] [blame] | 2150 | const int lSplit = getLeftSplit(ctx, dpy); |
| 2151 | |
Jeykumar Sankaran | 8b40b43 | 2014-05-30 23:26:59 -0700 | [diff] [blame] | 2152 | // Calculate Left rects |
| 2153 | if(dst.left < lSplit) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2154 | tmp_cropL = crop; |
| 2155 | tmp_dstL = dst; |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 2156 | hwc_rect_t scissor = {0, 0, lSplit, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 2157 | scissor = getIntersection(ctx->mViewFrame[dpy], scissor); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2158 | qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0); |
| 2159 | } |
Jeykumar Sankaran | 8b40b43 | 2014-05-30 23:26:59 -0700 | [diff] [blame] | 2160 | |
| 2161 | // Calculate Right rects |
| 2162 | if(dst.right > lSplit) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2163 | tmp_cropR = crop; |
| 2164 | tmp_dstR = dst; |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 2165 | hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 2166 | scissor = getIntersection(ctx->mViewFrame[dpy], scissor); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2167 | qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0); |
| 2168 | } |
| 2169 | |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 2170 | sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd); |
| 2171 | |
Saurabh Shah | 94d6236 | 2013-07-02 10:58:48 -0700 | [diff] [blame] | 2172 | //When buffer is H-flipped, contents of mixer config also needs to swapped |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2173 | //Not needed if the layer is confined to one half of the screen. |
| 2174 | //If rotator has been used then it has also done the flips, so ignore them. |
Jeykumar Sankaran | 8b40b43 | 2014-05-30 23:26:59 -0700 | [diff] [blame] | 2175 | if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) && |
| 2176 | (dst.right > lSplit) && (*rot) == NULL) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2177 | hwc_rect_t new_cropR; |
| 2178 | new_cropR.left = tmp_cropL.left; |
| 2179 | new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left); |
| 2180 | |
| 2181 | hwc_rect_t new_cropL; |
| 2182 | new_cropL.left = new_cropR.right; |
| 2183 | new_cropL.right = tmp_cropR.right; |
| 2184 | |
| 2185 | tmp_cropL.left = new_cropL.left; |
| 2186 | tmp_cropL.right = new_cropL.right; |
| 2187 | |
| 2188 | tmp_cropR.left = new_cropR.left; |
| 2189 | tmp_cropR.right = new_cropR.right; |
| 2190 | |
| 2191 | } |
| 2192 | |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 2193 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 2194 | orient = OVERLAY_TRANSFORM_0; |
| 2195 | transform = 0; |
| 2196 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2197 | //configure left mixer |
| 2198 | if(lDest != OV_INVALID) { |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 2199 | PipeArgs pargL(mdpFlagsL, whf, z, |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 2200 | static_cast<eRotFlags>(rotFlags), layer->planeAlpha, |
| 2201 | (ovutils::eBlending) getBlending(layer->blending)); |
| 2202 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2203 | if(configMdp(ctx->mOverlay, pargL, orient, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 2204 | tmp_cropL, tmp_dstL, metadata, lDest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2205 | ALOGE("%s: commit failed for left mixer config", __FUNCTION__); |
| 2206 | return -1; |
| 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | //configure right mixer |
| 2211 | if(rDest != OV_INVALID) { |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 2212 | PipeArgs pargR(mdpFlagsR, whf, z, |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 2213 | static_cast<eRotFlags>(rotFlags), |
| 2214 | layer->planeAlpha, |
| 2215 | (ovutils::eBlending) getBlending(layer->blending)); |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 2216 | tmp_dstR.right = tmp_dstR.right - lSplit; |
| 2217 | tmp_dstR.left = tmp_dstR.left - lSplit; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2218 | if(configMdp(ctx->mOverlay, pargR, orient, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 2219 | tmp_cropR, tmp_dstR, metadata, rDest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2220 | ALOGE("%s: commit failed for right mixer config", __FUNCTION__); |
| 2221 | return -1; |
| 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | return 0; |
| 2226 | } |
Arun Kumar K.R | a297845 | 2013-02-07 01:34:24 -0800 | [diff] [blame] | 2227 | |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 2228 | int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer, |
| 2229 | const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z, |
| 2230 | const eDest& lDest, const eDest& rDest, |
| 2231 | Rotator **rot) { |
| 2232 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 2233 | if(!hnd) { |
| 2234 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 2235 | return -1; |
| 2236 | } |
| 2237 | //Both pipes are configured to the same mixer |
| 2238 | eZorder lz = z; |
| 2239 | eZorder rz = (eZorder)(z + 1); |
| 2240 | |
| 2241 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 2242 | |
| 2243 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
| 2244 | hwc_rect_t dst = layer->displayFrame; |
| 2245 | int transform = layer->transform; |
| 2246 | eTransform orient = static_cast<eTransform>(transform); |
| 2247 | int rotFlags = ROT_FLAGS_NONE; |
| 2248 | uint32_t format = ovutils::getMdpFormat(hnd->format, hnd->flags); |
| 2249 | Whf whf(getWidth(hnd), getHeight(hnd), format, (uint32_t)hnd->size); |
| 2250 | |
| 2251 | int downscale = getRotDownscale(ctx, layer); |
| 2252 | setMdpFlags(ctx, layer, mdpFlagsL, downscale, transform); |
| 2253 | |
| 2254 | //XXX: Check if rotation is supported and valid for 3D |
| 2255 | if((has90Transform(layer) or downscale) and isRotationDoable(ctx, hnd)) { |
| 2256 | (*rot) = ctx->mRotMgr->getNext(); |
| 2257 | if((*rot) == NULL) return -1; |
| 2258 | ctx->mLayerRotMap[dpy]->add(layer, *rot); |
| 2259 | //Configure rotator for pre-rotation |
| 2260 | if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) { |
| 2261 | ALOGE("%s: configRotator failed!", __FUNCTION__); |
| 2262 | return -1; |
| 2263 | } |
| 2264 | updateSource(orient, whf, crop, *rot); |
| 2265 | rotFlags |= ROT_PREROTATED; |
| 2266 | } |
| 2267 | |
| 2268 | eMdpFlags mdpFlagsR = mdpFlagsL; |
| 2269 | |
| 2270 | hwc_rect_t cropL = crop, dstL = dst; |
| 2271 | hwc_rect_t cropR = crop, dstR = dst; |
| 2272 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 2273 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 2274 | |
| 2275 | if(get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_L_R || |
| 2276 | get3DFormat(hnd) == HAL_3D_SIDE_BY_SIDE_R_L) { |
| 2277 | // Calculate Left rects |
| 2278 | // XXX: This assumes crop.right/2 is the center point of the video |
| 2279 | cropL.right = crop.right/2; |
| 2280 | dstL.left = dst.left/2; |
| 2281 | dstL.right = dst.right/2; |
| 2282 | |
| 2283 | // Calculate Right rects |
| 2284 | cropR.left = crop.right/2; |
| 2285 | dstR.left = hw_w/2 + dst.left/2; |
| 2286 | dstR.right = hw_w/2 + dst.right/2; |
| 2287 | } else if(get3DFormat(hnd) == HAL_3D_TOP_BOTTOM) { |
| 2288 | // Calculate Left rects |
| 2289 | cropL.bottom = crop.bottom/2; |
| 2290 | dstL.top = dst.top/2; |
| 2291 | dstL.bottom = dst.bottom/2; |
| 2292 | |
| 2293 | // Calculate Right rects |
| 2294 | cropR.top = crop.bottom/2; |
| 2295 | dstR.top = hw_h/2 + dst.top/2; |
| 2296 | dstR.bottom = hw_h/2 + dst.bottom/2; |
| 2297 | } else { |
| 2298 | ALOGE("%s: Unsupported 3D mode ", __FUNCTION__); |
| 2299 | return -1; |
| 2300 | } |
| 2301 | |
| 2302 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 2303 | orient = OVERLAY_TRANSFORM_0; |
| 2304 | transform = 0; |
| 2305 | |
| 2306 | //configure left pipe |
| 2307 | if(lDest != OV_INVALID) { |
| 2308 | PipeArgs pargL(mdpFlagsL, whf, lz, |
| 2309 | static_cast<eRotFlags>(rotFlags), layer->planeAlpha, |
| 2310 | (ovutils::eBlending) getBlending(layer->blending)); |
| 2311 | |
| 2312 | if(configMdp(ctx->mOverlay, pargL, orient, |
| 2313 | cropL, dstL, metadata, lDest) < 0) { |
| 2314 | ALOGE("%s: commit failed for left mixer config", __FUNCTION__); |
| 2315 | return -1; |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | //configure right pipe |
| 2320 | if(rDest != OV_INVALID) { |
| 2321 | PipeArgs pargR(mdpFlagsR, whf, rz, |
| 2322 | static_cast<eRotFlags>(rotFlags), |
| 2323 | layer->planeAlpha, |
| 2324 | (ovutils::eBlending) getBlending(layer->blending)); |
| 2325 | if(configMdp(ctx->mOverlay, pargR, orient, |
| 2326 | cropR, dstR, metadata, rDest) < 0) { |
| 2327 | ALOGE("%s: commit failed for right mixer config", __FUNCTION__); |
| 2328 | return -1; |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | return 0; |
| 2333 | } |
| 2334 | |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2335 | int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, |
| 2336 | const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z, |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 2337 | const eDest& lDest, const eDest& rDest, |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2338 | Rotator **rot) { |
| 2339 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 2340 | if(!hnd) { |
| 2341 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 2342 | return -1; |
| 2343 | } |
| 2344 | |
| 2345 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 2346 | |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2347 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);; |
| 2348 | hwc_rect_t dst = layer->displayFrame; |
| 2349 | int transform = layer->transform; |
| 2350 | eTransform orient = static_cast<eTransform>(transform); |
| 2351 | const int downscale = 0; |
| 2352 | int rotFlags = ROT_FLAGS_NONE; |
| 2353 | //Splitting only YUV layer on primary panel needs different zorders |
| 2354 | //for both layers as both the layers are configured to single mixer |
| 2355 | eZorder lz = z; |
| 2356 | eZorder rz = (eZorder)(z + 1); |
| 2357 | |
| 2358 | Whf whf(getWidth(hnd), getHeight(hnd), |
Praveena Pachipulusu | d9443c7 | 2014-02-17 10:42:28 +0530 | [diff] [blame] | 2359 | getMdpFormat(hnd->format), (uint32_t)hnd->size); |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2360 | |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 2361 | // update source crop and destination position of AIV video layer. |
Ramkumar Radhakrishnan | b33f490 | 2014-10-03 16:46:35 -0700 | [diff] [blame] | 2362 | if(ctx->listStats[dpy].mAIVVideoMode && isYuvBuffer(hnd)) { |
| 2363 | updateCoordinates(ctx, crop, dst, dpy); |
Ramkumar Radhakrishnan | 9d7bc31 | 2014-08-13 19:38:13 -0700 | [diff] [blame] | 2364 | } |
| 2365 | |
Ramkumar Radhakrishnan | 8ab3f5d | 2014-02-20 19:37:15 -0800 | [diff] [blame] | 2366 | /* Calculate the external display position based on MDP downscale, |
| 2367 | ActionSafe, and extorientation features. */ |
| 2368 | calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient); |
| 2369 | |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 2370 | setMdpFlags(ctx, layer, mdpFlagsL, 0, transform); |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2371 | trimLayer(ctx, dpy, transform, crop, dst); |
| 2372 | |
Ramkumar Radhakrishnan | 9d20b39 | 2013-11-15 19:32:47 -0800 | [diff] [blame] | 2373 | if(has90Transform(layer) && isRotationDoable(ctx, hnd)) { |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2374 | (*rot) = ctx->mRotMgr->getNext(); |
| 2375 | if((*rot) == NULL) return -1; |
Saurabh Shah | 39240c9 | 2014-03-31 10:31:42 -0700 | [diff] [blame] | 2376 | ctx->mLayerRotMap[dpy]->add(layer, *rot); |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2377 | //Configure rotator for pre-rotation |
| 2378 | if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) { |
| 2379 | ALOGE("%s: configRotator failed!", __FUNCTION__); |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2380 | return -1; |
| 2381 | } |
Saurabh Shah | 8ec9b5e | 2014-06-30 14:37:17 -0700 | [diff] [blame] | 2382 | updateSource(orient, whf, crop, *rot); |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2383 | rotFlags |= ROT_PREROTATED; |
| 2384 | } |
| 2385 | |
| 2386 | eMdpFlags mdpFlagsR = mdpFlagsL; |
| 2387 | int lSplit = dst.left + (dst.right - dst.left)/2; |
| 2388 | |
| 2389 | hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0}; |
| 2390 | hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0}; |
| 2391 | |
| 2392 | if(lDest != OV_INVALID) { |
| 2393 | tmp_cropL = crop; |
| 2394 | tmp_dstL = dst; |
| 2395 | hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom }; |
| 2396 | qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0); |
| 2397 | } |
| 2398 | if(rDest != OV_INVALID) { |
| 2399 | tmp_cropR = crop; |
| 2400 | tmp_dstR = dst; |
| 2401 | hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom }; |
| 2402 | qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0); |
| 2403 | } |
| 2404 | |
| 2405 | sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd); |
| 2406 | |
| 2407 | //When buffer is H-flipped, contents of mixer config also needs to swapped |
| 2408 | //Not needed if the layer is confined to one half of the screen. |
| 2409 | //If rotator has been used then it has also done the flips, so ignore them. |
| 2410 | if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID |
| 2411 | && rDest != OV_INVALID && (*rot) == NULL) { |
| 2412 | hwc_rect_t new_cropR; |
| 2413 | new_cropR.left = tmp_cropL.left; |
| 2414 | new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left); |
| 2415 | |
| 2416 | hwc_rect_t new_cropL; |
| 2417 | new_cropL.left = new_cropR.right; |
| 2418 | new_cropL.right = tmp_cropR.right; |
| 2419 | |
| 2420 | tmp_cropL.left = new_cropL.left; |
| 2421 | tmp_cropL.right = new_cropL.right; |
| 2422 | |
| 2423 | tmp_cropR.left = new_cropR.left; |
| 2424 | tmp_cropR.right = new_cropR.right; |
| 2425 | |
| 2426 | } |
| 2427 | |
| 2428 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 2429 | orient = OVERLAY_TRANSFORM_0; |
| 2430 | transform = 0; |
| 2431 | |
| 2432 | //configure left half |
| 2433 | if(lDest != OV_INVALID) { |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 2434 | PipeArgs pargL(mdpFlagsL, whf, lz, |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2435 | static_cast<eRotFlags>(rotFlags), layer->planeAlpha, |
| 2436 | (ovutils::eBlending) getBlending(layer->blending)); |
| 2437 | |
| 2438 | if(configMdp(ctx->mOverlay, pargL, orient, |
| 2439 | tmp_cropL, tmp_dstL, metadata, lDest) < 0) { |
| 2440 | ALOGE("%s: commit failed for left half config", __FUNCTION__); |
| 2441 | return -1; |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | //configure right half |
| 2446 | if(rDest != OV_INVALID) { |
Saurabh Shah | 2c8ad05 | 2014-08-15 13:27:46 -0700 | [diff] [blame] | 2447 | PipeArgs pargR(mdpFlagsR, whf, rz, |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 2448 | static_cast<eRotFlags>(rotFlags), |
| 2449 | layer->planeAlpha, |
| 2450 | (ovutils::eBlending) getBlending(layer->blending)); |
| 2451 | if(configMdp(ctx->mOverlay, pargR, orient, |
| 2452 | tmp_cropR, tmp_dstR, metadata, rDest) < 0) { |
| 2453 | ALOGE("%s: commit failed for right half config", __FUNCTION__); |
| 2454 | return -1; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | return 0; |
| 2459 | } |
| 2460 | |
Amara Venkata Mastan Manoj Kumar | 9d373c0 | 2013-08-20 14:30:09 -0700 | [diff] [blame] | 2461 | bool canUseRotator(hwc_context_t *ctx, int dpy) { |
Raj Kamal | 068f457 | 2014-04-14 16:14:06 +0530 | [diff] [blame] | 2462 | if(ctx->mOverlay->isDMAMultiplexingSupported() && |
Ramkumar Radhakrishnan | 8bb48d3 | 2013-12-30 23:11:27 -0800 | [diff] [blame] | 2463 | isSecondaryConnected(ctx) && |
Amara Venkata Mastan Manoj Kumar | 5cbac94 | 2013-08-13 19:00:14 -0700 | [diff] [blame] | 2464 | !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) { |
Raj Kamal | 068f457 | 2014-04-14 16:14:06 +0530 | [diff] [blame] | 2465 | /* mdss driver on certain targets support multiplexing of DMA pipe |
Raj Kamal | a8c065f | 2013-10-22 14:52:45 +0530 | [diff] [blame] | 2466 | * in LINE and BLOCK modes for writeback panels. |
| 2467 | */ |
Amara Venkata Mastan Manoj Kumar | 9d373c0 | 2013-08-20 14:30:09 -0700 | [diff] [blame] | 2468 | if(dpy == HWC_DISPLAY_PRIMARY) |
| 2469 | return false; |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 2470 | } |
Ramakant Singh | b4106a1 | 2014-10-07 18:06:56 +0530 | [diff] [blame] | 2471 | if((ctx->mMDP.version == qdutils::MDP_V3_0_4) |
| 2472 | ||(ctx->mMDP.version == qdutils::MDP_V3_0_5)) |
Terence Hampson | 45c02ef | 2013-05-17 17:00:11 -0400 | [diff] [blame] | 2473 | return false; |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 2474 | return true; |
| 2475 | } |
| 2476 | |
Saurabh Shah | 07a8ca8 | 2013-08-06 18:45:42 -0700 | [diff] [blame] | 2477 | int getLeftSplit(hwc_context_t *ctx, const int& dpy) { |
| 2478 | //Default even split for all displays with high res |
| 2479 | int lSplit = ctx->dpyAttr[dpy].xres / 2; |
| 2480 | if(dpy == HWC_DISPLAY_PRIMARY && |
| 2481 | qdutils::MDPVersion::getInstance().getLeftSplit()) { |
| 2482 | //Override if split published by driver for primary |
| 2483 | lSplit = qdutils::MDPVersion::getInstance().getLeftSplit(); |
| 2484 | } |
| 2485 | return lSplit; |
| 2486 | } |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2487 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 2488 | bool isDisplaySplit(hwc_context_t* ctx, int dpy) { |
Prabhanjan Kandula | 5bae9f5 | 2014-05-15 16:48:18 +0530 | [diff] [blame] | 2489 | qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance(); |
Jeykumar Sankaran | dc76ba8 | 2015-01-28 14:51:50 -0800 | [diff] [blame] | 2490 | if(ctx->dpyAttr[dpy].xres > mdpHw.getMaxMixerWidth()) { |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 2491 | return true; |
| 2492 | } |
Prabhanjan Kandula | 5bae9f5 | 2014-05-15 16:48:18 +0530 | [diff] [blame] | 2493 | if(dpy == HWC_DISPLAY_PRIMARY && mdpHw.getRightSplit()) { |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 2494 | return true; |
| 2495 | } |
| 2496 | return false; |
| 2497 | } |
| 2498 | |
Ramkumar Radhakrishnan | 8bb48d3 | 2013-12-30 23:11:27 -0800 | [diff] [blame] | 2499 | //clear prev layer prop flags and realloc for current frame |
| 2500 | void reset_layer_prop(hwc_context_t* ctx, int dpy, int numAppLayers) { |
| 2501 | if(ctx->layerProp[dpy]) { |
| 2502 | delete[] ctx->layerProp[dpy]; |
| 2503 | ctx->layerProp[dpy] = NULL; |
| 2504 | } |
| 2505 | ctx->layerProp[dpy] = new LayerProp[numAppLayers]; |
| 2506 | } |
| 2507 | |
Ramakant Singh | 0def28c | 2014-03-28 20:43:13 +0530 | [diff] [blame] | 2508 | bool isAbcInUse(hwc_context_t *ctx){ |
| 2509 | return (ctx->enableABC && ctx->listStats[0].renderBufIndexforABC == 0); |
| 2510 | } |
| 2511 | |
Tatenda Chipeperekwa | 523eac5 | 2014-05-29 14:58:39 -0700 | [diff] [blame] | 2512 | void dumpBuffer(private_handle_t *ohnd, char *bufferName) { |
| 2513 | if (ohnd != NULL && ohnd->base) { |
| 2514 | char dumpFilename[PATH_MAX]; |
| 2515 | bool bResult = false; |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 2516 | int width = getWidth(ohnd); |
| 2517 | int height = getHeight(ohnd); |
| 2518 | int format = ohnd->format; |
| 2519 | //dummy aligned w & h. |
| 2520 | int alW = 0, alH = 0; |
| 2521 | int size = getBufferSizeAndDimensions(width, height, format, alW, alH); |
Tatenda Chipeperekwa | 523eac5 | 2014-05-29 14:58:39 -0700 | [diff] [blame] | 2522 | snprintf(dumpFilename, sizeof(dumpFilename), "/data/%s.%s.%dx%d.raw", |
| 2523 | bufferName, |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 2524 | overlay::utils::getFormatString(utils::getMdpFormat(format)), |
| 2525 | width, height); |
Tatenda Chipeperekwa | 523eac5 | 2014-05-29 14:58:39 -0700 | [diff] [blame] | 2526 | FILE* fp = fopen(dumpFilename, "w+"); |
| 2527 | if (NULL != fp) { |
Tatenda Chipeperekwa | cb2a243 | 2014-08-06 17:45:58 -0700 | [diff] [blame] | 2528 | bResult = (bool) fwrite((void*)ohnd->base, size, 1, fp); |
Tatenda Chipeperekwa | 523eac5 | 2014-05-29 14:58:39 -0700 | [diff] [blame] | 2529 | fclose(fp); |
| 2530 | } |
| 2531 | ALOGD("Buffer[%s] Dump to %s: %s", |
| 2532 | bufferName, dumpFilename, bResult ? "Success" : "Fail"); |
| 2533 | } |
| 2534 | } |
| 2535 | |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2536 | bool isGLESComp(hwc_context_t *ctx, |
| 2537 | hwc_display_contents_1_t* list) { |
| 2538 | int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers; |
| 2539 | for(int index = 0; index < numAppLayers; index++) { |
| 2540 | hwc_layer_1_t* layer = &(list->hwLayers[index]); |
| 2541 | if(layer->compositionType == HWC_FRAMEBUFFER) |
| 2542 | return true; |
| 2543 | } |
| 2544 | return false; |
| 2545 | } |
| 2546 | |
| 2547 | void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) { |
| 2548 | struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo; |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 2549 | if(!gpuHint->mGpuPerfModeEnable || !ctx || !list) |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2550 | return; |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 2551 | |
| 2552 | #ifdef QCOM_BSP |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2553 | /* Set the GPU hint flag to high for MIXED/GPU composition only for |
| 2554 | first frame after MDP -> GPU/MIXED mode transition. Set the GPU |
| 2555 | hint to default if the previous composition is GPU or current GPU |
| 2556 | composition is due to idle fallback */ |
| 2557 | if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) { |
| 2558 | gpuHint->mEGLDisplay = eglGetCurrentDisplay(); |
| 2559 | if(!gpuHint->mEGLDisplay) { |
| 2560 | ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__); |
| 2561 | return; |
| 2562 | } |
| 2563 | gpuHint->mEGLContext = eglGetCurrentContext(); |
| 2564 | if(!gpuHint->mEGLContext) { |
| 2565 | ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__); |
| 2566 | return; |
| 2567 | } |
| 2568 | } |
| 2569 | if(isGLESComp(ctx, list)) { |
Ramkumar Radhakrishnan | 3efce48 | 2014-05-28 15:40:17 -0700 | [diff] [blame] | 2570 | if(gpuHint->mCompositionState != COMPOSITION_STATE_GPU |
| 2571 | && !MDPComp::isIdleFallback()) { |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2572 | EGLint attr_list[] = {EGL_GPU_HINT_1, |
| 2573 | EGL_GPU_LEVEL_3, |
| 2574 | EGL_NONE }; |
| 2575 | if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) && |
| 2576 | !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay, |
| 2577 | gpuHint->mEGLContext, attr_list)) { |
| 2578 | ALOGW("eglGpuPerfHintQCOM failed for Built in display"); |
| 2579 | } else { |
| 2580 | gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3; |
Ramkumar Radhakrishnan | 3efce48 | 2014-05-28 15:40:17 -0700 | [diff] [blame] | 2581 | gpuHint->mCompositionState = COMPOSITION_STATE_GPU; |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2582 | } |
| 2583 | } else { |
| 2584 | EGLint attr_list[] = {EGL_GPU_HINT_1, |
| 2585 | EGL_GPU_LEVEL_0, |
| 2586 | EGL_NONE }; |
| 2587 | if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) && |
| 2588 | !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay, |
| 2589 | gpuHint->mEGLContext, attr_list)) { |
| 2590 | ALOGW("eglGpuPerfHintQCOM failed for Built in display"); |
| 2591 | } else { |
| 2592 | gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0; |
| 2593 | } |
Ramkumar Radhakrishnan | 3efce48 | 2014-05-28 15:40:17 -0700 | [diff] [blame] | 2594 | if(MDPComp::isIdleFallback()) { |
| 2595 | gpuHint->mCompositionState = COMPOSITION_STATE_IDLE_FALLBACK; |
| 2596 | } |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2597 | } |
| 2598 | } else { |
| 2599 | /* set the GPU hint flag to default for MDP composition */ |
| 2600 | EGLint attr_list[] = {EGL_GPU_HINT_1, |
| 2601 | EGL_GPU_LEVEL_0, |
| 2602 | EGL_NONE }; |
| 2603 | if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) && |
| 2604 | !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay, |
| 2605 | gpuHint->mEGLContext, attr_list)) { |
| 2606 | ALOGW("eglGpuPerfHintQCOM failed for Built in display"); |
| 2607 | } else { |
| 2608 | gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0; |
| 2609 | } |
Ramkumar Radhakrishnan | 3efce48 | 2014-05-28 15:40:17 -0700 | [diff] [blame] | 2610 | gpuHint->mCompositionState = COMPOSITION_STATE_MDP; |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2611 | } |
Saurabh Shah | 74eff4d | 2014-03-28 16:33:13 -0700 | [diff] [blame] | 2612 | #endif |
Ramkumar Radhakrishnan | fb82291 | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
Sushil Chauhan | defd352 | 2014-05-13 18:17:12 -0700 | [diff] [blame] | 2615 | bool isPeripheral(const hwc_rect_t& rect1, const hwc_rect_t& rect2) { |
| 2616 | // To be peripheral, 3 boundaries should match. |
| 2617 | uint8_t eqBounds = 0; |
| 2618 | if (rect1.left == rect2.left) |
| 2619 | eqBounds++; |
| 2620 | if (rect1.top == rect2.top) |
| 2621 | eqBounds++; |
| 2622 | if (rect1.right == rect2.right) |
| 2623 | eqBounds++; |
| 2624 | if (rect1.bottom == rect2.bottom) |
| 2625 | eqBounds++; |
| 2626 | return (eqBounds == 3); |
| 2627 | } |
| 2628 | |
Krishna Chaitanya Parimi | db992fd | 2014-10-22 20:50:50 +0530 | [diff] [blame] | 2629 | void processBootAnimCompleted(hwc_context_t *ctx) { |
| 2630 | char value[PROPERTY_VALUE_MAX]; |
| 2631 | int boot_finished = 0, ret = -1; |
| 2632 | int (*applyMode)(int) = NULL; |
| 2633 | void *modeHandle = NULL; |
| 2634 | |
| 2635 | // Reading property set on boot finish in SF |
| 2636 | property_get("service.bootanim.exit", value, "0"); |
| 2637 | boot_finished = atoi(value); |
| 2638 | if (!boot_finished) |
| 2639 | return; |
| 2640 | |
| 2641 | modeHandle = dlopen("libmm-qdcm.so", RTLD_NOW); |
| 2642 | if (modeHandle) { |
| 2643 | *(void **)&applyMode = dlsym(modeHandle, "applyDefaults"); |
| 2644 | if (applyMode) { |
| 2645 | ret = applyMode(HWC_DISPLAY_PRIMARY); |
| 2646 | if (ret) |
| 2647 | ALOGD("%s: Not able to apply default mode", __FUNCTION__); |
| 2648 | } else { |
| 2649 | ALOGE("%s: No symbol applyDefaults found", __FUNCTION__); |
| 2650 | } |
| 2651 | dlclose(modeHandle); |
| 2652 | } else { |
| 2653 | ALOGE("%s: Not able to load libmm-qdcm.so", __FUNCTION__); |
| 2654 | } |
| 2655 | |
| 2656 | ctx->mBootAnimCompleted = true; |
| 2657 | } |
| 2658 | |
Saurabh Shah | cd01835 | 2014-11-11 13:54:19 -0800 | [diff] [blame] | 2659 | void BwcPM::setBwc(const hwc_context_t *ctx, const int& dpy, |
| 2660 | const private_handle_t *hnd, |
| 2661 | const hwc_rect_t& crop, const hwc_rect_t& dst, |
Saurabh Shah | c46cf9d | 2014-07-02 15:22:34 -0700 | [diff] [blame] | 2662 | const int& transform,const int& downscale, |
| 2663 | ovutils::eMdpFlags& mdpFlags) { |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2664 | //Target doesnt support Bwc |
Prabhanjan Kandula | 5bae9f5 | 2014-05-15 16:48:18 +0530 | [diff] [blame] | 2665 | qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance(); |
Saurabh Shah | cd01835 | 2014-11-11 13:54:19 -0800 | [diff] [blame] | 2666 | if(not mdpHw.supportsBWC()) { |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2667 | return; |
| 2668 | } |
Saurabh Shah | cd01835 | 2014-11-11 13:54:19 -0800 | [diff] [blame] | 2669 | //Disabled at runtime |
| 2670 | if(not ctx->mBWCEnabled) return; |
| 2671 | //BWC not supported with rot-downscale |
| 2672 | if(downscale) return; |
| 2673 | //Not enabled for secondary displays |
| 2674 | if(dpy) return; |
| 2675 | //Not enabled for non-video buffers |
| 2676 | if(not isYuvBuffer(hnd)) return; |
| 2677 | |
Saurabh Shah | b6810df | 2014-06-17 16:00:22 -0700 | [diff] [blame] | 2678 | int src_w = crop.right - crop.left; |
| 2679 | int src_h = crop.bottom - crop.top; |
| 2680 | int dst_w = dst.right - dst.left; |
| 2681 | int dst_h = dst.bottom - dst.top; |
| 2682 | if(transform & HAL_TRANSFORM_ROT_90) { |
| 2683 | swap(src_w, src_h); |
| 2684 | } |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2685 | //src width > MAX mixer supported dim |
Jeykumar Sankaran | 3930580 | 2014-12-12 17:55:57 -0800 | [diff] [blame] | 2686 | if(src_w > (int) qdutils::MDPVersion::getInstance().getMaxPipeWidth()) { |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2687 | return; |
| 2688 | } |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2689 | //Decimation necessary, cannot use BWC. H/W requirement. |
| 2690 | if(qdutils::MDPVersion::getInstance().supportsDecimation()) { |
Saurabh Shah | b6810df | 2014-06-17 16:00:22 -0700 | [diff] [blame] | 2691 | uint8_t horzDeci = 0; |
| 2692 | uint8_t vertDeci = 0; |
| 2693 | ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horzDeci, |
| 2694 | vertDeci); |
Saurabh Shah | c5b96dc | 2013-06-05 13:19:52 -0700 | [diff] [blame] | 2695 | if(horzDeci || vertDeci) return; |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2696 | } |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2697 | |
| 2698 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN); |
| 2699 | } |
| 2700 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 2701 | void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) { |
Raj Kamal | 389d6e3 | 2014-08-04 14:43:24 +0530 | [diff] [blame] | 2702 | if(mCount >= RotMgr::MAX_ROT_SESS) return; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 2703 | mLayer[mCount] = layer; |
| 2704 | mRot[mCount] = rot; |
| 2705 | mCount++; |
| 2706 | } |
| 2707 | |
| 2708 | void LayerRotMap::reset() { |
Raj Kamal | 389d6e3 | 2014-08-04 14:43:24 +0530 | [diff] [blame] | 2709 | for (int i = 0; i < RotMgr::MAX_ROT_SESS; i++) { |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 2710 | mLayer[i] = 0; |
| 2711 | mRot[i] = 0; |
| 2712 | } |
| 2713 | mCount = 0; |
| 2714 | } |
| 2715 | |
Saurabh Shah | da5b3ce | 2013-11-26 10:48:06 -0800 | [diff] [blame] | 2716 | void LayerRotMap::clear() { |
Saurabh Shah | 7a60684 | 2013-12-11 14:36:04 -0800 | [diff] [blame] | 2717 | RotMgr::getInstance()->markUnusedTop(mCount); |
Saurabh Shah | da5b3ce | 2013-11-26 10:48:06 -0800 | [diff] [blame] | 2718 | reset(); |
| 2719 | } |
| 2720 | |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 2721 | bool LayerRotMap::isRotCached(uint32_t index) const { |
| 2722 | overlay::Rotator* rot = getRot(index); |
| 2723 | hwc_layer_1_t* layer = getLayer(index); |
| 2724 | |
| 2725 | if(rot and layer and layer->handle) { |
| 2726 | private_handle_t *hnd = (private_handle_t *)(layer->handle); |
| 2727 | return (rot->isRotCached(hnd->fd,(uint32_t)(hnd->offset))); |
| 2728 | } |
| 2729 | return false; |
| 2730 | } |
| 2731 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 2732 | void LayerRotMap::setReleaseFd(const int& fence) { |
| 2733 | for(uint32_t i = 0; i < mCount; i++) { |
Raj Kamal | bd3bdc6 | 2014-08-05 18:52:49 +0530 | [diff] [blame] | 2734 | if(mRot[i] and mLayer[i] and mLayer[i]->handle) { |
| 2735 | /* Ensure that none of the above (Rotator-instance, |
| 2736 | * layer and layer-handle) are NULL*/ |
| 2737 | if(isRotCached(i)) |
| 2738 | mRot[i]->setPrevBufReleaseFd(dup(fence)); |
| 2739 | else |
| 2740 | mRot[i]->setCurrBufReleaseFd(dup(fence)); |
| 2741 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 2742 | } |
| 2743 | } |
| 2744 | |
Jeykumar Sankaran | aedd143 | 2015-01-15 11:25:03 -0800 | [diff] [blame] | 2745 | hwc_rect expandROIFromMidPoint(hwc_rect roi, hwc_rect fullFrame) { |
| 2746 | int lRoiWidth = 0, rRoiWidth = 0; |
| 2747 | int half_frame_width = fullFrame.right/2; |
| 2748 | |
| 2749 | hwc_rect lFrame = fullFrame; |
| 2750 | hwc_rect rFrame = fullFrame; |
| 2751 | lFrame.right = (lFrame.right - lFrame.left)/2; |
| 2752 | rFrame.left = lFrame.right; |
| 2753 | |
| 2754 | hwc_rect lRoi = getIntersection(roi, lFrame); |
| 2755 | hwc_rect rRoi = getIntersection(roi, rFrame); |
| 2756 | |
| 2757 | lRoiWidth = lRoi.right - lRoi.left; |
| 2758 | rRoiWidth = rRoi.right - rRoi.left; |
| 2759 | |
| 2760 | if(lRoiWidth && rRoiWidth) { |
| 2761 | if(lRoiWidth < rRoiWidth) |
| 2762 | roi.left = half_frame_width - rRoiWidth; |
| 2763 | else |
| 2764 | roi.right = half_frame_width + lRoiWidth; |
| 2765 | } |
| 2766 | return roi; |
| 2767 | } |
| 2768 | |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 2769 | void resetROI(hwc_context_t *ctx, const int dpy) { |
| 2770 | const int fbXRes = (int)ctx->dpyAttr[dpy].xres; |
| 2771 | const int fbYRes = (int)ctx->dpyAttr[dpy].yres; |
| 2772 | if(isDisplaySplit(ctx, dpy)) { |
| 2773 | const int lSplit = getLeftSplit(ctx, dpy); |
| 2774 | ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0, lSplit, fbYRes}; |
| 2775 | ctx->listStats[dpy].rRoi = (struct hwc_rect){lSplit, 0, fbXRes, fbYRes}; |
| 2776 | } else { |
| 2777 | ctx->listStats[dpy].lRoi = (struct hwc_rect){0, 0,fbXRes, fbYRes}; |
| 2778 | ctx->listStats[dpy].rRoi = (struct hwc_rect){0, 0, 0, 0}; |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | hwc_rect_t getSanitizeROI(struct hwc_rect roi, hwc_rect boundary) |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2783 | { |
| 2784 | if(!isValidRect(roi)) |
| 2785 | return roi; |
| 2786 | |
| 2787 | struct hwc_rect t_roi = roi; |
| 2788 | |
| 2789 | const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign(); |
| 2790 | const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign(); |
| 2791 | const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign(); |
| 2792 | const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign(); |
| 2793 | const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth(); |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 2794 | const int MIN_HEIGHT = qdutils::MDPVersion::getInstance().getMinROIHeight(); |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2795 | |
| 2796 | /* Align to minimum width recommended by the panel */ |
| 2797 | if((t_roi.right - t_roi.left) < MIN_WIDTH) { |
| 2798 | if((t_roi.left + MIN_WIDTH) > boundary.right) |
| 2799 | t_roi.left = t_roi.right - MIN_WIDTH; |
| 2800 | else |
| 2801 | t_roi.right = t_roi.left + MIN_WIDTH; |
| 2802 | } |
| 2803 | |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 2804 | /* Align to minimum height recommended by the panel */ |
| 2805 | if((t_roi.bottom - t_roi.top) < MIN_HEIGHT) { |
| 2806 | if((t_roi.top + MIN_HEIGHT) > boundary.bottom) |
| 2807 | t_roi.top = t_roi.bottom - MIN_HEIGHT; |
| 2808 | else |
| 2809 | t_roi.bottom = t_roi.top + MIN_HEIGHT; |
| 2810 | } |
| 2811 | |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2812 | /* Align left and width to meet panel restrictions */ |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 2813 | if(LEFT_ALIGN) |
| 2814 | t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN); |
| 2815 | |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2816 | if(WIDTH_ALIGN) { |
| 2817 | int width = t_roi.right - t_roi.left; |
| 2818 | width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN); |
| 2819 | t_roi.right = t_roi.left + width; |
| 2820 | |
| 2821 | if(t_roi.right > boundary.right) { |
| 2822 | t_roi.right = boundary.right; |
| 2823 | t_roi.left = t_roi.right - width; |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 2824 | |
| 2825 | if(LEFT_ALIGN) |
| 2826 | t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN); |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2827 | } |
| 2828 | } |
| 2829 | |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2830 | |
| 2831 | /* Align top and height to meet panel restrictions */ |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 2832 | if(TOP_ALIGN) |
| 2833 | t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN); |
| 2834 | |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2835 | if(HEIGHT_ALIGN) { |
| 2836 | int height = t_roi.bottom - t_roi.top; |
| 2837 | height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN); |
| 2838 | t_roi.bottom = t_roi.top + height; |
| 2839 | |
| 2840 | if(t_roi.bottom > boundary.bottom) { |
| 2841 | t_roi.bottom = boundary.bottom; |
| 2842 | t_roi.top = t_roi.bottom - height; |
Jeykumar Sankaran | 6c7eeac | 2013-11-18 11:19:45 -0800 | [diff] [blame] | 2843 | |
| 2844 | if(TOP_ALIGN) |
| 2845 | t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN); |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2846 | } |
| 2847 | } |
| 2848 | |
Jeykumar Sankaran | 7c85238 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2849 | |
| 2850 | return t_roi; |
| 2851 | } |
| 2852 | |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 2853 | void handle_pause(hwc_context_t* ctx, int dpy) { |
Arun Kumar K.R | 33888f5 | 2014-10-09 15:56:33 -0700 | [diff] [blame] | 2854 | if(ctx->dpyAttr[dpy].connected) { |
| 2855 | ctx->mDrawLock.lock(); |
| 2856 | ctx->dpyAttr[dpy].isActive = true; |
| 2857 | ctx->dpyAttr[dpy].isPause = true; |
| 2858 | ctx->mDrawLock.unlock(); |
| 2859 | ctx->proc->invalidate(ctx->proc); |
| 2860 | |
| 2861 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 2862 | * 2 / 1000); |
| 2863 | |
| 2864 | // At this point all the pipes used by External have been |
| 2865 | // marked as UNSET. |
| 2866 | ctx->mDrawLock.lock(); |
| 2867 | // Perform commit to unstage the pipes. |
| 2868 | if (!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) { |
| 2869 | ALOGE("%s: display commit fail! for %d dpy", |
| 2870 | __FUNCTION__, dpy); |
| 2871 | } |
| 2872 | ctx->mDrawLock.unlock(); |
| 2873 | ctx->proc->invalidate(ctx->proc); |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 2874 | } |
| 2875 | return; |
| 2876 | } |
| 2877 | |
| 2878 | void handle_resume(hwc_context_t* ctx, int dpy) { |
Arun Kumar K.R | 33888f5 | 2014-10-09 15:56:33 -0700 | [diff] [blame] | 2879 | if(ctx->dpyAttr[dpy].connected) { |
| 2880 | ctx->mDrawLock.lock(); |
| 2881 | ctx->dpyAttr[dpy].isConfiguring = true; |
| 2882 | ctx->dpyAttr[dpy].isActive = true; |
| 2883 | ctx->mDrawLock.unlock(); |
| 2884 | ctx->proc->invalidate(ctx->proc); |
| 2885 | |
| 2886 | usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period |
| 2887 | * 2 / 1000); |
| 2888 | |
| 2889 | //At this point external has all the pipes it would need. |
| 2890 | ctx->mDrawLock.lock(); |
| 2891 | ctx->dpyAttr[dpy].isPause = false; |
| 2892 | ctx->mDrawLock.unlock(); |
| 2893 | ctx->proc->invalidate(ctx->proc); |
Manoj Kumar AVM | 9591a5e | 2014-08-21 22:50:21 -0700 | [diff] [blame] | 2894 | } |
| 2895 | return; |
| 2896 | } |
| 2897 | |
Tatenda Chipeperekwa | d80b617 | 2014-09-23 11:29:37 -0700 | [diff] [blame] | 2898 | void clearPipeResources(hwc_context_t* ctx, int dpy) { |
| 2899 | if(ctx->mOverlay) { |
| 2900 | ctx->mOverlay->configBegin(); |
| 2901 | ctx->mOverlay->configDone(); |
| 2902 | } |
| 2903 | if(ctx->mRotMgr) { |
| 2904 | ctx->mRotMgr->clear(); |
| 2905 | } |
| 2906 | // Call a display commit to ensure that pipes and associated |
| 2907 | // fd's are cleaned up. |
| 2908 | if(!Overlay::displayCommit(ctx->dpyAttr[dpy].fd)) { |
| 2909 | ALOGE("%s: display commit failed for %d", __FUNCTION__, dpy); |
| 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | // Handles online events when HDMI is the primary display. In particular, |
| 2914 | // online events for hdmi connected before AND after boot up and HWC init. |
| 2915 | void handle_online(hwc_context_t* ctx, int dpy) { |
| 2916 | // Close the current fd if it was opened earlier on when HWC |
| 2917 | // was initialized. |
| 2918 | if (ctx->dpyAttr[dpy].fd >= 0) { |
| 2919 | close(ctx->dpyAttr[dpy].fd); |
| 2920 | ctx->dpyAttr[dpy].fd = -1; |
| 2921 | } |
| 2922 | // TODO: If HDMI is connected after the display has booted up, |
| 2923 | // and the best configuration is different from the default |
| 2924 | // then we need to deal with this appropriately. |
| 2925 | ctx->mHDMIDisplay->configure(); |
| 2926 | updateDisplayInfo(ctx, dpy); |
| 2927 | initCompositionResources(ctx, dpy); |
| 2928 | ctx->dpyAttr[dpy].connected = true; |
| 2929 | } |
| 2930 | |
| 2931 | // Handles offline events for HDMI. This can be used for offline events |
| 2932 | // initiated by the HDMI driver and the CEC framework. |
| 2933 | void handle_offline(hwc_context_t* ctx, int dpy) { |
| 2934 | destroyCompositionResources(ctx, dpy); |
| 2935 | // Clear all pipe resources and call a display commit to ensure |
| 2936 | // that all the fd's are closed. This will ensure that the HDMI |
| 2937 | // core turns off and that we receive an event the next time the |
| 2938 | // cable is connected. |
| 2939 | if (ctx->mHDMIDisplay->isHDMIPrimaryDisplay()) { |
| 2940 | clearPipeResources(ctx, dpy); |
| 2941 | } |
| 2942 | ctx->mHDMIDisplay->teardown(); |
| 2943 | resetDisplayInfo(ctx, dpy); |
| 2944 | ctx->dpyAttr[dpy].connected = false; |
| 2945 | ctx->dpyAttr[dpy].isActive = false; |
| 2946 | } |
| 2947 | |
Naseer Ahmed | 6bbd0a1 | 2015-01-23 11:57:10 -0500 | [diff] [blame^] | 2948 | int convertS3DFormatToMode(int s3DFormat) { |
| 2949 | int ret; |
| 2950 | switch(s3DFormat) { |
| 2951 | case HAL_3D_SIDE_BY_SIDE_L_R: |
| 2952 | case HAL_3D_SIDE_BY_SIDE_R_L: |
| 2953 | ret = HDMI_S3D_SIDE_BY_SIDE; |
| 2954 | break; |
| 2955 | case HAL_3D_TOP_BOTTOM: |
| 2956 | ret = HDMI_S3D_TOP_AND_BOTTOM; |
| 2957 | break; |
| 2958 | default: |
| 2959 | ret = HDMI_S3D_NONE; |
| 2960 | } |
| 2961 | return ret; |
| 2962 | } |
| 2963 | |
| 2964 | bool needs3DComposition(hwc_context_t* ctx, int dpy) { |
| 2965 | return (displaySupports3D(ctx, dpy) && ctx->dpyAttr[dpy].connected && |
| 2966 | ctx->dpyAttr[dpy].s3dMode != HDMI_S3D_NONE); |
| 2967 | } |
| 2968 | |
| 2969 | void setup3DMode(hwc_context_t *ctx, int dpy, int s3dMode) { |
| 2970 | if (ctx->dpyAttr[dpy].s3dMode != s3dMode) { |
| 2971 | ALOGD("%s: setup 3D mode: %d", __FUNCTION__, s3dMode); |
| 2972 | if(ctx->mHDMIDisplay->configure3D(s3dMode)) { |
| 2973 | ctx->dpyAttr[dpy].s3dMode = s3dMode; |
| 2974 | } |
| 2975 | } |
| 2976 | } |
| 2977 | |
| 2978 | bool displaySupports3D(hwc_context_t* ctx, int dpy) { |
| 2979 | return ((dpy == HWC_DISPLAY_EXTERNAL) || |
| 2980 | ((dpy == HWC_DISPLAY_PRIMARY) && |
| 2981 | ctx->mHDMIDisplay->isHDMIPrimaryDisplay())); |
| 2982 | } |
| 2983 | |
| 2984 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2985 | };//namespace qhwc |