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