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