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