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