Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 3 | * Copyright (C) 2012-2013, The Linux Foundation All rights reserved. |
| 4 | * |
| 5 | * Not a Contribution, Apache license notifications and license are retained |
| 6 | * for attribution purposes only. |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | * you may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
Naseer Ahmed | 099a693 | 2013-09-09 14:25:20 -0400 | [diff] [blame] | 20 | #define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 21 | #define HWC_UTILS_DEBUG 0 |
Saurabh Shah | c5b96dc | 2013-06-05 13:19:52 -0700 | [diff] [blame] | 22 | #include <math.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 23 | #include <sys/ioctl.h> |
Naseer Ahmed | 66e9788 | 2013-03-19 20:42:11 -0400 | [diff] [blame] | 24 | #include <linux/fb.h> |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 25 | #include <binder/IServiceManager.h> |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 26 | #include <EGL/egl.h> |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 27 | #include <cutils/properties.h> |
Naseer Ahmed | 099a693 | 2013-09-09 14:25:20 -0400 | [diff] [blame] | 28 | #include <utils/Trace.h> |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 29 | #include <gralloc_priv.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 30 | #include <overlay.h> |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 31 | #include <overlayRotator.h> |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 32 | #include <overlayWriteback.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 33 | #include "hwc_utils.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 34 | #include "hwc_mdpcomp.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 35 | #include "hwc_fbupdate.h" |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 36 | #include "hwc_ad.h" |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 37 | #include "mdp_version.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 38 | #include "hwc_copybit.h" |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 39 | #include "hwc_dump_layers.h" |
Naseer Ahmed | 58780b9 | 2013-07-29 17:41:40 -0400 | [diff] [blame] | 40 | #include "hwc_vpuclient.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 41 | #include "external.h" |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 42 | #include "virtual.h" |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 43 | #include "hwc_qclient.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 44 | #include "QService.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 45 | #include "comptype.h" |
Tatenda Chipeperekwa | 266ef78 | 2014-03-05 13:02:24 -0800 | [diff] [blame] | 46 | #include "qd_utils.h" |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 47 | |
| 48 | using namespace qClient; |
| 49 | using namespace qService; |
| 50 | using namespace android; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 51 | using namespace overlay; |
| 52 | using namespace overlay::utils; |
| 53 | namespace ovutils = overlay::utils; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 54 | |
Ramkumar Radhakrishnan | 9c9a94b | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 55 | #ifdef __cplusplus |
| 56 | extern "C" { |
| 57 | #endif |
| 58 | |
| 59 | EGLAPI EGLBoolean eglGpuPerfHintQCOM(EGLDisplay dpy, EGLContext ctx, |
| 60 | EGLint *attrib_list); |
| 61 | #define EGL_GPU_HINT_1 0x32D0 |
| 62 | #define EGL_GPU_HINT_2 0x32D1 |
| 63 | |
| 64 | #define EGL_GPU_LEVEL_0 0x0 |
| 65 | #define EGL_GPU_LEVEL_1 0x1 |
| 66 | #define EGL_GPU_LEVEL_2 0x2 |
| 67 | #define EGL_GPU_LEVEL_3 0x3 |
| 68 | #define EGL_GPU_LEVEL_4 0x4 |
| 69 | #define EGL_GPU_LEVEL_5 0x5 |
| 70 | |
| 71 | #ifdef __cplusplus |
| 72 | } |
| 73 | #endif |
| 74 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 75 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 76 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 77 | static int openFramebufferDevice(hwc_context_t *ctx) |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 78 | { |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 79 | struct fb_fix_screeninfo finfo; |
| 80 | struct fb_var_screeninfo info; |
| 81 | |
| 82 | int fb_fd = openFb(HWC_DISPLAY_PRIMARY); |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 83 | if(fb_fd < 0) { |
| 84 | ALOGE("%s: Error Opening FB : %s", __FUNCTION__, strerror(errno)); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 85 | return -errno; |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) { |
| 89 | ALOGE("%s:Error in ioctl FBIOGET_VSCREENINFO: %s", __FUNCTION__, |
| 90 | strerror(errno)); |
| 91 | close(fb_fd); |
| 92 | return -errno; |
| 93 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 94 | |
| 95 | if (int(info.width) <= 0 || int(info.height) <= 0) { |
| 96 | // the driver doesn't return that information |
| 97 | // default to 160 dpi |
| 98 | info.width = ((info.xres * 25.4f)/160.0f + 0.5f); |
| 99 | info.height = ((info.yres * 25.4f)/160.0f + 0.5f); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 100 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 101 | |
| 102 | float xdpi = (info.xres * 25.4f) / info.width; |
| 103 | float ydpi = (info.yres * 25.4f) / info.height; |
| 104 | |
| 105 | #ifdef MSMFB_METADATA_GET |
| 106 | struct msmfb_metadata metadata; |
| 107 | memset(&metadata, 0 , sizeof(metadata)); |
| 108 | metadata.op = metadata_op_frame_rate; |
| 109 | |
| 110 | if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) { |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 111 | ALOGE("%s:Error retrieving panel frame rate: %s", __FUNCTION__, |
| 112 | strerror(errno)); |
| 113 | close(fb_fd); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 114 | return -errno; |
| 115 | } |
| 116 | |
| 117 | float fps = metadata.data.panel_frame_rate; |
| 118 | #else |
| 119 | //XXX: Remove reserved field usage on all baselines |
| 120 | //The reserved[3] field is used to store FPS by the driver. |
| 121 | float fps = info.reserved[3] & 0xFF; |
| 122 | #endif |
| 123 | |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 124 | if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) { |
| 125 | ALOGE("%s:Error in ioctl FBIOGET_FSCREENINFO: %s", __FUNCTION__, |
| 126 | strerror(errno)); |
| 127 | close(fb_fd); |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 128 | return -errno; |
Sravan Kumar D.V.N | 78f51e7 | 2013-04-16 10:24:55 +0530 | [diff] [blame] | 129 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 130 | |
| 131 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd; |
| 132 | //xres, yres may not be 32 aligned |
| 133 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8); |
| 134 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres; |
| 135 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres; |
| 136 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi; |
| 137 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi; |
| 138 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps; |
| 139 | |
Naseer Ahmed | 22616d9 | 2013-05-15 17:20:26 -0400 | [diff] [blame] | 140 | //Unblank primary on first boot |
| 141 | if(ioctl(fb_fd, FBIOBLANK,FB_BLANK_UNBLANK) < 0) { |
| 142 | ALOGE("%s: Failed to unblank display", __FUNCTION__); |
| 143 | return -errno; |
| 144 | } |
| 145 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].isActive = true; |
| 146 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 147 | return 0; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 150 | void initContext(hwc_context_t *ctx) |
| 151 | { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 152 | openFramebufferDevice(ctx); |
Raj kamal | 9af062e | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 153 | char value[PROPERTY_VALUE_MAX]; |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 154 | ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 155 | ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); |
| 156 | ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 157 | overlay::Overlay::initOverlay(); |
| 158 | ctx->mOverlay = overlay::Overlay::getInstance(); |
Saurabh Shah | 7a60684 | 2013-12-11 14:36:04 -0800 | [diff] [blame] | 159 | ctx->mRotMgr = RotMgr::getInstance(); |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 160 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 161 | //Is created and destroyed only once for primary |
| 162 | //For external it could get created and destroyed multiple times depending |
| 163 | //on what external we connect to. |
| 164 | ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] = |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 165 | IFBUpdate::getObject(ctx, HWC_DISPLAY_PRIMARY); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 166 | |
Arun Kumar K.R | 9fc8997 | 2014-01-02 17:01:02 -0800 | [diff] [blame] | 167 | // Check if the target supports copybit compostion (dyn/mdp) to |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 168 | // decide if we need to open the copybit module. |
| 169 | int compositionType = |
| 170 | qdutils::QCCompositionType::getInstance().getCompositionType(); |
| 171 | |
Arun Kumar K.R | 9fc8997 | 2014-01-02 17:01:02 -0800 | [diff] [blame] | 172 | // Only MDP copybit is used |
| 173 | if ((compositionType & (qdutils::COMPOSITION_TYPE_DYN | |
| 174 | qdutils::COMPOSITION_TYPE_MDP)) && |
| 175 | (qdutils::MDPVersion::getInstance().getMDPVersion() == |
| 176 | qdutils::MDP_V3_0_4)) { |
| 177 | ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(ctx, |
| 178 | HWC_DISPLAY_PRIMARY); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 181 | ctx->mExtDisplay = new ExternalDisplay(ctx); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 182 | ctx->mVirtualDisplay = new VirtualDisplay(ctx); |
| 183 | ctx->mVirtualonExtActive = false; |
| 184 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive = false; |
| 185 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = false; |
| 186 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = false; |
| 187 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected = false; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 188 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].mDownScaleMode= false; |
| 189 | ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].mDownScaleMode = false; |
| 190 | ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].mDownScaleMode = false; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 191 | |
| 192 | ctx->mMDPComp[HWC_DISPLAY_PRIMARY] = |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 193 | MDPComp::getObject(ctx, HWC_DISPLAY_PRIMARY); |
Jeykumar Sankaran | 27dee26 | 2013-08-01 17:09:54 -0700 | [diff] [blame] | 194 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].connected = true; |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 195 | |
Amara Venkata Mastan Manoj Kumar | 7fb1327 | 2013-07-01 13:59:34 -0700 | [diff] [blame] | 196 | for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 197 | ctx->mHwcDebug[i] = new HwcDebug(i); |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 198 | ctx->mLayerRotMap[i] = new LayerRotMap(); |
Ramkumar Radhakrishnan | a70981a | 2013-08-28 11:33:53 -0700 | [diff] [blame] | 199 | ctx->mAnimationState[i] = ANIMATION_STOPPED; |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 200 | ctx->dpyAttr[i].mActionSafePresent = false; |
| 201 | ctx->dpyAttr[i].mAsWidthRatio = 0; |
| 202 | ctx->dpyAttr[i].mAsHeightRatio = 0; |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 203 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 204 | |
Raj Kamal | fc5b922 | 2014-02-07 16:15:17 +0530 | [diff] [blame] | 205 | for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
| 206 | ctx->mPrevHwLayerCount[i] = 0; |
| 207 | } |
| 208 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 209 | MDPComp::init(ctx); |
Saurabh Shah | c4f1fa6 | 2013-09-03 13:12:14 -0700 | [diff] [blame] | 210 | ctx->mAD = new AssertiveDisplay(ctx); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 211 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 212 | ctx->vstate.enable = false; |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 213 | ctx->vstate.fakevsync = false; |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 214 | ctx->mExtOrientation = 0; |
Raj Kamal | 1cbe839 | 2014-01-27 19:35:13 +0530 | [diff] [blame] | 215 | ctx->numActiveDisplays = 1; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 216 | |
| 217 | //Right now hwc starts the service but anybody could do it, or it could be |
| 218 | //independent process as well. |
| 219 | QService::init(); |
| 220 | sp<IQClient> client = new QClient(ctx); |
| 221 | interface_cast<IQService>( |
| 222 | defaultServiceManager()->getService( |
| 223 | String16("display.qservice")))->connect(client); |
| 224 | |
Ramkumar Radhakrishnan | a70981a | 2013-08-28 11:33:53 -0700 | [diff] [blame] | 225 | // Initialize device orientation to its default orientation |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 226 | ctx->deviceOrientation = 0; |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 227 | ctx->mBufferMirrorMode = false; |
Tatenda Chipeperekwa | 093a0b6 | 2014-02-20 19:07:01 -0800 | [diff] [blame] | 228 | ctx->mVPUClient = NULL; |
| 229 | |
| 230 | // Read the system property to determine if downscale feature is enabled. |
| 231 | ctx->mMDPDownscaleEnabled = false; |
Tatenda Chipeperekwa | 093a0b6 | 2014-02-20 19:07:01 -0800 | [diff] [blame] | 232 | if(property_get("sys.hwc.mdp_downscale_enabled", value, "false") |
| 233 | && !strcmp(value, "true")) { |
| 234 | ctx->mMDPDownscaleEnabled = true; |
| 235 | } |
| 236 | |
Naseer Ahmed | 58780b9 | 2013-07-29 17:41:40 -0400 | [diff] [blame] | 237 | #ifdef VPU_TARGET |
| 238 | ctx->mVPUClient = new VPUClient(); |
| 239 | #endif |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 240 | |
Ramkumar Radhakrishnan | 9c9a94b | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 241 | // Initialize gpu perfomance hint related parameters |
| 242 | property_get("sys.hwc.gpu_perf_mode", value, "0"); |
| 243 | ctx->mGPUHintInfo.mGpuPerfModeEnable = atoi(value)? true : false; |
| 244 | |
| 245 | ctx->mGPUHintInfo.mEGLDisplay = NULL; |
| 246 | ctx->mGPUHintInfo.mEGLContext = NULL; |
| 247 | ctx->mGPUHintInfo.mPrevCompositionGLES = false; |
| 248 | ctx->mGPUHintInfo.mCurrGPUPerfMode = EGL_GPU_LEVEL_0; |
| 249 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 250 | ALOGI("Initializing Qualcomm Hardware Composer"); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 251 | ALOGI("MDP version: %d", ctx->mMDP.version); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | void closeContext(hwc_context_t *ctx) |
| 255 | { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 256 | if(ctx->mOverlay) { |
| 257 | delete ctx->mOverlay; |
| 258 | ctx->mOverlay = NULL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 259 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 260 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 261 | if(ctx->mRotMgr) { |
| 262 | delete ctx->mRotMgr; |
| 263 | ctx->mRotMgr = NULL; |
| 264 | } |
| 265 | |
Amara Venkata Mastan Manoj Kumar | 7fb1327 | 2013-07-01 13:59:34 -0700 | [diff] [blame] | 266 | for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 267 | if(ctx->mCopyBit[i]) { |
| 268 | delete ctx->mCopyBit[i]; |
| 269 | ctx->mCopyBit[i] = NULL; |
| 270 | } |
| 271 | } |
| 272 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 273 | if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 274 | close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd); |
| 275 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 276 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 277 | |
| 278 | if(ctx->mExtDisplay) { |
| 279 | delete ctx->mExtDisplay; |
| 280 | ctx->mExtDisplay = NULL; |
| 281 | } |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 282 | |
Naseer Ahmed | 58780b9 | 2013-07-29 17:41:40 -0400 | [diff] [blame] | 283 | #ifdef VPU_TARGET |
| 284 | if(ctx->mVPUClient) { |
| 285 | delete ctx->mVPUClient; |
| 286 | } |
| 287 | #endif |
| 288 | |
Amara Venkata Mastan Manoj Kumar | 7fb1327 | 2013-07-01 13:59:34 -0700 | [diff] [blame] | 289 | for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 290 | if(ctx->mFBUpdate[i]) { |
| 291 | delete ctx->mFBUpdate[i]; |
| 292 | ctx->mFBUpdate[i] = NULL; |
| 293 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 294 | if(ctx->mMDPComp[i]) { |
| 295 | delete ctx->mMDPComp[i]; |
| 296 | ctx->mMDPComp[i] = NULL; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 297 | } |
Ramkumar Radhakrishnan | d224a1a | 2013-04-05 17:46:55 -0700 | [diff] [blame] | 298 | if(ctx->mHwcDebug[i]) { |
| 299 | delete ctx->mHwcDebug[i]; |
| 300 | ctx->mHwcDebug[i] = NULL; |
| 301 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 302 | if(ctx->mLayerRotMap[i]) { |
| 303 | delete ctx->mLayerRotMap[i]; |
| 304 | ctx->mLayerRotMap[i] = NULL; |
| 305 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 306 | } |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 307 | if(ctx->mAD) { |
| 308 | delete ctx->mAD; |
| 309 | ctx->mAD = NULL; |
| 310 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 311 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 312 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 313 | } |
| 314 | |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 315 | |
| 316 | void dumpsys_log(android::String8& buf, const char* fmt, ...) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 317 | { |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 318 | va_list varargs; |
| 319 | va_start(varargs, fmt); |
| 320 | buf.appendFormatV(fmt, varargs); |
| 321 | va_end(varargs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 324 | int getExtOrientation(hwc_context_t* ctx) { |
| 325 | int extOrient = ctx->mExtOrientation; |
| 326 | if(ctx->mBufferMirrorMode) |
| 327 | extOrient = getMirrorModeOrientation(ctx); |
| 328 | return extOrient; |
| 329 | } |
| 330 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 331 | /* Calculates the destination position based on the action safe rectangle */ |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 332 | void getActionSafePosition(hwc_context_t *ctx, int dpy, hwc_rect_t& rect) { |
| 333 | // Position |
| 334 | int x = rect.left, y = rect.top; |
| 335 | int w = rect.right - rect.left; |
| 336 | int h = rect.bottom - rect.top; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 337 | |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 338 | if(!ctx->dpyAttr[dpy].mActionSafePresent) |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 339 | return; |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 340 | // Read action safe properties |
| 341 | int asWidthRatio = ctx->dpyAttr[dpy].mAsWidthRatio; |
| 342 | int asHeightRatio = ctx->dpyAttr[dpy].mAsHeightRatio; |
Arun Kumar K.R | 82f1d28 | 2013-05-17 15:37:31 -0700 | [diff] [blame] | 343 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 344 | float wRatio = 1.0; |
| 345 | float hRatio = 1.0; |
| 346 | float xRatio = 1.0; |
| 347 | float yRatio = 1.0; |
| 348 | |
Arpita Banerjee | b28b309 | 2013-12-06 20:14:23 -0800 | [diff] [blame] | 349 | int fbWidth = ctx->dpyAttr[dpy].xres; |
| 350 | int fbHeight = ctx->dpyAttr[dpy].yres; |
Arun Kumar KR | 7b7f401 | 2013-10-29 11:53:11 -0700 | [diff] [blame] | 351 | if(ctx->dpyAttr[dpy].mDownScaleMode) { |
| 352 | // if downscale Mode is enabled for external, need to query |
| 353 | // the actual width and height, as that is the physical w & h |
Arpita Banerjee | b28b309 | 2013-12-06 20:14:23 -0800 | [diff] [blame] | 354 | ctx->mExtDisplay->getAttributes(fbWidth, fbHeight); |
Arun Kumar KR | 7b7f401 | 2013-10-29 11:53:11 -0700 | [diff] [blame] | 355 | } |
| 356 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 357 | |
Arun Kumar K.R | 82f1d28 | 2013-05-17 15:37:31 -0700 | [diff] [blame] | 358 | // Since external is rotated 90, need to swap width/height |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 359 | int extOrient = getExtOrientation(ctx); |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 360 | |
| 361 | if(extOrient & HWC_TRANSFORM_ROT_90) |
Arun Kumar K.R | 82f1d28 | 2013-05-17 15:37:31 -0700 | [diff] [blame] | 362 | swap(fbWidth, fbHeight); |
| 363 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 364 | float asX = 0; |
| 365 | float asY = 0; |
| 366 | float asW = fbWidth; |
Arpita Banerjee | b28b309 | 2013-12-06 20:14:23 -0800 | [diff] [blame] | 367 | float asH = fbHeight; |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 368 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 369 | // based on the action safe ratio, get the Action safe rectangle |
| 370 | asW = fbWidth * (1.0f - asWidthRatio / 100.0f); |
| 371 | asH = fbHeight * (1.0f - asHeightRatio / 100.0f); |
| 372 | asX = (fbWidth - asW) / 2; |
| 373 | asY = (fbHeight - asH) / 2; |
| 374 | |
| 375 | // calculate the position ratio |
| 376 | xRatio = (float)x/fbWidth; |
| 377 | yRatio = (float)y/fbHeight; |
| 378 | wRatio = (float)w/fbWidth; |
| 379 | hRatio = (float)h/fbHeight; |
| 380 | |
| 381 | //Calculate the position... |
| 382 | x = (xRatio * asW) + asX; |
| 383 | y = (yRatio * asH) + asY; |
| 384 | w = (wRatio * asW); |
| 385 | h = (hRatio * asH); |
| 386 | |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 387 | // Convert it back to hwc_rect_t |
| 388 | rect.left = x; |
| 389 | rect.top = y; |
| 390 | rect.right = w + rect.left; |
| 391 | rect.bottom = h + rect.top; |
| 392 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 393 | return; |
| 394 | } |
| 395 | |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 396 | // This function gets the destination position for Seconday display |
| 397 | // based on the position and aspect ratio with orientation |
| 398 | void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation, |
| 399 | hwc_rect_t& inRect, hwc_rect_t& outRect) { |
| 400 | // Physical display resolution |
| 401 | float fbWidth = ctx->dpyAttr[dpy].xres; |
| 402 | float fbHeight = ctx->dpyAttr[dpy].yres; |
| 403 | //display position(x,y,w,h) in correct aspectratio after rotation |
| 404 | int xPos = 0; |
| 405 | int yPos = 0; |
| 406 | float width = fbWidth; |
| 407 | float height = fbHeight; |
| 408 | // Width/Height used for calculation, after rotation |
| 409 | float actualWidth = fbWidth; |
| 410 | float actualHeight = fbHeight; |
| 411 | |
| 412 | float wRatio = 1.0; |
| 413 | float hRatio = 1.0; |
| 414 | float xRatio = 1.0; |
| 415 | float yRatio = 1.0; |
| 416 | hwc_rect_t rect = {0, 0, (int)fbWidth, (int)fbHeight}; |
| 417 | |
| 418 | Dim inPos(inRect.left, inRect.top, inRect.right - inRect.left, |
| 419 | inRect.bottom - inRect.top); |
| 420 | Dim outPos(outRect.left, outRect.top, outRect.right - outRect.left, |
| 421 | outRect.bottom - outRect.top); |
| 422 | |
| 423 | Whf whf(fbWidth, fbHeight, 0); |
| 424 | eTransform extorient = static_cast<eTransform>(extOrientation); |
| 425 | // To calculate the destination co-ordinates in the new orientation |
| 426 | preRotateSource(extorient, whf, inPos); |
| 427 | |
| 428 | if(extOrientation & HAL_TRANSFORM_ROT_90) { |
| 429 | // Swap width/height for input position |
| 430 | swapWidthHeight(actualWidth, actualHeight); |
| 431 | getAspectRatioPosition(fbWidth, fbHeight, (int)actualWidth, |
| 432 | (int)actualHeight, rect); |
| 433 | xPos = rect.left; |
| 434 | yPos = rect.top; |
| 435 | width = rect.right - rect.left; |
| 436 | height = rect.bottom - rect.top; |
| 437 | } |
Ramkumar Radhakrishnan | 2d41c76 | 2014-03-24 14:33:17 -0700 | [diff] [blame] | 438 | xRatio = inPos.x/actualWidth; |
| 439 | yRatio = inPos.y/actualHeight; |
| 440 | wRatio = inPos.w/actualWidth; |
| 441 | hRatio = inPos.h/actualHeight; |
Ramkumar Radhakrishnan | debfc5a | 2013-12-04 15:15:42 -0800 | [diff] [blame] | 442 | |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 443 | |
| 444 | //Calculate the position... |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 445 | outPos.x = (xRatio * width) + xPos; |
| 446 | outPos.y = (yRatio * height) + yPos; |
| 447 | outPos.w = wRatio * width; |
| 448 | outPos.h = hRatio * height; |
| 449 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio Position: x = %d," |
| 450 | "y = %d w = %d h = %d", __FUNCTION__, outPos.x, outPos.y, |
| 451 | outPos.w, outPos.h); |
| 452 | |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 453 | // For sidesync, the dest fb will be in portrait orientation, and the crop |
| 454 | // will be updated to avoid the black side bands, and it will be upscaled |
| 455 | // to fit the dest RB, so recalculate |
| 456 | // the position based on the new width and height |
| 457 | if ((extOrientation & HWC_TRANSFORM_ROT_90) && |
| 458 | isOrientationPortrait(ctx)) { |
Ramkumar Radhakrishnan | 56db0cc | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 459 | hwc_rect_t r = {0, 0, 0, 0}; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 460 | //Calculate the position |
| 461 | xRatio = (outPos.x - xPos)/width; |
| 462 | // GetaspectRatio -- tricky to get the correct aspect ratio |
| 463 | // But we need to do this. |
| 464 | getAspectRatioPosition(width, height, width, height, r); |
| 465 | xPos = r.left; |
| 466 | yPos = r.top; |
| 467 | float tempWidth = r.right - r.left; |
| 468 | float tempHeight = r.bottom - r.top; |
| 469 | yRatio = yPos/height; |
| 470 | wRatio = outPos.w/width; |
| 471 | hRatio = tempHeight/height; |
| 472 | |
| 473 | //Map the coordinates back to Framebuffer domain |
| 474 | outPos.x = (xRatio * fbWidth); |
| 475 | outPos.y = (yRatio * fbHeight); |
| 476 | outPos.w = wRatio * fbWidth; |
| 477 | outPos.h = hRatio * fbHeight; |
| 478 | |
| 479 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: Calculated AspectRatio for device in" |
| 480 | "portrait: x = %d,y = %d w = %d h = %d", __FUNCTION__, |
| 481 | outPos.x, outPos.y, |
| 482 | outPos.w, outPos.h); |
| 483 | } |
| 484 | if(ctx->dpyAttr[dpy].mDownScaleMode) { |
| 485 | int extW, extH; |
| 486 | if(dpy == HWC_DISPLAY_EXTERNAL) |
| 487 | ctx->mExtDisplay->getAttributes(extW, extH); |
| 488 | else |
| 489 | ctx->mVirtualDisplay->getAttributes(extW, extH); |
| 490 | fbWidth = ctx->dpyAttr[dpy].xres; |
| 491 | fbHeight = ctx->dpyAttr[dpy].yres; |
| 492 | //Calculate the position... |
| 493 | xRatio = outPos.x/fbWidth; |
| 494 | yRatio = outPos.y/fbHeight; |
| 495 | wRatio = outPos.w/fbWidth; |
| 496 | hRatio = outPos.h/fbHeight; |
| 497 | |
| 498 | outPos.x = xRatio * extW; |
| 499 | outPos.y = yRatio * extH; |
| 500 | outPos.w = wRatio * extW; |
| 501 | outPos.h = hRatio * extH; |
| 502 | } |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 503 | // Convert Dim to hwc_rect_t |
| 504 | outRect.left = outPos.x; |
| 505 | outRect.top = outPos.y; |
| 506 | outRect.right = outPos.x + outPos.w; |
| 507 | outRect.bottom = outPos.y + outPos.h; |
| 508 | |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | bool isPrimaryPortrait(hwc_context_t *ctx) { |
| 513 | int fbWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres; |
| 514 | int fbHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres; |
| 515 | if(fbWidth < fbHeight) { |
| 516 | return true; |
| 517 | } |
| 518 | return false; |
| 519 | } |
| 520 | |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 521 | bool isOrientationPortrait(hwc_context_t *ctx) { |
| 522 | if(isPrimaryPortrait(ctx)) { |
| 523 | return !(ctx->deviceOrientation & 0x1); |
| 524 | } |
| 525 | return (ctx->deviceOrientation & 0x1); |
| 526 | } |
| 527 | |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 528 | void calcExtDisplayPosition(hwc_context_t *ctx, |
| 529 | private_handle_t *hnd, |
| 530 | int dpy, |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 531 | hwc_rect_t& sourceCrop, |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 532 | hwc_rect_t& displayFrame, |
| 533 | int& transform, |
| 534 | ovutils::eTransform& orient) { |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 535 | // Swap width and height when there is a 90deg transform |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 536 | int extOrient = getExtOrientation(ctx); |
| 537 | if(dpy && !qdutils::MDPVersion::getInstance().is8x26()) { |
| 538 | if(!isYuvBuffer(hnd)) { |
| 539 | if(extOrient & HWC_TRANSFORM_ROT_90) { |
| 540 | int dstWidth = ctx->dpyAttr[dpy].xres; |
| 541 | int dstHeight = ctx->dpyAttr[dpy].yres;; |
| 542 | int srcWidth = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres; |
| 543 | int srcHeight = ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres; |
| 544 | if(!isPrimaryPortrait(ctx)) { |
| 545 | swap(srcWidth, srcHeight); |
| 546 | } // Get Aspect Ratio for external |
| 547 | getAspectRatioPosition(dstWidth, dstHeight, srcWidth, |
| 548 | srcHeight, displayFrame); |
| 549 | // Crop - this is needed, because for sidesync, the dest fb will |
| 550 | // be in portrait orientation, so update the crop to not show the |
| 551 | // black side bands. |
| 552 | if (isOrientationPortrait(ctx)) { |
| 553 | sourceCrop = displayFrame; |
| 554 | displayFrame.left = 0; |
| 555 | displayFrame.top = 0; |
| 556 | displayFrame.right = dstWidth; |
| 557 | displayFrame.bottom = dstHeight; |
| 558 | } |
| 559 | } |
| 560 | if(ctx->dpyAttr[dpy].mDownScaleMode) { |
| 561 | int extW, extH; |
| 562 | // if downscale is enabled, map the co-ordinates to new |
| 563 | // domain(downscaled) |
| 564 | float fbWidth = ctx->dpyAttr[dpy].xres; |
| 565 | float fbHeight = ctx->dpyAttr[dpy].yres; |
| 566 | // query MDP configured attributes |
| 567 | if(dpy == HWC_DISPLAY_EXTERNAL) |
| 568 | ctx->mExtDisplay->getAttributes(extW, extH); |
| 569 | else |
| 570 | ctx->mVirtualDisplay->getAttributes(extW, extH); |
| 571 | //Calculate the ratio... |
| 572 | float wRatio = ((float)extW)/fbWidth; |
| 573 | float hRatio = ((float)extH)/fbHeight; |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 574 | |
Ramkumar Radhakrishnan | 66f856c | 2013-08-21 16:09:47 -0700 | [diff] [blame] | 575 | //convert Dim to hwc_rect_t |
| 576 | displayFrame.left *= wRatio; |
| 577 | displayFrame.top *= hRatio; |
| 578 | displayFrame.right *= wRatio; |
| 579 | displayFrame.bottom *= hRatio; |
| 580 | } |
| 581 | }else { |
| 582 | if(extOrient || ctx->dpyAttr[dpy].mDownScaleMode) { |
| 583 | getAspectRatioPosition(ctx, dpy, extOrient, |
| 584 | displayFrame, displayFrame); |
| 585 | } |
| 586 | } |
| 587 | // If there is a external orientation set, use that |
| 588 | if(extOrient) { |
| 589 | transform = extOrient; |
| 590 | orient = static_cast<ovutils::eTransform >(extOrient); |
| 591 | } |
| 592 | // Calculate the actionsafe dimensions for External(dpy = 1 or 2) |
| 593 | getActionSafePosition(ctx, dpy, displayFrame); |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 594 | } |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 595 | } |
Amara Venkata Mastan Manoj Kumar | 376d8a8 | 2013-03-13 19:18:47 -0700 | [diff] [blame] | 596 | |
Arun Kumar K.R | fb5bfa6 | 2013-07-25 03:10:51 -0700 | [diff] [blame] | 597 | /* Returns the orientation which needs to be set on External for |
| 598 | * SideSync/Buffer Mirrormode |
| 599 | */ |
| 600 | int getMirrorModeOrientation(hwc_context_t *ctx) { |
| 601 | int extOrientation = 0; |
| 602 | int deviceOrientation = ctx->deviceOrientation; |
| 603 | if(!isPrimaryPortrait(ctx)) |
| 604 | deviceOrientation = (deviceOrientation + 1) % 4; |
| 605 | if (deviceOrientation == 0) |
| 606 | extOrientation = HWC_TRANSFORM_ROT_270; |
| 607 | else if (deviceOrientation == 1)//90 |
| 608 | extOrientation = 0; |
| 609 | else if (deviceOrientation == 2)//180 |
| 610 | extOrientation = HWC_TRANSFORM_ROT_90; |
| 611 | else if (deviceOrientation == 3)//270 |
| 612 | extOrientation = HWC_TRANSFORM_FLIP_V | HWC_TRANSFORM_FLIP_H; |
| 613 | |
| 614 | return extOrientation; |
Arun Kumar K.R | 5898c65 | 2013-07-17 14:20:32 -0700 | [diff] [blame] | 615 | } |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 616 | |
Raj kamal | 9af062e | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 617 | /* Get External State names */ |
| 618 | const char* getExternalDisplayState(uint32_t external_state) { |
| 619 | static const char* externalStates[EXTERNAL_MAXSTATES] = {0}; |
| 620 | externalStates[EXTERNAL_OFFLINE] = STR(EXTERNAL_OFFLINE); |
| 621 | externalStates[EXTERNAL_ONLINE] = STR(EXTERNAL_ONLINE); |
| 622 | externalStates[EXTERNAL_PAUSE] = STR(EXTERNAL_PAUSE); |
| 623 | externalStates[EXTERNAL_RESUME] = STR(EXTERNAL_RESUME); |
| 624 | |
| 625 | if(external_state >= EXTERNAL_MAXSTATES) { |
| 626 | return "EXTERNAL_INVALID"; |
| 627 | } |
| 628 | |
| 629 | return externalStates[external_state]; |
| 630 | } |
| 631 | |
Prabhanjan Kandula | 21918db | 2013-11-26 15:51:58 +0530 | [diff] [blame] | 632 | bool isDownscaleRequired(hwc_layer_1_t const* layer) { |
| 633 | hwc_rect_t displayFrame = layer->displayFrame; |
| 634 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
| 635 | int dst_w, dst_h, src_w, src_h; |
| 636 | dst_w = displayFrame.right - displayFrame.left; |
| 637 | dst_h = displayFrame.bottom - displayFrame.top; |
| 638 | src_w = sourceCrop.right - sourceCrop.left; |
| 639 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 640 | |
| 641 | if(((src_w > dst_w) || (src_h > dst_h))) |
| 642 | return true; |
| 643 | |
| 644 | return false; |
| 645 | } |
| 646 | bool needsScaling(hwc_layer_1_t const* layer) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 647 | int dst_w, dst_h, src_w, src_h; |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 648 | hwc_rect_t displayFrame = layer->displayFrame; |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 649 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 650 | |
| 651 | dst_w = displayFrame.right - displayFrame.left; |
| 652 | dst_h = displayFrame.bottom - displayFrame.top; |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 653 | src_w = sourceCrop.right - sourceCrop.left; |
| 654 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 655 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 656 | if(((src_w != dst_w) || (src_h != dst_h))) |
| 657 | return true; |
| 658 | |
| 659 | return false; |
| 660 | } |
| 661 | |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 662 | // Checks if layer needs scaling with split |
| 663 | bool needsScalingWithSplit(hwc_context_t* ctx, hwc_layer_1_t const* layer, |
| 664 | const int& dpy) { |
| 665 | |
| 666 | int src_width_l, src_height_l; |
| 667 | int src_width_r, src_height_r; |
| 668 | int dst_width_l, dst_height_l; |
| 669 | int dst_width_r, dst_height_r; |
| 670 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 671 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 672 | hwc_rect_t cropL, dstL, cropR, dstR; |
| 673 | const int lSplit = getLeftSplit(ctx, dpy); |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 674 | hwc_rect_t sourceCrop = integerizeSourceCrop(layer->sourceCropf); |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 675 | hwc_rect_t displayFrame = layer->displayFrame; |
| 676 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 677 | |
| 678 | cropL = sourceCrop; |
| 679 | dstL = displayFrame; |
| 680 | hwc_rect_t scissorL = { 0, 0, lSplit, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 681 | scissorL = getIntersection(ctx->mViewFrame[dpy], scissorL); |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 682 | qhwc::calculate_crop_rects(cropL, dstL, scissorL, 0); |
| 683 | |
| 684 | cropR = sourceCrop; |
| 685 | dstR = displayFrame; |
| 686 | hwc_rect_t scissorR = { lSplit, 0, hw_w, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 687 | scissorR = getIntersection(ctx->mViewFrame[dpy], scissorR); |
Sushil Chauhan | 15a2ea6 | 2013-09-04 18:28:36 -0700 | [diff] [blame] | 688 | qhwc::calculate_crop_rects(cropR, dstR, scissorR, 0); |
| 689 | |
| 690 | // Sanitize Crop to stitch |
| 691 | sanitizeSourceCrop(cropL, cropR, hnd); |
| 692 | |
| 693 | // Calculate the left dst |
| 694 | dst_width_l = dstL.right - dstL.left; |
| 695 | dst_height_l = dstL.bottom - dstL.top; |
| 696 | src_width_l = cropL.right - cropL.left; |
| 697 | src_height_l = cropL.bottom - cropL.top; |
| 698 | |
| 699 | // check if there is any scaling on the left |
| 700 | if(((src_width_l != dst_width_l) || (src_height_l != dst_height_l))) |
| 701 | return true; |
| 702 | |
| 703 | // Calculate the right dst |
| 704 | dst_width_r = dstR.right - dstR.left; |
| 705 | dst_height_r = dstR.bottom - dstR.top; |
| 706 | src_width_r = cropR.right - cropR.left; |
| 707 | src_height_r = cropR.bottom - cropR.top; |
| 708 | |
| 709 | // check if there is any scaling on the right |
| 710 | if(((src_width_r != dst_width_r) || (src_height_r != dst_height_r))) |
| 711 | return true; |
| 712 | |
| 713 | return false; |
| 714 | } |
| 715 | |
Prabhanjan Kandula | 21918db | 2013-11-26 15:51:58 +0530 | [diff] [blame] | 716 | bool isAlphaScaled(hwc_layer_1_t const* layer) { |
| 717 | if(needsScaling(layer) && isAlphaPresent(layer)) { |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 718 | return true; |
| 719 | } |
| 720 | return false; |
| 721 | } |
| 722 | |
| 723 | bool isAlphaPresent(hwc_layer_1_t const* layer) { |
| 724 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | 7a4287c | 2013-03-26 18:11:41 -0400 | [diff] [blame] | 725 | if(hnd) { |
| 726 | int format = hnd->format; |
| 727 | switch(format) { |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 728 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 729 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 730 | // In any more formats with Alpha go here.. |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 731 | return true; |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 732 | default : return false; |
Naseer Ahmed | 7a4287c | 2013-03-26 18:11:41 -0400 | [diff] [blame] | 733 | } |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 734 | } |
| 735 | return false; |
| 736 | } |
| 737 | |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 738 | static void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform, |
| 739 | hwc_rect_t& crop, hwc_rect_t& dst) { |
| 740 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 741 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 742 | if(dst.left < 0 || dst.top < 0 || |
| 743 | dst.right > hw_w || dst.bottom > hw_h) { |
| 744 | hwc_rect_t scissor = {0, 0, hw_w, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 745 | scissor = getIntersection(ctx->mViewFrame[dpy], scissor); |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 746 | qhwc::calculate_crop_rects(crop, dst, scissor, transform); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | static void trimList(hwc_context_t *ctx, hwc_display_contents_1_t *list, |
| 751 | const int& dpy) { |
| 752 | for(uint32_t i = 0; i < list->numHwLayers - 1; i++) { |
| 753 | hwc_layer_1_t *layer = &list->hwLayers[i]; |
| 754 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Sushil Chauhan | d8ef93f | 2014-03-20 11:08:41 -0700 | [diff] [blame] | 755 | int transform = (list->hwLayers[i].flags & HWC_COLOR_FILL) ? 0 : |
| 756 | list->hwLayers[i].transform; |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 757 | trimLayer(ctx, dpy, |
Sushil Chauhan | d8ef93f | 2014-03-20 11:08:41 -0700 | [diff] [blame] | 758 | transform, |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 759 | (hwc_rect_t&)crop, |
| 760 | (hwc_rect_t&)list->hwLayers[i].displayFrame); |
| 761 | layer->sourceCropf.left = crop.left; |
| 762 | layer->sourceCropf.right = crop.right; |
| 763 | layer->sourceCropf.top = crop.top; |
| 764 | layer->sourceCropf.bottom = crop.bottom; |
| 765 | } |
| 766 | } |
| 767 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 768 | void setListStats(hwc_context_t *ctx, |
Saurabh Shah | d9ff30b | 2013-10-03 16:37:06 -0700 | [diff] [blame] | 769 | hwc_display_contents_1_t *list, int dpy) { |
Saurabh Shah | d4e6585 | 2013-06-17 11:33:53 -0700 | [diff] [blame] | 770 | const int prevYuvCount = ctx->listStats[dpy].yuvCount; |
| 771 | memset(&ctx->listStats[dpy], 0, sizeof(ListStats)); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 772 | ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1; |
| 773 | ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 774 | ctx->listStats[dpy].skipCount = 0; |
Sravan Kumar D.V.N | b5ed029 | 2013-03-15 08:51:16 +0530 | [diff] [blame] | 775 | ctx->listStats[dpy].preMultipliedAlpha = false; |
Saurabh Shah | 8028e3b | 2013-10-15 12:27:59 -0700 | [diff] [blame] | 776 | ctx->listStats[dpy].isSecurePresent = false; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 777 | ctx->listStats[dpy].yuvCount = 0; |
Ping Li | 9404e2a | 2013-04-24 16:36:03 -0400 | [diff] [blame] | 778 | char property[PROPERTY_VALUE_MAX]; |
Arun Kumar K.R | a297845 | 2013-02-07 01:34:24 -0800 | [diff] [blame] | 779 | ctx->listStats[dpy].extOnlyLayerIndex = -1; |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 780 | ctx->listStats[dpy].isDisplayAnimating = false; |
Jeykumar Sankaran | 6a9bb9e | 2013-08-01 14:19:26 -0700 | [diff] [blame] | 781 | ctx->listStats[dpy].roi = ovutils::Dim(0, 0, |
| 782 | (int)ctx->dpyAttr[dpy].xres, (int)ctx->dpyAttr[dpy].yres); |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 783 | ctx->listStats[dpy].secureUI = false; |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 784 | ctx->listStats[dpy].yuv4k2kCount = 0; |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 785 | ctx->dpyAttr[dpy].mActionSafePresent = isActionSafePresent(ctx, dpy); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 786 | |
Sushil Chauhan | 5c69879 | 2014-04-09 09:15:37 -0700 | [diff] [blame] | 787 | trimList(ctx, list, dpy); |
| 788 | optimizeLayerRects(ctx, list, dpy); |
| 789 | |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 790 | 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] | 791 | hwc_layer_1_t const* layer = &list->hwLayers[i]; |
| 792 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 793 | |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 794 | #ifdef QCOM_BSP |
| 795 | if (layer->flags & HWC_SCREENSHOT_ANIMATOR_LAYER) { |
| 796 | ctx->listStats[dpy].isDisplayAnimating = true; |
| 797 | } |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 798 | if(isSecureDisplayBuffer(hnd)) { |
| 799 | ctx->listStats[dpy].secureUI = true; |
| 800 | } |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 801 | #endif |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 802 | // continue if number of app layers exceeds MAX_NUM_APP_LAYERS |
| 803 | if(ctx->listStats[dpy].numAppLayers > MAX_NUM_APP_LAYERS) |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 804 | continue; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 805 | |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 806 | //reset yuv indices |
| 807 | ctx->listStats[dpy].yuvIndices[i] = -1; |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 808 | ctx->listStats[dpy].yuv4k2kIndices[i] = -1; |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 809 | |
Saurabh Shah | 8028e3b | 2013-10-15 12:27:59 -0700 | [diff] [blame] | 810 | if (isSecureBuffer(hnd)) { |
| 811 | ctx->listStats[dpy].isSecurePresent = true; |
| 812 | } |
| 813 | |
Ramkumar Radhakrishnan | 26bdee9 | 2013-06-20 16:56:56 -0700 | [diff] [blame] | 814 | if (isSkipLayer(&list->hwLayers[i])) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 815 | ctx->listStats[dpy].skipCount++; |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | if (UNLIKELY(isYuvBuffer(hnd))) { |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 819 | int& yuvCount = ctx->listStats[dpy].yuvCount; |
| 820 | ctx->listStats[dpy].yuvIndices[yuvCount] = i; |
| 821 | yuvCount++; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 822 | |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 823 | if(UNLIKELY(is4kx2kYuvBuffer(hnd))){ |
| 824 | int& yuv4k2kCount = ctx->listStats[dpy].yuv4k2kCount; |
| 825 | ctx->listStats[dpy].yuv4k2kIndices[yuv4k2kCount] = i; |
| 826 | yuv4k2kCount++; |
| 827 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 828 | } |
Sravan Kumar D.V.N | b5ed029 | 2013-03-15 08:51:16 +0530 | [diff] [blame] | 829 | if(layer->blending == HWC_BLENDING_PREMULT) |
| 830 | ctx->listStats[dpy].preMultipliedAlpha = true; |
Jeykumar Sankaran | 7535aba | 2013-02-04 11:03:09 -0800 | [diff] [blame] | 831 | |
Arun Kumar K.R | a297845 | 2013-02-07 01:34:24 -0800 | [diff] [blame] | 832 | |
| 833 | if(UNLIKELY(isExtOnly(hnd))){ |
| 834 | ctx->listStats[dpy].extOnlyLayerIndex = i; |
| 835 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 836 | } |
Ping Li | 9404e2a | 2013-04-24 16:36:03 -0400 | [diff] [blame] | 837 | if(ctx->listStats[dpy].yuvCount > 0) { |
| 838 | if (property_get("hw.cabl.yuv", property, NULL) > 0) { |
| 839 | if (atoi(property) != 1) { |
| 840 | property_set("hw.cabl.yuv", "1"); |
| 841 | } |
| 842 | } |
| 843 | } else { |
| 844 | if (property_get("hw.cabl.yuv", property, NULL) > 0) { |
| 845 | if (atoi(property) != 0) { |
| 846 | property_set("hw.cabl.yuv", "0"); |
| 847 | } |
| 848 | } |
| 849 | } |
Saurabh Shah | d4e6585 | 2013-06-17 11:33:53 -0700 | [diff] [blame] | 850 | |
| 851 | //The marking of video begin/end is useful on some targets where we need |
| 852 | //to have a padding round to be able to shift pipes across mixers. |
| 853 | if(prevYuvCount != ctx->listStats[dpy].yuvCount) { |
| 854 | ctx->mVideoTransFlag = true; |
| 855 | } |
Raj Kamal | fc5b922 | 2014-02-07 16:15:17 +0530 | [diff] [blame] | 856 | |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 857 | if(dpy == HWC_DISPLAY_PRIMARY) { |
| 858 | ctx->mAD->markDoable(ctx, list); |
| 859 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 862 | |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 863 | static void calc_cut(double& leftCutRatio, double& topCutRatio, |
| 864 | double& rightCutRatio, double& bottomCutRatio, int orient) { |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 865 | if(orient & HAL_TRANSFORM_FLIP_H) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 866 | swap(leftCutRatio, rightCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 867 | } |
| 868 | if(orient & HAL_TRANSFORM_FLIP_V) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 869 | swap(topCutRatio, bottomCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 870 | } |
| 871 | if(orient & HAL_TRANSFORM_ROT_90) { |
| 872 | //Anti clock swapping |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 873 | double tmpCutRatio = leftCutRatio; |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 874 | leftCutRatio = topCutRatio; |
| 875 | topCutRatio = rightCutRatio; |
| 876 | rightCutRatio = bottomCutRatio; |
| 877 | bottomCutRatio = tmpCutRatio; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 881 | bool isSecuring(hwc_context_t* ctx, hwc_layer_1_t const* layer) { |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 882 | if((ctx->mMDP.version < qdutils::MDSS_V5) && |
| 883 | (ctx->mMDP.version > qdutils::MDP_V3_0) && |
| 884 | ctx->mSecuring) { |
| 885 | return true; |
| 886 | } |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 887 | if (isSecureModePolicy(ctx->mMDP.version)) { |
| 888 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 889 | if(ctx->mSecureMode) { |
| 890 | if (! isSecureBuffer(hnd)) { |
| 891 | ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning ON ...", |
| 892 | __FUNCTION__); |
| 893 | return true; |
| 894 | } |
| 895 | } else { |
| 896 | if (isSecureBuffer(hnd)) { |
| 897 | ALOGD_IF(HWC_UTILS_DEBUG,"%s:Securing Turning OFF ...", |
| 898 | __FUNCTION__); |
| 899 | return true; |
| 900 | } |
| 901 | } |
| 902 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 903 | return false; |
| 904 | } |
| 905 | |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 906 | bool isSecureModePolicy(int mdpVersion) { |
| 907 | if (mdpVersion < qdutils::MDSS_V5) |
| 908 | return true; |
| 909 | else |
| 910 | return false; |
| 911 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 912 | |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 913 | // returns true if Action safe dimensions are set and target supports Actionsafe |
| 914 | bool isActionSafePresent(hwc_context_t *ctx, int dpy) { |
| 915 | // if external supports underscan, do nothing |
| 916 | // it will be taken care in the driver |
Ramkumar Radhakrishnan | 9921b4c | 2014-03-03 14:46:21 -0800 | [diff] [blame] | 917 | // Disable Action safe for 8974 due to HW limitation for downscaling |
| 918 | // layers with overlapped region |
| 919 | // Disable Actionsafe for non HDMI displays. |
| 920 | if(!(dpy == HWC_DISPLAY_EXTERNAL) || |
| 921 | qdutils::MDPVersion::getInstance().is8x74v2() || |
| 922 | ctx->mExtDisplay->isCEUnderscanSupported()) { |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 923 | return false; |
Ramkumar Radhakrishnan | 9921b4c | 2014-03-03 14:46:21 -0800 | [diff] [blame] | 924 | } |
Ramkumar Radhakrishnan | 4af1ef0 | 2013-12-12 11:53:08 -0800 | [diff] [blame] | 925 | |
| 926 | char value[PROPERTY_VALUE_MAX]; |
| 927 | // Read action safe properties |
| 928 | property_get("persist.sys.actionsafe.width", value, "0"); |
| 929 | ctx->dpyAttr[dpy].mAsWidthRatio = atoi(value); |
| 930 | property_get("persist.sys.actionsafe.height", value, "0"); |
| 931 | ctx->dpyAttr[dpy].mAsHeightRatio = atoi(value); |
| 932 | |
| 933 | if(!ctx->dpyAttr[dpy].mAsWidthRatio && !ctx->dpyAttr[dpy].mAsHeightRatio) { |
| 934 | //No action safe ratio set, return |
| 935 | return false; |
| 936 | } |
| 937 | return true; |
| 938 | } |
| 939 | |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 940 | int getBlending(int blending) { |
| 941 | switch(blending) { |
| 942 | case HWC_BLENDING_NONE: |
| 943 | return overlay::utils::OVERLAY_BLENDING_OPAQUE; |
| 944 | case HWC_BLENDING_PREMULT: |
| 945 | return overlay::utils::OVERLAY_BLENDING_PREMULT; |
| 946 | case HWC_BLENDING_COVERAGE : |
| 947 | default: |
| 948 | return overlay::utils::OVERLAY_BLENDING_COVERAGE; |
| 949 | } |
| 950 | } |
| 951 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 952 | //Crops source buffer against destination and FB boundaries |
| 953 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 954 | const hwc_rect_t& scissor, int orient) { |
| 955 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 956 | int& crop_l = crop.left; |
| 957 | int& crop_t = crop.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 958 | int& crop_r = crop.right; |
| 959 | int& crop_b = crop.bottom; |
| 960 | int crop_w = crop.right - crop.left; |
| 961 | int crop_h = crop.bottom - crop.top; |
| 962 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 963 | int& dst_l = dst.left; |
| 964 | int& dst_t = dst.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 965 | int& dst_r = dst.right; |
| 966 | int& dst_b = dst.bottom; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 967 | int dst_w = abs(dst.right - dst.left); |
| 968 | int dst_h = abs(dst.bottom - dst.top); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 969 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 970 | const int& sci_l = scissor.left; |
| 971 | const int& sci_t = scissor.top; |
| 972 | const int& sci_r = scissor.right; |
| 973 | const int& sci_b = scissor.bottom; |
| 974 | int sci_w = abs(sci_r - sci_l); |
| 975 | int sci_h = abs(sci_b - sci_t); |
| 976 | |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 977 | double leftCutRatio = 0.0, rightCutRatio = 0.0, topCutRatio = 0.0, |
| 978 | bottomCutRatio = 0.0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 979 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 980 | if(dst_l < sci_l) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 981 | leftCutRatio = (double)(sci_l - dst_l) / (double)dst_w; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 982 | dst_l = sci_l; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 983 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 984 | |
| 985 | if(dst_r > sci_r) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 986 | rightCutRatio = (double)(dst_r - sci_r) / (double)dst_w; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 987 | dst_r = sci_r; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 988 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 989 | |
| 990 | if(dst_t < sci_t) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 991 | topCutRatio = (double)(sci_t - dst_t) / (double)dst_h; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 992 | dst_t = sci_t; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 993 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 994 | |
| 995 | if(dst_b > sci_b) { |
Saurabh Shah | 6810742 | 2013-07-09 11:12:42 -0700 | [diff] [blame] | 996 | bottomCutRatio = (double)(dst_b - sci_b) / (double)dst_h; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 997 | dst_b = sci_b; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 998 | } |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 999 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 1000 | calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient); |
Dileep Kumar Reddi | aff14c9 | 2014-03-06 11:56:10 +0530 | [diff] [blame] | 1001 | crop_l += (int)round((double)crop_w * leftCutRatio); |
| 1002 | crop_t += (int)round((double)crop_h * topCutRatio); |
| 1003 | crop_r -= (int)round((double)crop_w * rightCutRatio); |
| 1004 | crop_b -= (int)round((double)crop_h * bottomCutRatio); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1005 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 1006 | |
Prabhanjan Kandula | 9bd5f64 | 2013-09-25 17:00:36 +0530 | [diff] [blame] | 1007 | bool areLayersIntersecting(const hwc_layer_1_t* layer1, |
| 1008 | const hwc_layer_1_t* layer2) { |
| 1009 | hwc_rect_t irect = getIntersection(layer1->displayFrame, |
| 1010 | layer2->displayFrame); |
| 1011 | return isValidRect(irect); |
| 1012 | } |
| 1013 | |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1014 | bool isValidRect(const hwc_rect& rect) |
| 1015 | { |
| 1016 | return ((rect.bottom > rect.top) && (rect.right > rect.left)) ; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1017 | } |
| 1018 | |
Jeykumar Sankaran | 7889342 | 2014-05-07 16:23:14 -0700 | [diff] [blame] | 1019 | hwc_rect_t moveRect(const hwc_rect_t& rect, const int& x_off, const int& y_off) |
| 1020 | { |
| 1021 | hwc_rect_t res; |
| 1022 | |
| 1023 | if(!isValidRect(rect)) |
| 1024 | return (hwc_rect_t){0, 0, 0, 0}; |
| 1025 | |
| 1026 | res.left = rect.left + x_off; |
| 1027 | res.top = rect.top + y_off; |
| 1028 | res.right = rect.right + x_off; |
| 1029 | res.bottom = rect.bottom + y_off; |
| 1030 | |
| 1031 | return res; |
| 1032 | } |
| 1033 | |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1034 | /* computes the intersection of two rects */ |
| 1035 | hwc_rect_t getIntersection(const hwc_rect_t& rect1, const hwc_rect_t& rect2) |
| 1036 | { |
| 1037 | hwc_rect_t res; |
| 1038 | |
| 1039 | if(!isValidRect(rect1) || !isValidRect(rect2)){ |
| 1040 | return (hwc_rect_t){0, 0, 0, 0}; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | res.left = max(rect1.left, rect2.left); |
| 1045 | res.top = max(rect1.top, rect2.top); |
| 1046 | res.right = min(rect1.right, rect2.right); |
| 1047 | res.bottom = min(rect1.bottom, rect2.bottom); |
| 1048 | |
| 1049 | if(!isValidRect(res)) |
| 1050 | return (hwc_rect_t){0, 0, 0, 0}; |
| 1051 | |
| 1052 | return res; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1053 | } |
| 1054 | |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1055 | /* computes the union of two rects */ |
| 1056 | hwc_rect_t getUnion(const hwc_rect &rect1, const hwc_rect &rect2) |
| 1057 | { |
| 1058 | hwc_rect_t res; |
| 1059 | |
| 1060 | if(!isValidRect(rect1)){ |
| 1061 | return rect2; |
| 1062 | } |
| 1063 | |
| 1064 | if(!isValidRect(rect2)){ |
| 1065 | return rect1; |
| 1066 | } |
| 1067 | |
| 1068 | res.left = min(rect1.left, rect2.left); |
| 1069 | res.top = min(rect1.top, rect2.top); |
| 1070 | res.right = max(rect1.right, rect2.right); |
| 1071 | res.bottom = max(rect1.bottom, rect2.bottom); |
| 1072 | |
| 1073 | return res; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1074 | } |
| 1075 | |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1076 | /* Not a geometrical rect deduction. Deducts rect2 from rect1 only if it results |
| 1077 | * a single rect */ |
| 1078 | 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] | 1079 | |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1080 | hwc_rect_t res = rect1; |
| 1081 | |
| 1082 | if((rect1.left == rect2.left) && (rect1.right == rect2.right)) { |
| 1083 | if((rect1.top == rect2.top) && (rect2.bottom <= rect1.bottom)) |
| 1084 | res.top = rect2.bottom; |
| 1085 | else if((rect1.bottom == rect2.bottom)&& (rect2.top >= rect1.top)) |
| 1086 | res.bottom = rect2.top; |
| 1087 | } |
| 1088 | else if((rect1.top == rect2.top) && (rect1.bottom == rect2.bottom)) { |
| 1089 | if((rect1.left == rect2.left) && (rect2.right <= rect1.right)) |
| 1090 | res.left = rect2.right; |
| 1091 | else if((rect1.right == rect2.right)&& (rect2.left >= rect1.left)) |
| 1092 | res.right = rect2.left; |
| 1093 | } |
| 1094 | return res; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | void optimizeLayerRects(hwc_context_t *ctx, |
| 1098 | const hwc_display_contents_1_t *list, const int& dpy) { |
| 1099 | int i=list->numHwLayers-2; |
| 1100 | hwc_rect_t irect; |
| 1101 | while(i > 0) { |
| 1102 | |
| 1103 | //see if there is no blending required. |
| 1104 | //If it is opaque see if we can substract this region from below layers. |
| 1105 | if(list->hwLayers[i].blending == HWC_BLENDING_NONE) { |
| 1106 | int j= i-1; |
| 1107 | hwc_rect_t& topframe = |
| 1108 | (hwc_rect_t&)list->hwLayers[i].displayFrame; |
| 1109 | while(j >= 0) { |
Prabhanjan Kandula | 21918db | 2013-11-26 15:51:58 +0530 | [diff] [blame] | 1110 | if(!needsScaling(&list->hwLayers[j])) { |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1111 | hwc_layer_1_t* layer = (hwc_layer_1_t*)&list->hwLayers[j]; |
| 1112 | hwc_rect_t& bottomframe = layer->displayFrame; |
Jeykumar Sankaran | ccf281c | 2014-01-14 17:21:49 -0800 | [diff] [blame] | 1113 | hwc_rect_t bottomCrop = |
| 1114 | integerizeSourceCrop(layer->sourceCropf); |
Sushil Chauhan | d8ef93f | 2014-03-20 11:08:41 -0700 | [diff] [blame] | 1115 | int transform = (layer->flags & HWC_COLOR_FILL) ? 0 : |
| 1116 | layer->transform; |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1117 | |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1118 | hwc_rect_t irect = getIntersection(bottomframe, topframe); |
| 1119 | if(isValidRect(irect)) { |
Jeykumar Sankaran | 1b3da40 | 2013-12-04 16:22:34 -0800 | [diff] [blame] | 1120 | hwc_rect_t dest_rect; |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1121 | //if intersection is valid rect, deduct it |
Jeykumar Sankaran | 1b3da40 | 2013-12-04 16:22:34 -0800 | [diff] [blame] | 1122 | dest_rect = deductRect(bottomframe, irect); |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1123 | qhwc::calculate_crop_rects(bottomCrop, bottomframe, |
Jeykumar Sankaran | 1b3da40 | 2013-12-04 16:22:34 -0800 | [diff] [blame] | 1124 | dest_rect, transform); |
Jeykumar Sankaran | ccf281c | 2014-01-14 17:21:49 -0800 | [diff] [blame] | 1125 | //Update layer sourceCropf |
Jeykumar Sankaran | 4d76a38 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 1126 | layer->sourceCropf.left =(float)bottomCrop.left; |
| 1127 | layer->sourceCropf.top = (float)bottomCrop.top; |
| 1128 | layer->sourceCropf.right = (float)bottomCrop.right; |
| 1129 | layer->sourceCropf.bottom = (float)bottomCrop.bottom; |
| 1130 | #ifdef QCOM_BSP |
| 1131 | //Update layer dirtyRect |
| 1132 | layer->dirtyRect = getIntersection(bottomCrop, |
| 1133 | layer->dirtyRect); |
| 1134 | #endif |
Jeykumar Sankaran | 9394353 | 2013-11-08 18:05:11 -0800 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | j--; |
Prabhanjan Kandula | a5dc8e9 | 2013-09-25 15:20:33 +0530 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | i--; |
| 1141 | } |
| 1142 | } |
| 1143 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1144 | void getNonWormholeRegion(hwc_display_contents_1_t* list, |
| 1145 | hwc_rect_t& nwr) |
| 1146 | { |
| 1147 | uint32_t last = list->numHwLayers - 1; |
| 1148 | hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame; |
| 1149 | //Initiliaze nwr to first frame |
| 1150 | nwr.left = list->hwLayers[0].displayFrame.left; |
| 1151 | nwr.top = list->hwLayers[0].displayFrame.top; |
| 1152 | nwr.right = list->hwLayers[0].displayFrame.right; |
| 1153 | nwr.bottom = list->hwLayers[0].displayFrame.bottom; |
| 1154 | |
| 1155 | for (uint32_t i = 1; i < last; i++) { |
| 1156 | hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1157 | nwr = getUnion(nwr, displayFrame); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | //Intersect with the framebuffer |
Jeykumar Sankaran | 6a58579 | 2013-10-03 11:30:55 -0700 | [diff] [blame] | 1161 | nwr = getIntersection(nwr, fbDisplayFrame); |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1162 | } |
| 1163 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 1164 | bool isExternalActive(hwc_context_t* ctx) { |
| 1165 | return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive; |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 1166 | } |
| 1167 | |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1168 | void closeAcquireFds(hwc_display_contents_1_t* list) { |
| 1169 | for(uint32_t i = 0; list && i < list->numHwLayers; i++) { |
| 1170 | //Close the acquireFenceFds |
| 1171 | //HWC_FRAMEBUFFER are -1 already by SF, rest we close. |
| 1172 | if(list->hwLayers[i].acquireFenceFd >= 0) { |
| 1173 | close(list->hwLayers[i].acquireFenceFd); |
| 1174 | list->hwLayers[i].acquireFenceFd = -1; |
| 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1179 | 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] | 1180 | int fd) { |
Naseer Ahmed | 099a693 | 2013-09-09 14:25:20 -0400 | [diff] [blame] | 1181 | ATRACE_CALL(); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1182 | int ret = 0; |
Ramkumar Radhakrishnan | e661f96 | 2013-06-05 17:21:38 -0700 | [diff] [blame] | 1183 | int acquireFd[MAX_NUM_APP_LAYERS]; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1184 | int count = 0; |
| 1185 | int releaseFd = -1; |
Arun Kumar K.R | 641a3be | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1186 | int retireFd = -1; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1187 | int fbFd = -1; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1188 | bool swapzero = false; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1189 | int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 1190 | |
| 1191 | struct mdp_buf_sync data; |
| 1192 | memset(&data, 0, sizeof(data)); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1193 | data.acq_fen_fd = acquireFd; |
| 1194 | data.rel_fen_fd = &releaseFd; |
Arun Kumar K.R | 641a3be | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1195 | data.retire_fen_fd = &retireFd; |
| 1196 | data.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1197 | |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1198 | char property[PROPERTY_VALUE_MAX]; |
| 1199 | if(property_get("debug.egl.swapinterval", property, "1") > 0) { |
| 1200 | if(atoi(property) == 0) |
| 1201 | swapzero = true; |
| 1202 | } |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1203 | |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1204 | bool isExtAnimating = false; |
| 1205 | if(dpy) |
| 1206 | isExtAnimating = ctx->listStats[dpy].isDisplayAnimating; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1207 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1208 | //Send acquireFenceFds to rotator |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1209 | for(uint32_t i = 0; i < ctx->mLayerRotMap[dpy]->getCount(); i++) { |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1210 | int rotFd = ctx->mRotMgr->getRotDevFd(); |
| 1211 | int rotReleaseFd = -1; |
Ramkumar Radhakrishnan | 56db0cc | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1212 | overlay::Rotator* currRot = ctx->mLayerRotMap[dpy]->getRot(i); |
| 1213 | hwc_layer_1_t* currLayer = ctx->mLayerRotMap[dpy]->getLayer(i); |
| 1214 | if((currRot == NULL) || (currLayer == NULL)) { |
| 1215 | continue; |
| 1216 | } |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1217 | struct mdp_buf_sync rotData; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1218 | memset(&rotData, 0, sizeof(rotData)); |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1219 | rotData.acq_fen_fd = |
Ramkumar Radhakrishnan | 56db0cc | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1220 | &currLayer->acquireFenceFd; |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1221 | rotData.rel_fen_fd = &rotReleaseFd; //driver to populate this |
Ramkumar Radhakrishnan | 56db0cc | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1222 | rotData.session_id = currRot->getSessId(); |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1223 | int ret = 0; |
| 1224 | ret = ioctl(rotFd, MSMFB_BUFFER_SYNC, &rotData); |
| 1225 | if(ret < 0) { |
| 1226 | ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed for rot sync, err=%s", |
| 1227 | __FUNCTION__, strerror(errno)); |
| 1228 | } else { |
Ramkumar Radhakrishnan | 56db0cc | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1229 | close(currLayer->acquireFenceFd); |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1230 | //For MDP to wait on. |
Ramkumar Radhakrishnan | 56db0cc | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1231 | currLayer->acquireFenceFd = |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1232 | dup(rotReleaseFd); |
| 1233 | //A buffer is free to be used by producer as soon as its copied to |
| 1234 | //rotator |
Ramkumar Radhakrishnan | 56db0cc | 2014-01-31 20:03:01 -0800 | [diff] [blame] | 1235 | currLayer->releaseFenceFd = |
Saurabh Shah | e9b5a8f | 2013-06-28 11:33:25 -0700 | [diff] [blame] | 1236 | rotReleaseFd; |
| 1237 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1238 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1239 | |
Balamurugan Thanikachalam | 770d9e8 | 2014-01-31 18:23:20 +0530 | [diff] [blame] | 1240 | //Accumulate acquireFenceFds for MDP Overlays |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1241 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Balamurugan Thanikachalam | 770d9e8 | 2014-01-31 18:23:20 +0530 | [diff] [blame] | 1242 | if(list->hwLayers[i].compositionType == HWC_OVERLAY && |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1243 | list->hwLayers[i].acquireFenceFd >= 0) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1244 | if(UNLIKELY(swapzero)) |
| 1245 | acquireFd[count++] = -1; |
| 1246 | else |
| 1247 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1248 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1249 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 1250 | if(UNLIKELY(swapzero)) |
| 1251 | acquireFd[count++] = -1; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1252 | else if(fd >= 0) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1253 | //set the acquireFD from fd - which is coming from c2d |
| 1254 | acquireFd[count++] = fd; |
| 1255 | // Buffer sync IOCTL should be async when using c2d fence is |
| 1256 | // used |
| 1257 | data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1258 | } else if(list->hwLayers[i].acquireFenceFd >= 0) |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1259 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
| 1260 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1263 | data.acq_fen_fd_cnt = count; |
| 1264 | fbFd = ctx->dpyAttr[dpy].fd; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1265 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1266 | //Waits for acquire fences, returns a release fence |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1267 | if(LIKELY(!swapzero)) { |
| 1268 | uint64_t start = systemTime(); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1269 | ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1270 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d", |
| 1271 | __FUNCTION__, (size_t) ns2ms(systemTime() - start)); |
| 1272 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1273 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1274 | if(ret < 0) { |
Ramkumar Radhakrishnan | b32a0bc | 2013-04-11 17:57:32 -0700 | [diff] [blame] | 1275 | ALOGE("%s: ioctl MSMFB_BUFFER_SYNC failed, err=%s", |
| 1276 | __FUNCTION__, strerror(errno)); |
| 1277 | ALOGE("%s: acq_fen_fd_cnt=%d flags=%d fd=%d dpy=%d numHwLayers=%d", |
| 1278 | __FUNCTION__, data.acq_fen_fd_cnt, data.flags, fbFd, |
| 1279 | dpy, list->numHwLayers); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1280 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1281 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1282 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1283 | if(list->hwLayers[i].compositionType == HWC_OVERLAY || |
Justin Philip | 8e5f966 | 2014-07-31 11:52:34 +0530 | [diff] [blame] | 1284 | list->hwLayers[i].compositionType == HWC_BLIT || |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 1285 | list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1286 | //Populate releaseFenceFds. |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1287 | if(UNLIKELY(swapzero)) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1288 | list->hwLayers[i].releaseFenceFd = -1; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1289 | } else if(isExtAnimating) { |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1290 | // Release all the app layer fds immediately, |
| 1291 | // if animation is in progress. |
Ramkumar Radhakrishnan | a70981a | 2013-08-28 11:33:53 -0700 | [diff] [blame] | 1292 | list->hwLayers[i].releaseFenceFd = -1; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1293 | } else if(list->hwLayers[i].releaseFenceFd < 0) { |
| 1294 | //If rotator has not already populated this field. |
Justin Philip | 8e5f966 | 2014-07-31 11:52:34 +0530 | [diff] [blame] | 1295 | if(list->hwLayers[i].compositionType == HWC_BLIT) { |
| 1296 | //For Blit, the app layers should be released when the Blit is |
| 1297 | //complete. This fd was passed from copybit->draw |
| 1298 | list->hwLayers[i].releaseFenceFd = dup(fd); |
| 1299 | } else { |
Balamurugan Thanikachalam | 770d9e8 | 2014-01-31 18:23:20 +0530 | [diff] [blame] | 1300 | list->hwLayers[i].releaseFenceFd = dup(releaseFd); |
Justin Philip | 8e5f966 | 2014-07-31 11:52:34 +0530 | [diff] [blame] | 1301 | } |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1302 | } |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 1303 | } |
| 1304 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 1305 | |
| 1306 | if(fd >= 0) { |
| 1307 | close(fd); |
| 1308 | fd = -1; |
| 1309 | } |
| 1310 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 1311 | if (ctx->mCopyBit[dpy]) |
| 1312 | ctx->mCopyBit[dpy]->setReleaseFd(releaseFd); |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1313 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1314 | //Signals when MDP finishes reading rotator buffers. |
| 1315 | ctx->mLayerRotMap[dpy]->setReleaseFd(releaseFd); |
Arun Kumar K.R | 641a3be | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1316 | close(releaseFd); |
| 1317 | releaseFd = -1; |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 1318 | |
Arun Kumar K.R | 641a3be | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1319 | if(UNLIKELY(swapzero)) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1320 | list->retireFenceFd = -1; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1321 | } else { |
Arun Kumar K.R | 641a3be | 2013-11-19 11:20:28 -0800 | [diff] [blame] | 1322 | list->retireFenceFd = retireFd; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 1323 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 1324 | return ret; |
| 1325 | } |
| 1326 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1327 | void setMdpFlags(hwc_layer_1_t *layer, |
| 1328 | ovutils::eMdpFlags &mdpFlags, |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1329 | int rotDownscale, int transform) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1330 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Saurabh Shah | 220a30c | 2013-10-29 16:12:12 -0700 | [diff] [blame] | 1331 | MetaData_t *metadata = hnd ? (MetaData_t *)hnd->base_metadata : NULL; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1332 | |
| 1333 | if(layer->blending == HWC_BLENDING_PREMULT) { |
| 1334 | ovutils::setMdpFlags(mdpFlags, |
| 1335 | ovutils::OV_MDP_BLEND_FG_PREMULT); |
| 1336 | } |
| 1337 | |
| 1338 | if(isYuvBuffer(hnd)) { |
| 1339 | if(isSecureBuffer(hnd)) { |
| 1340 | ovutils::setMdpFlags(mdpFlags, |
| 1341 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
| 1342 | } |
| 1343 | if(metadata && (metadata->operation & PP_PARAM_INTERLACED) && |
| 1344 | metadata->interlaced) { |
| 1345 | ovutils::setMdpFlags(mdpFlags, |
| 1346 | ovutils::OV_MDP_DEINTERLACE); |
| 1347 | } |
| 1348 | //Pre-rotation will be used using rotator. |
| 1349 | if(transform & HWC_TRANSFORM_ROT_90) { |
| 1350 | ovutils::setMdpFlags(mdpFlags, |
| 1351 | ovutils::OV_MDP_SOURCE_ROTATED_90); |
| 1352 | } |
| 1353 | } |
| 1354 | |
Ramkumar Radhakrishnan | ba71338 | 2013-08-30 18:41:07 -0700 | [diff] [blame] | 1355 | if(isSecureDisplayBuffer(hnd)) { |
| 1356 | // Secure display needs both SECURE_OVERLAY and SECURE_DISPLAY_OV |
| 1357 | ovutils::setMdpFlags(mdpFlags, |
| 1358 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
| 1359 | ovutils::setMdpFlags(mdpFlags, |
| 1360 | ovutils::OV_MDP_SECURE_DISPLAY_OVERLAY_SESSION); |
| 1361 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1362 | //No 90 component and no rot-downscale then flips done by MDP |
| 1363 | //If we use rot then it might as well do flips |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1364 | if(!(transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) { |
| 1365 | if(transform & HWC_TRANSFORM_FLIP_H) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1366 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H); |
| 1367 | } |
| 1368 | |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1369 | if(transform & HWC_TRANSFORM_FLIP_V) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1370 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V); |
| 1371 | } |
| 1372 | } |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1373 | |
| 1374 | if(metadata && |
| 1375 | ((metadata->operation & PP_PARAM_HSIC) |
| 1376 | || (metadata->operation & PP_PARAM_IGC) |
| 1377 | || (metadata->operation & PP_PARAM_SHARP2))) { |
| 1378 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN); |
| 1379 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1380 | } |
| 1381 | |
Prabhanjan Kandula | a1d8301 | 2013-04-23 13:06:02 +0530 | [diff] [blame] | 1382 | int configRotator(Rotator *rot, Whf& whf, |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1383 | hwc_rect_t& crop, const eMdpFlags& mdpFlags, |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1384 | const eTransform& orient, const int& downscale) { |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1385 | |
Prabhanjan Kandula | a1d8301 | 2013-04-23 13:06:02 +0530 | [diff] [blame] | 1386 | // Fix alignments for TILED format |
| 1387 | if(whf.format == MDP_Y_CRCB_H2V2_TILE || |
| 1388 | whf.format == MDP_Y_CBCR_H2V2_TILE) { |
| 1389 | whf.w = utils::alignup(whf.w, 64); |
| 1390 | whf.h = utils::alignup(whf.h, 32); |
| 1391 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1392 | rot->setSource(whf); |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1393 | |
| 1394 | if (qdutils::MDPVersion::getInstance().getMDPVersion() >= |
| 1395 | qdutils::MDSS_V5) { |
| 1396 | uint32_t crop_w = (crop.right - crop.left); |
| 1397 | uint32_t crop_h = (crop.bottom - crop.top); |
Sushil Chauhan | 6181aa2 | 2013-05-17 18:04:10 -0700 | [diff] [blame] | 1398 | if (ovutils::isYuv(whf.format)) { |
| 1399 | ovutils::normalizeCrop((uint32_t&)crop.left, crop_w); |
| 1400 | ovutils::normalizeCrop((uint32_t&)crop.top, crop_h); |
Sushil Chauhan | 5491c8a | 2013-05-24 10:15:30 -0700 | [diff] [blame] | 1401 | // For interlaced, crop.h should be 4-aligned |
| 1402 | if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4)) |
| 1403 | crop_h = ovutils::aligndown(crop_h, 4); |
Sushil Chauhan | 6181aa2 | 2013-05-17 18:04:10 -0700 | [diff] [blame] | 1404 | crop.right = crop.left + crop_w; |
| 1405 | crop.bottom = crop.top + crop_h; |
| 1406 | } |
Sushil Chauhan | 1cac815 | 2013-05-08 15:53:51 -0700 | [diff] [blame] | 1407 | Dim rotCrop(crop.left, crop.top, crop_w, crop_h); |
| 1408 | rot->setCrop(rotCrop); |
| 1409 | } |
| 1410 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1411 | rot->setFlags(mdpFlags); |
| 1412 | rot->setTransform(orient); |
| 1413 | rot->setDownscale(downscale); |
| 1414 | if(!rot->commit()) return -1; |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 1418 | int configMdp(Overlay *ov, const PipeArgs& parg, |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1419 | const eTransform& orient, const hwc_rect_t& crop, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1420 | const hwc_rect_t& pos, const MetaData_t *metadata, |
| 1421 | const eDest& dest) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1422 | ov->setSource(parg, dest); |
| 1423 | ov->setTransform(orient, dest); |
| 1424 | |
| 1425 | int crop_w = crop.right - crop.left; |
| 1426 | int crop_h = crop.bottom - crop.top; |
| 1427 | Dim dcrop(crop.left, crop.top, crop_w, crop_h); |
| 1428 | ov->setCrop(dcrop, dest); |
| 1429 | |
| 1430 | int posW = pos.right - pos.left; |
| 1431 | int posH = pos.bottom - pos.top; |
| 1432 | Dim position(pos.left, pos.top, posW, posH); |
| 1433 | ov->setPosition(position, dest); |
| 1434 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1435 | if (metadata) |
| 1436 | ov->setVisualParams(*metadata, dest); |
| 1437 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1438 | if (!ov->commit(dest)) { |
| 1439 | return -1; |
| 1440 | } |
| 1441 | return 0; |
| 1442 | } |
| 1443 | |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1444 | int configColorLayer(hwc_context_t *ctx, hwc_layer_1_t *layer, |
| 1445 | const int& dpy, eMdpFlags& mdpFlags, eZorder& z, |
| 1446 | eIsFg& isFg, const eDest& dest) { |
| 1447 | |
| 1448 | hwc_rect_t dst = layer->displayFrame; |
| 1449 | trimLayer(ctx, dpy, 0, dst, dst); |
| 1450 | |
| 1451 | int w = ctx->dpyAttr[dpy].xres; |
| 1452 | int h = ctx->dpyAttr[dpy].yres; |
| 1453 | int dst_w = dst.right - dst.left; |
| 1454 | int dst_h = dst.bottom - dst.top; |
| 1455 | uint32_t color = layer->transform; |
| 1456 | Whf whf(w, h, getMdpFormat(HAL_PIXEL_FORMAT_RGBA_8888), 0); |
| 1457 | |
Sushil Chauhan | f10c523 | 2013-12-19 10:35:54 -0800 | [diff] [blame] | 1458 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_SOLID_FILL); |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1459 | if (layer->blending == HWC_BLENDING_PREMULT) |
| 1460 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_BLEND_FG_PREMULT); |
| 1461 | |
| 1462 | PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(0), |
| 1463 | layer->planeAlpha, |
| 1464 | (ovutils::eBlending) getBlending(layer->blending)); |
| 1465 | |
| 1466 | // Configure MDP pipe for Color layer |
| 1467 | Dim pos(dst.left, dst.top, dst_w, dst_h); |
| 1468 | ctx->mOverlay->setSource(parg, dest); |
| 1469 | ctx->mOverlay->setColor(color, dest); |
| 1470 | ctx->mOverlay->setTransform(0, dest); |
| 1471 | ctx->mOverlay->setCrop(pos, dest); |
| 1472 | ctx->mOverlay->setPosition(pos, dest); |
| 1473 | |
| 1474 | if (!ctx->mOverlay->commit(dest)) { |
| 1475 | ALOGE("%s: Configure color layer failed!", __FUNCTION__); |
| 1476 | return -1; |
| 1477 | } |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 1481 | void updateSource(eTransform& orient, Whf& whf, |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1482 | hwc_rect_t& crop) { |
| 1483 | Dim srcCrop(crop.left, crop.top, |
| 1484 | crop.right - crop.left, |
| 1485 | crop.bottom - crop.top); |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 1486 | orient = static_cast<eTransform>(ovutils::getMdpOrient(orient)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1487 | preRotateSource(orient, whf, srcCrop); |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1488 | if (qdutils::MDPVersion::getInstance().getMDPVersion() >= |
| 1489 | qdutils::MDSS_V5) { |
| 1490 | // Source for overlay will be the cropped (and rotated) |
| 1491 | crop.left = 0; |
| 1492 | crop.top = 0; |
| 1493 | crop.right = srcCrop.w; |
| 1494 | crop.bottom = srcCrop.h; |
| 1495 | // Set width & height equal to sourceCrop w & h |
| 1496 | whf.w = srcCrop.w; |
| 1497 | whf.h = srcCrop.h; |
| 1498 | } else { |
| 1499 | crop.left = srcCrop.x; |
| 1500 | crop.top = srcCrop.y; |
| 1501 | crop.right = srcCrop.x + srcCrop.w; |
| 1502 | crop.bottom = srcCrop.y + srcCrop.h; |
| 1503 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1504 | } |
| 1505 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1506 | int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1507 | const int& dpy, eMdpFlags& mdpFlags, eZorder& z, |
| 1508 | eIsFg& isFg, const eDest& dest, Rotator **rot) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1509 | |
| 1510 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1511 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1512 | if(!hnd) { |
Sushil Chauhan | 897a9c3 | 2013-07-18 11:09:55 -0700 | [diff] [blame] | 1513 | if (layer->flags & HWC_COLOR_FILL) { |
| 1514 | // Configure Color layer |
| 1515 | return configColorLayer(ctx, layer, dpy, mdpFlags, z, isFg, dest); |
| 1516 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1517 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 1518 | return -1; |
| 1519 | } |
| 1520 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1521 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 1522 | |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 1523 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1524 | hwc_rect_t dst = layer->displayFrame; |
| 1525 | int transform = layer->transform; |
| 1526 | eTransform orient = static_cast<eTransform>(transform); |
| 1527 | int downscale = 0; |
| 1528 | int rotFlags = ovutils::ROT_FLAGS_NONE; |
Ramkumar Radhakrishnan | 92f3abe | 2013-06-05 13:52:40 -0700 | [diff] [blame] | 1529 | Whf whf(getWidth(hnd), getHeight(hnd), |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1530 | getMdpFormat(hnd->format), hnd->size); |
| 1531 | |
Sushil Chauhan | 1f6d68f | 2013-10-11 11:49:35 -0700 | [diff] [blame] | 1532 | // Handle R/B swap |
| 1533 | if (layer->flags & HWC_FORMAT_RB_SWAP) { |
| 1534 | if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888) |
| 1535 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888); |
| 1536 | else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888) |
| 1537 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888); |
| 1538 | } |
| 1539 | |
Ramkumar Radhakrishnan | 939a9e7 | 2013-12-04 18:30:18 -0800 | [diff] [blame] | 1540 | calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient); |
Arun Kumar K.R | ffef748 | 2013-04-10 14:17:22 -0700 | [diff] [blame] | 1541 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1542 | if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 && |
Jeykumar Sankaran | 85977e3 | 2013-02-25 17:06:08 -0800 | [diff] [blame] | 1543 | ctx->mMDP.version < qdutils::MDSS_V5) { |
| 1544 | downscale = getDownscaleFactor( |
| 1545 | crop.right - crop.left, |
| 1546 | crop.bottom - crop.top, |
| 1547 | dst.right - dst.left, |
| 1548 | dst.bottom - dst.top); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1549 | if(downscale) { |
| 1550 | rotFlags = ROT_DOWNSCALE_ENABLED; |
| 1551 | } |
| 1552 | } |
| 1553 | |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1554 | setMdpFlags(layer, mdpFlags, downscale, transform); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1555 | |
| 1556 | if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot |
| 1557 | ((transform & HWC_TRANSFORM_ROT_90) || downscale)) { |
| 1558 | *rot = ctx->mRotMgr->getNext(); |
| 1559 | if(*rot == NULL) return -1; |
Saurabh Shah | 70b62f5 | 2014-03-31 10:31:42 -0700 | [diff] [blame] | 1560 | ctx->mLayerRotMap[dpy]->add(layer, *rot); |
Tatenda Chipeperekwa | 8856270 | 2013-10-19 19:56:16 -0700 | [diff] [blame] | 1561 | if(!dpy) |
| 1562 | BwcPM::setBwc(ctx, crop, dst, transform, mdpFlags); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1563 | //Configure rotator for pre-rotation |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1564 | if(configRotator(*rot, whf, crop, mdpFlags, orient, downscale) < 0) { |
| 1565 | ALOGE("%s: configRotator failed!", __FUNCTION__); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1566 | return -1; |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1567 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1568 | whf.format = (*rot)->getDstFormat(); |
| 1569 | updateSource(orient, whf, crop); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1570 | rotFlags |= ovutils::ROT_PREROTATED; |
| 1571 | } |
| 1572 | |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 1573 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 1574 | orient = OVERLAY_TRANSFORM_0; |
| 1575 | transform = 0; |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 1576 | PipeArgs parg(mdpFlags, whf, z, isFg, |
| 1577 | static_cast<eRotFlags>(rotFlags), layer->planeAlpha, |
| 1578 | (ovutils::eBlending) getBlending(layer->blending)); |
| 1579 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1580 | if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1581 | ALOGE("%s: commit failed for low res panel", __FUNCTION__); |
| 1582 | return -1; |
| 1583 | } |
| 1584 | return 0; |
| 1585 | } |
| 1586 | |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 1587 | //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] | 1588 | void sanitizeSourceCrop(hwc_rect_t& cropL, hwc_rect_t& cropR, |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 1589 | private_handle_t *hnd) { |
| 1590 | if(cropL.right - cropL.left) { |
| 1591 | if(isYuvBuffer(hnd)) { |
| 1592 | //Always safe to even down left |
| 1593 | ovutils::even_floor(cropL.left); |
| 1594 | //If right is even, automatically width is even, since left is |
| 1595 | //already even |
| 1596 | ovutils::even_floor(cropL.right); |
| 1597 | } |
| 1598 | //Make sure there are no gaps between left and right splits if the layer |
| 1599 | //is spread across BOTH halves |
| 1600 | if(cropR.right - cropR.left) { |
| 1601 | cropR.left = cropL.right; |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | if(cropR.right - cropR.left) { |
| 1606 | if(isYuvBuffer(hnd)) { |
| 1607 | //Always safe to even down left |
| 1608 | ovutils::even_floor(cropR.left); |
| 1609 | //If right is even, automatically width is even, since left is |
| 1610 | //already even |
| 1611 | ovutils::even_floor(cropR.right); |
| 1612 | } |
| 1613 | } |
| 1614 | } |
| 1615 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1616 | int configureSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, |
Ramkumar Radhakrishnan | 59a1107 | 2013-04-15 16:14:49 -0700 | [diff] [blame] | 1617 | const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z, |
| 1618 | eIsFg& isFg, const eDest& lDest, const eDest& rDest, |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1619 | Rotator **rot) { |
| 1620 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1621 | if(!hnd) { |
| 1622 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 1623 | return -1; |
| 1624 | } |
| 1625 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1626 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 1627 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1628 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 1629 | int hw_h = ctx->dpyAttr[dpy].yres; |
Saurabh Shah | 62e1d73 | 2013-09-17 10:44:05 -0700 | [diff] [blame] | 1630 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1631 | hwc_rect_t dst = layer->displayFrame; |
| 1632 | int transform = layer->transform; |
| 1633 | eTransform orient = static_cast<eTransform>(transform); |
| 1634 | const int downscale = 0; |
| 1635 | int rotFlags = ROT_FLAGS_NONE; |
| 1636 | |
Ramkumar Radhakrishnan | 92f3abe | 2013-06-05 13:52:40 -0700 | [diff] [blame] | 1637 | Whf whf(getWidth(hnd), getHeight(hnd), |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1638 | getMdpFormat(hnd->format), hnd->size); |
| 1639 | |
Sushil Chauhan | 1f6d68f | 2013-10-11 11:49:35 -0700 | [diff] [blame] | 1640 | // Handle R/B swap |
| 1641 | if (layer->flags & HWC_FORMAT_RB_SWAP) { |
| 1642 | if (hnd->format == HAL_PIXEL_FORMAT_RGBA_8888) |
| 1643 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRA_8888); |
| 1644 | else if (hnd->format == HAL_PIXEL_FORMAT_RGBX_8888) |
| 1645 | whf.format = getMdpFormat(HAL_PIXEL_FORMAT_BGRX_8888); |
| 1646 | } |
| 1647 | |
Ramkumar Radhakrishnan | 9921b4c | 2014-03-03 14:46:21 -0800 | [diff] [blame] | 1648 | /* Calculate the external display position based on MDP downscale, |
| 1649 | ActionSafe, and extorientation features. */ |
| 1650 | calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient); |
| 1651 | |
Ramkumar Radhakrishnan | 9d52f43 | 2013-05-14 14:46:59 -0700 | [diff] [blame] | 1652 | setMdpFlags(layer, mdpFlagsL, 0, transform); |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 1653 | |
| 1654 | if(lDest != OV_INVALID && rDest != OV_INVALID) { |
| 1655 | //Enable overfetch |
| 1656 | setMdpFlags(mdpFlagsL, OV_MDSS_MDP_DUAL_PIPE); |
| 1657 | } |
| 1658 | |
Saurabh Shah | a9da08f | 2013-07-03 13:27:53 -0700 | [diff] [blame] | 1659 | //Will do something only if feature enabled and conditions suitable |
| 1660 | //hollow call otherwise |
| 1661 | if(ctx->mAD->prepare(ctx, crop, whf, hnd)) { |
| 1662 | overlay::Writeback *wb = overlay::Writeback::getInstance(); |
| 1663 | whf.format = wb->getOutputFormat(); |
| 1664 | } |
| 1665 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1666 | if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) { |
| 1667 | (*rot) = ctx->mRotMgr->getNext(); |
| 1668 | if((*rot) == NULL) return -1; |
Saurabh Shah | 70b62f5 | 2014-03-31 10:31:42 -0700 | [diff] [blame] | 1669 | ctx->mLayerRotMap[dpy]->add(layer, *rot); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1670 | //Configure rotator for pre-rotation |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1671 | if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) { |
| 1672 | ALOGE("%s: configRotator failed!", __FUNCTION__); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1673 | return -1; |
Sushil Chauhan | 80fc1f9 | 2013-04-23 17:30:05 -0700 | [diff] [blame] | 1674 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1675 | whf.format = (*rot)->getDstFormat(); |
| 1676 | updateSource(orient, whf, crop); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1677 | rotFlags |= ROT_PREROTATED; |
| 1678 | } |
| 1679 | |
| 1680 | eMdpFlags mdpFlagsR = mdpFlagsL; |
| 1681 | setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER); |
| 1682 | |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 1683 | hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0}; |
| 1684 | hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0}; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1685 | |
Saurabh Shah | 07a8ca8 | 2013-08-06 18:45:42 -0700 | [diff] [blame] | 1686 | const int lSplit = getLeftSplit(ctx, dpy); |
| 1687 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1688 | if(lDest != OV_INVALID) { |
| 1689 | tmp_cropL = crop; |
| 1690 | tmp_dstL = dst; |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 1691 | hwc_rect_t scissor = {0, 0, lSplit, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 1692 | scissor = getIntersection(ctx->mViewFrame[dpy], scissor); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1693 | qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0); |
| 1694 | } |
| 1695 | if(rDest != OV_INVALID) { |
| 1696 | tmp_cropR = crop; |
| 1697 | tmp_dstR = dst; |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 1698 | hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h }; |
Ramkumar Radhakrishnan | d855948 | 2013-12-05 11:21:44 -0800 | [diff] [blame] | 1699 | scissor = getIntersection(ctx->mViewFrame[dpy], scissor); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1700 | qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0); |
| 1701 | } |
| 1702 | |
Saurabh Shah | d9e426d | 2013-08-01 13:35:31 -0700 | [diff] [blame] | 1703 | sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd); |
| 1704 | |
Saurabh Shah | 94d6236 | 2013-07-02 10:58:48 -0700 | [diff] [blame] | 1705 | //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] | 1706 | //Not needed if the layer is confined to one half of the screen. |
| 1707 | //If rotator has been used then it has also done the flips, so ignore them. |
Saurabh Shah | 94d6236 | 2013-07-02 10:58:48 -0700 | [diff] [blame] | 1708 | if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID |
Ramkumar Radhakrishnan | fe7ce80 | 2013-04-30 11:19:17 -0700 | [diff] [blame] | 1709 | && rDest != OV_INVALID && (*rot) == NULL) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1710 | hwc_rect_t new_cropR; |
| 1711 | new_cropR.left = tmp_cropL.left; |
| 1712 | new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left); |
| 1713 | |
| 1714 | hwc_rect_t new_cropL; |
| 1715 | new_cropL.left = new_cropR.right; |
| 1716 | new_cropL.right = tmp_cropR.right; |
| 1717 | |
| 1718 | tmp_cropL.left = new_cropL.left; |
| 1719 | tmp_cropL.right = new_cropL.right; |
| 1720 | |
| 1721 | tmp_cropR.left = new_cropR.left; |
| 1722 | tmp_cropR.right = new_cropR.right; |
| 1723 | |
| 1724 | } |
| 1725 | |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 1726 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 1727 | orient = OVERLAY_TRANSFORM_0; |
| 1728 | transform = 0; |
| 1729 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1730 | //configure left mixer |
| 1731 | if(lDest != OV_INVALID) { |
| 1732 | PipeArgs pargL(mdpFlagsL, whf, z, isFg, |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 1733 | static_cast<eRotFlags>(rotFlags), layer->planeAlpha, |
| 1734 | (ovutils::eBlending) getBlending(layer->blending)); |
| 1735 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1736 | if(configMdp(ctx->mOverlay, pargL, orient, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1737 | tmp_cropL, tmp_dstL, metadata, lDest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1738 | ALOGE("%s: commit failed for left mixer config", __FUNCTION__); |
| 1739 | return -1; |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | //configure right mixer |
| 1744 | if(rDest != OV_INVALID) { |
| 1745 | PipeArgs pargR(mdpFlagsR, whf, z, isFg, |
Naseer Ahmed | 522ce66 | 2013-03-18 20:14:05 -0400 | [diff] [blame] | 1746 | static_cast<eRotFlags>(rotFlags), |
| 1747 | layer->planeAlpha, |
| 1748 | (ovutils::eBlending) getBlending(layer->blending)); |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 1749 | tmp_dstR.right = tmp_dstR.right - lSplit; |
| 1750 | tmp_dstR.left = tmp_dstR.left - lSplit; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1751 | if(configMdp(ctx->mOverlay, pargR, orient, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 1752 | tmp_cropR, tmp_dstR, metadata, rDest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 1753 | ALOGE("%s: commit failed for right mixer config", __FUNCTION__); |
| 1754 | return -1; |
| 1755 | } |
| 1756 | } |
| 1757 | |
| 1758 | return 0; |
| 1759 | } |
Arun Kumar K.R | a297845 | 2013-02-07 01:34:24 -0800 | [diff] [blame] | 1760 | |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1761 | int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, |
| 1762 | const int& dpy, eMdpFlags& mdpFlagsL, eZorder& z, |
| 1763 | eIsFg& isFg, const eDest& lDest, const eDest& rDest, |
| 1764 | Rotator **rot) { |
| 1765 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 1766 | if(!hnd) { |
| 1767 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 1768 | return -1; |
| 1769 | } |
| 1770 | |
| 1771 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 1772 | |
| 1773 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 1774 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 1775 | hwc_rect_t crop = integerizeSourceCrop(layer->sourceCropf);; |
| 1776 | hwc_rect_t dst = layer->displayFrame; |
| 1777 | int transform = layer->transform; |
| 1778 | eTransform orient = static_cast<eTransform>(transform); |
| 1779 | const int downscale = 0; |
| 1780 | int rotFlags = ROT_FLAGS_NONE; |
| 1781 | //Splitting only YUV layer on primary panel needs different zorders |
| 1782 | //for both layers as both the layers are configured to single mixer |
| 1783 | eZorder lz = z; |
| 1784 | eZorder rz = (eZorder)(z + 1); |
| 1785 | |
| 1786 | Whf whf(getWidth(hnd), getHeight(hnd), |
| 1787 | getMdpFormat(hnd->format), hnd->size); |
| 1788 | |
Ramkumar Radhakrishnan | 3a070cc | 2014-02-20 19:37:15 -0800 | [diff] [blame] | 1789 | /* Calculate the external display position based on MDP downscale, |
| 1790 | ActionSafe, and extorientation features. */ |
| 1791 | calcExtDisplayPosition(ctx, hnd, dpy, crop, dst, transform, orient); |
| 1792 | |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1793 | setMdpFlags(layer, mdpFlagsL, 0, transform); |
| 1794 | trimLayer(ctx, dpy, transform, crop, dst); |
| 1795 | |
| 1796 | if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) { |
| 1797 | (*rot) = ctx->mRotMgr->getNext(); |
| 1798 | if((*rot) == NULL) return -1; |
Saurabh Shah | 70b62f5 | 2014-03-31 10:31:42 -0700 | [diff] [blame] | 1799 | ctx->mLayerRotMap[dpy]->add(layer, *rot); |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1800 | if(!dpy) |
| 1801 | BwcPM::setBwc(ctx, crop, dst, transform, mdpFlagsL); |
| 1802 | //Configure rotator for pre-rotation |
| 1803 | if(configRotator(*rot, whf, crop, mdpFlagsL, orient, downscale) < 0) { |
| 1804 | ALOGE("%s: configRotator failed!", __FUNCTION__); |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1805 | return -1; |
| 1806 | } |
radhakrishna | c9a6741 | 2013-09-25 17:40:42 +0530 | [diff] [blame] | 1807 | whf.format = (*rot)->getDstFormat(); |
| 1808 | updateSource(orient, whf, crop); |
| 1809 | rotFlags |= ROT_PREROTATED; |
| 1810 | } |
| 1811 | |
| 1812 | eMdpFlags mdpFlagsR = mdpFlagsL; |
| 1813 | int lSplit = dst.left + (dst.right - dst.left)/2; |
| 1814 | |
| 1815 | hwc_rect_t tmp_cropL = {0}, tmp_dstL = {0}; |
| 1816 | hwc_rect_t tmp_cropR = {0}, tmp_dstR = {0}; |
| 1817 | |
| 1818 | if(lDest != OV_INVALID) { |
| 1819 | tmp_cropL = crop; |
| 1820 | tmp_dstL = dst; |
| 1821 | hwc_rect_t scissor = {dst.left, dst.top, lSplit, dst.bottom }; |
| 1822 | qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0); |
| 1823 | } |
| 1824 | if(rDest != OV_INVALID) { |
| 1825 | tmp_cropR = crop; |
| 1826 | tmp_dstR = dst; |
| 1827 | hwc_rect_t scissor = {lSplit, dst.top, dst.right, dst.bottom }; |
| 1828 | qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0); |
| 1829 | } |
| 1830 | |
| 1831 | sanitizeSourceCrop(tmp_cropL, tmp_cropR, hnd); |
| 1832 | |
| 1833 | //When buffer is H-flipped, contents of mixer config also needs to swapped |
| 1834 | //Not needed if the layer is confined to one half of the screen. |
| 1835 | //If rotator has been used then it has also done the flips, so ignore them. |
| 1836 | if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID |
| 1837 | && rDest != OV_INVALID && (*rot) == NULL) { |
| 1838 | hwc_rect_t new_cropR; |
| 1839 | new_cropR.left = tmp_cropL.left; |
| 1840 | new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left); |
| 1841 | |
| 1842 | hwc_rect_t new_cropL; |
| 1843 | new_cropL.left = new_cropR.right; |
| 1844 | new_cropL.right = tmp_cropR.right; |
| 1845 | |
| 1846 | tmp_cropL.left = new_cropL.left; |
| 1847 | tmp_cropL.right = new_cropL.right; |
| 1848 | |
| 1849 | tmp_cropR.left = new_cropR.left; |
| 1850 | tmp_cropR.right = new_cropR.right; |
| 1851 | |
| 1852 | } |
| 1853 | |
| 1854 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 1855 | orient = OVERLAY_TRANSFORM_0; |
| 1856 | transform = 0; |
| 1857 | |
| 1858 | //configure left half |
| 1859 | if(lDest != OV_INVALID) { |
| 1860 | PipeArgs pargL(mdpFlagsL, whf, lz, isFg, |
| 1861 | static_cast<eRotFlags>(rotFlags), layer->planeAlpha, |
| 1862 | (ovutils::eBlending) getBlending(layer->blending)); |
| 1863 | |
| 1864 | if(configMdp(ctx->mOverlay, pargL, orient, |
| 1865 | tmp_cropL, tmp_dstL, metadata, lDest) < 0) { |
| 1866 | ALOGE("%s: commit failed for left half config", __FUNCTION__); |
| 1867 | return -1; |
| 1868 | } |
| 1869 | } |
| 1870 | |
| 1871 | //configure right half |
| 1872 | if(rDest != OV_INVALID) { |
| 1873 | PipeArgs pargR(mdpFlagsR, whf, rz, isFg, |
| 1874 | static_cast<eRotFlags>(rotFlags), |
| 1875 | layer->planeAlpha, |
| 1876 | (ovutils::eBlending) getBlending(layer->blending)); |
| 1877 | if(configMdp(ctx->mOverlay, pargR, orient, |
| 1878 | tmp_cropR, tmp_dstR, metadata, rDest) < 0) { |
| 1879 | ALOGE("%s: commit failed for right half config", __FUNCTION__); |
| 1880 | return -1; |
| 1881 | } |
| 1882 | } |
| 1883 | |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
Amara Venkata Mastan Manoj Kumar | 9d373c0 | 2013-08-20 14:30:09 -0700 | [diff] [blame] | 1887 | bool canUseRotator(hwc_context_t *ctx, int dpy) { |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 1888 | if(qdutils::MDPVersion::getInstance().is8x26() && |
Tatenda Chipeperekwa | 75a4181 | 2014-04-01 12:54:13 -0700 | [diff] [blame] | 1889 | isSecondaryConnected(ctx) && |
Amara Venkata Mastan Manoj Kumar | 5cbac94 | 2013-08-13 19:00:14 -0700 | [diff] [blame] | 1890 | !ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isPause) { |
Raj Kamal | a8c065f | 2013-10-22 14:52:45 +0530 | [diff] [blame] | 1891 | /* 8x26 mdss driver supports multiplexing of DMA pipe |
| 1892 | * in LINE and BLOCK modes for writeback panels. |
| 1893 | */ |
Amara Venkata Mastan Manoj Kumar | 9d373c0 | 2013-08-20 14:30:09 -0700 | [diff] [blame] | 1894 | if(dpy == HWC_DISPLAY_PRIMARY) |
| 1895 | return false; |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 1896 | } |
Terence Hampson | 45c02ef | 2013-05-17 17:00:11 -0400 | [diff] [blame] | 1897 | if(ctx->mMDP.version == qdutils::MDP_V3_0_4) |
| 1898 | return false; |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 1899 | return true; |
| 1900 | } |
| 1901 | |
Saurabh Shah | 07a8ca8 | 2013-08-06 18:45:42 -0700 | [diff] [blame] | 1902 | int getLeftSplit(hwc_context_t *ctx, const int& dpy) { |
| 1903 | //Default even split for all displays with high res |
| 1904 | int lSplit = ctx->dpyAttr[dpy].xres / 2; |
| 1905 | if(dpy == HWC_DISPLAY_PRIMARY && |
| 1906 | qdutils::MDPVersion::getInstance().getLeftSplit()) { |
| 1907 | //Override if split published by driver for primary |
| 1908 | lSplit = qdutils::MDPVersion::getInstance().getLeftSplit(); |
| 1909 | } |
| 1910 | return lSplit; |
| 1911 | } |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 1912 | |
Saurabh Shah | 88e4d27 | 2013-09-03 13:31:29 -0700 | [diff] [blame] | 1913 | bool isDisplaySplit(hwc_context_t* ctx, int dpy) { |
| 1914 | if(ctx->dpyAttr[dpy].xres > qdutils::MAX_DISPLAY_DIM) { |
| 1915 | return true; |
| 1916 | } |
| 1917 | //For testing we could split primary via device tree values |
| 1918 | if(dpy == HWC_DISPLAY_PRIMARY && |
| 1919 | qdutils::MDPVersion::getInstance().getRightSplit()) { |
| 1920 | return true; |
| 1921 | } |
| 1922 | return false; |
| 1923 | } |
| 1924 | |
Ramkumar Radhakrishnan | 9c9a94b | 2014-03-14 17:28:14 -0700 | [diff] [blame] | 1925 | bool isGLESComp(hwc_context_t *ctx, |
| 1926 | hwc_display_contents_1_t* list) { |
| 1927 | int numAppLayers = ctx->listStats[HWC_DISPLAY_PRIMARY].numAppLayers; |
| 1928 | for(int index = 0; index < numAppLayers; index++) { |
| 1929 | hwc_layer_1_t* layer = &(list->hwLayers[index]); |
| 1930 | if(layer->compositionType == HWC_FRAMEBUFFER) |
| 1931 | return true; |
| 1932 | } |
| 1933 | return false; |
| 1934 | } |
| 1935 | |
| 1936 | void setGPUHint(hwc_context_t* ctx, hwc_display_contents_1_t* list) { |
| 1937 | struct gpu_hint_info *gpuHint = &ctx->mGPUHintInfo; |
| 1938 | if(!gpuHint->mGpuPerfModeEnable) |
| 1939 | return; |
| 1940 | /* Set the GPU hint flag to high for MIXED/GPU composition only for |
| 1941 | first frame after MDP -> GPU/MIXED mode transition. Set the GPU |
| 1942 | hint to default if the previous composition is GPU or current GPU |
| 1943 | composition is due to idle fallback */ |
| 1944 | if(!gpuHint->mEGLDisplay || !gpuHint->mEGLContext) { |
| 1945 | gpuHint->mEGLDisplay = eglGetCurrentDisplay(); |
| 1946 | if(!gpuHint->mEGLDisplay) { |
| 1947 | ALOGW("%s Warning: EGL current display is NULL", __FUNCTION__); |
| 1948 | return; |
| 1949 | } |
| 1950 | gpuHint->mEGLContext = eglGetCurrentContext(); |
| 1951 | if(!gpuHint->mEGLContext) { |
| 1952 | ALOGW("%s Warning: EGL current context is NULL", __FUNCTION__); |
| 1953 | return; |
| 1954 | } |
| 1955 | } |
| 1956 | if(isGLESComp(ctx, list)) { |
| 1957 | if(!gpuHint->mPrevCompositionGLES && !MDPComp::isIdleFallback()) { |
| 1958 | EGLint attr_list[] = {EGL_GPU_HINT_1, |
| 1959 | EGL_GPU_LEVEL_3, |
| 1960 | EGL_NONE }; |
| 1961 | if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) && |
| 1962 | !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay, |
| 1963 | gpuHint->mEGLContext, attr_list)) { |
| 1964 | ALOGW("eglGpuPerfHintQCOM failed for Built in display"); |
| 1965 | } else { |
| 1966 | gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_3; |
| 1967 | gpuHint->mPrevCompositionGLES = true; |
| 1968 | } |
| 1969 | } else { |
| 1970 | EGLint attr_list[] = {EGL_GPU_HINT_1, |
| 1971 | EGL_GPU_LEVEL_0, |
| 1972 | EGL_NONE }; |
| 1973 | if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) && |
| 1974 | !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay, |
| 1975 | gpuHint->mEGLContext, attr_list)) { |
| 1976 | ALOGW("eglGpuPerfHintQCOM failed for Built in display"); |
| 1977 | } else { |
| 1978 | gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0; |
| 1979 | } |
| 1980 | } |
| 1981 | } else { |
| 1982 | /* set the GPU hint flag to default for MDP composition */ |
| 1983 | EGLint attr_list[] = {EGL_GPU_HINT_1, |
| 1984 | EGL_GPU_LEVEL_0, |
| 1985 | EGL_NONE }; |
| 1986 | if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_0) && |
| 1987 | !eglGpuPerfHintQCOM(gpuHint->mEGLDisplay, |
| 1988 | gpuHint->mEGLContext, attr_list)) { |
| 1989 | ALOGW("eglGpuPerfHintQCOM failed for Built in display"); |
| 1990 | } else { |
| 1991 | gpuHint->mCurrGPUPerfMode = EGL_GPU_LEVEL_0; |
| 1992 | } |
| 1993 | gpuHint->mPrevCompositionGLES = false; |
| 1994 | } |
| 1995 | } |
| 1996 | |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 1997 | void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop, |
| 1998 | const hwc_rect_t& dst, const int& transform, |
| 1999 | ovutils::eMdpFlags& mdpFlags) { |
| 2000 | //Target doesnt support Bwc |
| 2001 | if(!qdutils::MDPVersion::getInstance().supportsBWC()) { |
| 2002 | return; |
| 2003 | } |
| 2004 | //src width > MAX mixer supported dim |
| 2005 | if((crop.right - crop.left) > qdutils::MAX_DISPLAY_DIM) { |
| 2006 | return; |
| 2007 | } |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2008 | //Decimation necessary, cannot use BWC. H/W requirement. |
| 2009 | if(qdutils::MDPVersion::getInstance().supportsDecimation()) { |
| 2010 | int src_w = crop.right - crop.left; |
| 2011 | int src_h = crop.bottom - crop.top; |
| 2012 | int dst_w = dst.right - dst.left; |
| 2013 | int dst_h = dst.bottom - dst.top; |
| 2014 | if(transform & HAL_TRANSFORM_ROT_90) { |
| 2015 | swap(src_w, src_h); |
| 2016 | } |
| 2017 | float horDscale = 0.0f; |
| 2018 | float verDscale = 0.0f; |
Saurabh Shah | c5b96dc | 2013-06-05 13:19:52 -0700 | [diff] [blame] | 2019 | int horzDeci = 0; |
| 2020 | int vertDeci = 0; |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2021 | ovutils::getDecimationFactor(src_w, src_h, dst_w, dst_h, horDscale, |
| 2022 | verDscale); |
Saurabh Shah | c5b96dc | 2013-06-05 13:19:52 -0700 | [diff] [blame] | 2023 | //TODO Use log2f once math.h has it |
| 2024 | if((int)horDscale) |
| 2025 | horzDeci = (int)(log(horDscale) / log(2)); |
| 2026 | if((int)verDscale) |
| 2027 | vertDeci = (int)(log(verDscale) / log(2)); |
| 2028 | if(horzDeci || vertDeci) return; |
Saurabh Shah | 1a03d48 | 2013-05-29 13:44:20 -0700 | [diff] [blame] | 2029 | } |
| 2030 | //Property |
| 2031 | char value[PROPERTY_VALUE_MAX]; |
| 2032 | property_get("debug.disable.bwc", value, "0"); |
| 2033 | if(atoi(value)) return; |
| 2034 | |
| 2035 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDSS_MDP_BWC_EN); |
| 2036 | } |
| 2037 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 2038 | void LayerRotMap::add(hwc_layer_1_t* layer, Rotator *rot) { |
| 2039 | if(mCount >= MAX_SESS) return; |
| 2040 | mLayer[mCount] = layer; |
| 2041 | mRot[mCount] = rot; |
| 2042 | mCount++; |
| 2043 | } |
| 2044 | |
| 2045 | void LayerRotMap::reset() { |
| 2046 | for (int i = 0; i < MAX_SESS; i++) { |
| 2047 | mLayer[i] = 0; |
| 2048 | mRot[i] = 0; |
| 2049 | } |
| 2050 | mCount = 0; |
| 2051 | } |
| 2052 | |
Saurabh Shah | da5b3ce | 2013-11-26 10:48:06 -0800 | [diff] [blame] | 2053 | void LayerRotMap::clear() { |
Saurabh Shah | 7a60684 | 2013-12-11 14:36:04 -0800 | [diff] [blame] | 2054 | RotMgr::getInstance()->markUnusedTop(mCount); |
Saurabh Shah | da5b3ce | 2013-11-26 10:48:06 -0800 | [diff] [blame] | 2055 | reset(); |
| 2056 | } |
| 2057 | |
Saurabh Shah | 23a813c | 2013-03-20 16:58:12 -0700 | [diff] [blame] | 2058 | void LayerRotMap::setReleaseFd(const int& fence) { |
| 2059 | for(uint32_t i = 0; i < mCount; i++) { |
| 2060 | mRot[i]->setReleaseFd(dup(fence)); |
| 2061 | } |
| 2062 | } |
| 2063 | |
Jeykumar Sankaran | 4d76a38 | 2014-02-26 18:26:58 -0800 | [diff] [blame] | 2064 | hwc_rect_t sanitizeROI(struct hwc_rect roi, hwc_rect boundary) |
| 2065 | { |
| 2066 | if(!isValidRect(roi)) |
| 2067 | return roi; |
| 2068 | |
| 2069 | struct hwc_rect t_roi = roi; |
| 2070 | |
| 2071 | const int LEFT_ALIGN = qdutils::MDPVersion::getInstance().getLeftAlign(); |
| 2072 | const int WIDTH_ALIGN = qdutils::MDPVersion::getInstance().getWidthAlign(); |
| 2073 | const int TOP_ALIGN = qdutils::MDPVersion::getInstance().getTopAlign(); |
| 2074 | const int HEIGHT_ALIGN = qdutils::MDPVersion::getInstance().getHeightAlign(); |
| 2075 | const int MIN_WIDTH = qdutils::MDPVersion::getInstance().getMinROIWidth(); |
| 2076 | |
| 2077 | /* Align to minimum width recommended by the panel */ |
| 2078 | if((t_roi.right - t_roi.left) < MIN_WIDTH) { |
| 2079 | if((t_roi.left + MIN_WIDTH) > boundary.right) |
| 2080 | t_roi.left = t_roi.right - MIN_WIDTH; |
| 2081 | else |
| 2082 | t_roi.right = t_roi.left + MIN_WIDTH; |
| 2083 | } |
| 2084 | |
| 2085 | if(LEFT_ALIGN) |
| 2086 | t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN); |
| 2087 | |
| 2088 | /* Align left and width to meet panel restrictions */ |
| 2089 | if(WIDTH_ALIGN) { |
| 2090 | int width = t_roi.right - t_roi.left; |
| 2091 | width = WIDTH_ALIGN * ((width + (WIDTH_ALIGN - 1)) / WIDTH_ALIGN); |
| 2092 | t_roi.right = t_roi.left + width; |
| 2093 | |
| 2094 | if(t_roi.right > boundary.right) { |
| 2095 | t_roi.right = boundary.right; |
| 2096 | t_roi.left = t_roi.right - width; |
| 2097 | |
| 2098 | if(LEFT_ALIGN) |
| 2099 | t_roi.left = t_roi.left - (t_roi.left % LEFT_ALIGN); |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | /* Align top and height to meet panel restrictions */ |
| 2104 | if(TOP_ALIGN) |
| 2105 | t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN); |
| 2106 | |
| 2107 | if(HEIGHT_ALIGN) { |
| 2108 | int height = t_roi.bottom - t_roi.top; |
| 2109 | height = HEIGHT_ALIGN * ((height + (HEIGHT_ALIGN - 1)) / HEIGHT_ALIGN); |
| 2110 | t_roi.bottom = t_roi.top + height; |
| 2111 | |
| 2112 | if(t_roi.bottom > boundary.bottom) { |
| 2113 | t_roi.bottom = boundary.bottom; |
| 2114 | t_roi.top = t_roi.bottom - height; |
| 2115 | |
| 2116 | if(TOP_ALIGN) |
| 2117 | t_roi.top = t_roi.top - (t_roi.top % TOP_ALIGN); |
| 2118 | } |
| 2119 | } |
| 2120 | |
| 2121 | return t_roi; |
| 2122 | } |
| 2123 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 2124 | };//namespace qhwc |