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