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