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 | */ |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 20 | #define HWC_UTILS_DEBUG 0 |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 21 | #include <sys/ioctl.h> |
Naseer Ahmed | 66e9788 | 2013-03-19 20:42:11 -0400 | [diff] [blame] | 22 | #include <linux/fb.h> |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 23 | #include <binder/IServiceManager.h> |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 24 | #include <EGL/egl.h> |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 25 | #include <cutils/properties.h> |
| 26 | #include <gralloc_priv.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 27 | #include <overlay.h> |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 28 | #include <overlayRotator.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 29 | #include "hwc_utils.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 30 | #include "hwc_mdpcomp.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 31 | #include "hwc_fbupdate.h" |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 32 | #include "hwc_video.h" |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 33 | #include "mdp_version.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 34 | #include "hwc_copybit.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 35 | #include "external.h" |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 36 | #include "hwc_qclient.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 37 | #include "QService.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 38 | #include "comptype.h" |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 39 | |
| 40 | using namespace qClient; |
| 41 | using namespace qService; |
| 42 | using namespace android; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 43 | using namespace overlay; |
| 44 | using namespace overlay::utils; |
| 45 | namespace ovutils = overlay::utils; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 46 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 47 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 48 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 49 | static int openFramebufferDevice(hwc_context_t *ctx) |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 50 | { |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 51 | struct fb_fix_screeninfo finfo; |
| 52 | struct fb_var_screeninfo info; |
| 53 | |
| 54 | int fb_fd = openFb(HWC_DISPLAY_PRIMARY); |
| 55 | |
| 56 | if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &info) == -1) |
| 57 | return -errno; |
| 58 | |
| 59 | if (int(info.width) <= 0 || int(info.height) <= 0) { |
| 60 | // the driver doesn't return that information |
| 61 | // default to 160 dpi |
| 62 | info.width = ((info.xres * 25.4f)/160.0f + 0.5f); |
| 63 | info.height = ((info.yres * 25.4f)/160.0f + 0.5f); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 64 | } |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 65 | |
| 66 | float xdpi = (info.xres * 25.4f) / info.width; |
| 67 | float ydpi = (info.yres * 25.4f) / info.height; |
| 68 | |
| 69 | #ifdef MSMFB_METADATA_GET |
| 70 | struct msmfb_metadata metadata; |
| 71 | memset(&metadata, 0 , sizeof(metadata)); |
| 72 | metadata.op = metadata_op_frame_rate; |
| 73 | |
| 74 | if (ioctl(fb_fd, MSMFB_METADATA_GET, &metadata) == -1) { |
| 75 | ALOGE("Error retrieving panel frame rate"); |
| 76 | return -errno; |
| 77 | } |
| 78 | |
| 79 | float fps = metadata.data.panel_frame_rate; |
| 80 | #else |
| 81 | //XXX: Remove reserved field usage on all baselines |
| 82 | //The reserved[3] field is used to store FPS by the driver. |
| 83 | float fps = info.reserved[3] & 0xFF; |
| 84 | #endif |
| 85 | |
| 86 | if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &finfo) == -1) |
| 87 | return -errno; |
| 88 | |
| 89 | if (finfo.smem_len <= 0) |
| 90 | return -errno; |
| 91 | |
| 92 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = fb_fd; |
| 93 | //xres, yres may not be 32 aligned |
| 94 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = finfo.line_length /(info.xres/8); |
| 95 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = info.xres; |
| 96 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = info.yres; |
| 97 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = xdpi; |
| 98 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ydpi; |
| 99 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = 1000000000l / fps; |
| 100 | |
| 101 | return 0; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 102 | } |
| 103 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 104 | void initContext(hwc_context_t *ctx) |
| 105 | { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 106 | openFramebufferDevice(ctx); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 107 | ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 108 | ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); |
| 109 | ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 110 | overlay::Overlay::initOverlay(); |
| 111 | ctx->mOverlay = overlay::Overlay::getInstance(); |
| 112 | ctx->mRotMgr = new RotMgr(); |
| 113 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 114 | //Is created and destroyed only once for primary |
| 115 | //For external it could get created and destroyed multiple times depending |
| 116 | //on what external we connect to. |
| 117 | ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] = |
| 118 | IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres, |
| 119 | HWC_DISPLAY_PRIMARY); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 120 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 121 | ctx->mVidOv[HWC_DISPLAY_PRIMARY] = |
| 122 | IVideoOverlay::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres, |
| 123 | HWC_DISPLAY_PRIMARY); |
| 124 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 125 | // Check if the target supports copybit compostion (dyn/mdp/c2d) to |
| 126 | // decide if we need to open the copybit module. |
| 127 | int compositionType = |
| 128 | qdutils::QCCompositionType::getInstance().getCompositionType(); |
| 129 | |
| 130 | if (compositionType & (qdutils::COMPOSITION_TYPE_DYN | |
| 131 | qdutils::COMPOSITION_TYPE_MDP | |
| 132 | qdutils::COMPOSITION_TYPE_C2D)) { |
| 133 | ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(); |
| 134 | } |
| 135 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 136 | ctx->mExtDisplay = new ExternalDisplay(ctx); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 137 | for (uint32_t i = 0; i < MAX_DISPLAYS; i++) |
Naseer Ahmed | e78f052 | 2012-12-07 18:24:28 -0500 | [diff] [blame] | 138 | ctx->mLayerCache[i] = new LayerCache(); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 139 | ctx->mMDPComp = MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 140 | MDPComp::init(ctx); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 141 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 142 | pthread_mutex_init(&(ctx->vstate.lock), NULL); |
| 143 | pthread_cond_init(&(ctx->vstate.cond), NULL); |
| 144 | ctx->vstate.enable = false; |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 145 | ctx->vstate.fakevsync = false; |
Amara Venkata Mastan Manoj Kumar | 75526f5 | 2012-12-27 18:27:01 -0800 | [diff] [blame] | 146 | ctx->mExtDispConfiguring = false; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 147 | |
| 148 | //Right now hwc starts the service but anybody could do it, or it could be |
| 149 | //independent process as well. |
| 150 | QService::init(); |
| 151 | sp<IQClient> client = new QClient(ctx); |
| 152 | interface_cast<IQService>( |
| 153 | defaultServiceManager()->getService( |
| 154 | String16("display.qservice")))->connect(client); |
| 155 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 156 | ALOGI("Initializing Qualcomm Hardware Composer"); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 157 | ALOGI("MDP version: %d", ctx->mMDP.version); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | void closeContext(hwc_context_t *ctx) |
| 161 | { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 162 | if(ctx->mOverlay) { |
| 163 | delete ctx->mOverlay; |
| 164 | ctx->mOverlay = NULL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 165 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 166 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 167 | if(ctx->mRotMgr) { |
| 168 | delete ctx->mRotMgr; |
| 169 | ctx->mRotMgr = NULL; |
| 170 | } |
| 171 | |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 172 | for(int i = 0; i < MAX_DISPLAYS; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 173 | if(ctx->mCopyBit[i]) { |
| 174 | delete ctx->mCopyBit[i]; |
| 175 | ctx->mCopyBit[i] = NULL; |
| 176 | } |
| 177 | } |
| 178 | |
Jeykumar Sankaran | c1f8682 | 2013-02-20 18:32:01 -0800 | [diff] [blame] | 179 | if(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 180 | close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd); |
| 181 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 182 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 183 | |
| 184 | if(ctx->mExtDisplay) { |
| 185 | delete ctx->mExtDisplay; |
| 186 | ctx->mExtDisplay = NULL; |
| 187 | } |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 188 | |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 189 | for(int i = 0; i < MAX_DISPLAYS; i++) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 190 | if(ctx->mFBUpdate[i]) { |
| 191 | delete ctx->mFBUpdate[i]; |
| 192 | ctx->mFBUpdate[i] = NULL; |
| 193 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 194 | if(ctx->mVidOv[i]) { |
| 195 | delete ctx->mVidOv[i]; |
| 196 | ctx->mVidOv[i] = NULL; |
| 197 | } |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 200 | if(ctx->mMDPComp) { |
| 201 | delete ctx->mMDPComp; |
| 202 | ctx->mMDPComp = NULL; |
| 203 | } |
| 204 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 205 | pthread_mutex_destroy(&(ctx->vstate.lock)); |
| 206 | pthread_cond_destroy(&(ctx->vstate.cond)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 209 | |
| 210 | void dumpsys_log(android::String8& buf, const char* fmt, ...) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 211 | { |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 212 | va_list varargs; |
| 213 | va_start(varargs, fmt); |
| 214 | buf.appendFormatV(fmt, varargs); |
| 215 | va_end(varargs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 218 | /* Calculates the destination position based on the action safe rectangle */ |
| 219 | void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x, |
| 220 | uint32_t& y, uint32_t& w, uint32_t& h) { |
| 221 | |
| 222 | // if external supports underscan, do nothing |
| 223 | // it will be taken care in the driver |
| 224 | if(ctx->mExtDisplay->isCEUnderscanSupported()) |
| 225 | return; |
| 226 | |
| 227 | float wRatio = 1.0; |
| 228 | float hRatio = 1.0; |
| 229 | float xRatio = 1.0; |
| 230 | float yRatio = 1.0; |
| 231 | |
| 232 | float fbWidth = ctx->dpyAttr[dpy].xres; |
| 233 | float fbHeight = ctx->dpyAttr[dpy].yres; |
| 234 | |
| 235 | float asX = 0; |
| 236 | float asY = 0; |
| 237 | float asW = fbWidth; |
| 238 | float asH= fbHeight; |
| 239 | char value[PROPERTY_VALUE_MAX]; |
| 240 | |
| 241 | // Apply action safe parameters |
| 242 | property_get("hw.actionsafe.width", value, "0"); |
| 243 | int asWidthRatio = atoi(value); |
| 244 | property_get("hw.actionsafe.height", value, "0"); |
| 245 | int asHeightRatio = atoi(value); |
| 246 | // based on the action safe ratio, get the Action safe rectangle |
| 247 | asW = fbWidth * (1.0f - asWidthRatio / 100.0f); |
| 248 | asH = fbHeight * (1.0f - asHeightRatio / 100.0f); |
| 249 | asX = (fbWidth - asW) / 2; |
| 250 | asY = (fbHeight - asH) / 2; |
| 251 | |
| 252 | // calculate the position ratio |
| 253 | xRatio = (float)x/fbWidth; |
| 254 | yRatio = (float)y/fbHeight; |
| 255 | wRatio = (float)w/fbWidth; |
| 256 | hRatio = (float)h/fbHeight; |
| 257 | |
| 258 | //Calculate the position... |
| 259 | x = (xRatio * asW) + asX; |
| 260 | y = (yRatio * asH) + asY; |
| 261 | w = (wRatio * asW); |
| 262 | h = (hRatio * asH); |
| 263 | |
| 264 | return; |
| 265 | } |
| 266 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 267 | bool needsScaling(hwc_layer_1_t const* layer) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 268 | int dst_w, dst_h, src_w, src_h; |
| 269 | |
| 270 | hwc_rect_t displayFrame = layer->displayFrame; |
| 271 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 272 | |
| 273 | dst_w = displayFrame.right - displayFrame.left; |
| 274 | dst_h = displayFrame.bottom - displayFrame.top; |
| 275 | |
| 276 | src_w = sourceCrop.right - sourceCrop.left; |
| 277 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 278 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 279 | if(((src_w != dst_w) || (src_h != dst_h))) |
| 280 | return true; |
| 281 | |
| 282 | return false; |
| 283 | } |
| 284 | |
| 285 | bool isAlphaScaled(hwc_layer_1_t const* layer) { |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 286 | if(needsScaling(layer) && isAlphaPresent(layer)) { |
| 287 | return true; |
| 288 | } |
| 289 | return false; |
| 290 | } |
| 291 | |
| 292 | bool isAlphaPresent(hwc_layer_1_t const* layer) { |
| 293 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | 7a4287c | 2013-03-26 18:11:41 -0400 | [diff] [blame] | 294 | if(hnd) { |
| 295 | int format = hnd->format; |
| 296 | switch(format) { |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 297 | case HAL_PIXEL_FORMAT_RGBA_8888: |
| 298 | case HAL_PIXEL_FORMAT_BGRA_8888: |
| 299 | // In any more formats with Alpha go here.. |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 300 | return true; |
Sravan Kumar D.V.N | 075ef00 | 2013-03-20 05:22:26 +0530 | [diff] [blame] | 301 | default : return false; |
Naseer Ahmed | 7a4287c | 2013-03-26 18:11:41 -0400 | [diff] [blame] | 302 | } |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 303 | } |
| 304 | return false; |
| 305 | } |
| 306 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 307 | void setListStats(hwc_context_t *ctx, |
| 308 | const hwc_display_contents_1_t *list, int dpy) { |
| 309 | |
| 310 | ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1; |
| 311 | ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 312 | ctx->listStats[dpy].skipCount = 0; |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 313 | ctx->listStats[dpy].needsAlphaScale = false; |
Sravan Kumar D.V.N | b5ed029 | 2013-03-15 08:51:16 +0530 | [diff] [blame] | 314 | ctx->listStats[dpy].preMultipliedAlpha = false; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 315 | ctx->listStats[dpy].yuvCount = 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 316 | |
| 317 | for (size_t i = 0; i < list->numHwLayers; i++) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 318 | hwc_layer_1_t const* layer = &list->hwLayers[i]; |
| 319 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 320 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 321 | //reset stored yuv index |
| 322 | ctx->listStats[dpy].yuvIndices[i] = -1; |
| 323 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 324 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 325 | continue; |
| 326 | //We disregard FB being skip for now! so the else if |
Saurabh Shah | 35712cb | 2012-09-14 10:28:18 -0700 | [diff] [blame] | 327 | } else if (isSkipLayer(&list->hwLayers[i])) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 328 | ctx->listStats[dpy].skipCount++; |
Jeykumar Sankaran | 7535aba | 2013-02-04 11:03:09 -0800 | [diff] [blame] | 329 | } else if (UNLIKELY(isYuvBuffer(hnd))) { |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 330 | int& yuvCount = ctx->listStats[dpy].yuvCount; |
| 331 | ctx->listStats[dpy].yuvIndices[yuvCount] = i; |
| 332 | yuvCount++; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 333 | |
Jeykumar Sankaran | a37fdbf | 2013-03-06 18:59:28 -0800 | [diff] [blame] | 334 | if(layer->transform & HWC_TRANSFORM_ROT_90) |
| 335 | ctx->mNeedsRotator = true; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 336 | } |
Sravan Kumar D.V.N | b5ed029 | 2013-03-15 08:51:16 +0530 | [diff] [blame] | 337 | if(layer->blending == HWC_BLENDING_PREMULT) |
| 338 | ctx->listStats[dpy].preMultipliedAlpha = true; |
Jeykumar Sankaran | 7535aba | 2013-02-04 11:03:09 -0800 | [diff] [blame] | 339 | |
| 340 | if(!ctx->listStats[dpy].needsAlphaScale) |
| 341 | ctx->listStats[dpy].needsAlphaScale = isAlphaScaled(layer); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 342 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 345 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 346 | static inline void calc_cut(float& leftCutRatio, float& topCutRatio, |
| 347 | float& rightCutRatio, float& bottomCutRatio, int orient) { |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 348 | if(orient & HAL_TRANSFORM_FLIP_H) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 349 | swap(leftCutRatio, rightCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 350 | } |
| 351 | if(orient & HAL_TRANSFORM_FLIP_V) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 352 | swap(topCutRatio, bottomCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 353 | } |
| 354 | if(orient & HAL_TRANSFORM_ROT_90) { |
| 355 | //Anti clock swapping |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 356 | float tmpCutRatio = leftCutRatio; |
| 357 | leftCutRatio = topCutRatio; |
| 358 | topCutRatio = rightCutRatio; |
| 359 | rightCutRatio = bottomCutRatio; |
| 360 | bottomCutRatio = tmpCutRatio; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 364 | bool isSecuring(hwc_context_t* ctx) { |
| 365 | if((ctx->mMDP.version < qdutils::MDSS_V5) && |
| 366 | (ctx->mMDP.version > qdutils::MDP_V3_0) && |
| 367 | ctx->mSecuring) { |
| 368 | return true; |
| 369 | } |
| 370 | return false; |
| 371 | } |
| 372 | |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 373 | bool isSecureModePolicy(int mdpVersion) { |
| 374 | if (mdpVersion < qdutils::MDSS_V5) |
| 375 | return true; |
| 376 | else |
| 377 | return false; |
| 378 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 379 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 380 | //Crops source buffer against destination and FB boundaries |
| 381 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 382 | const hwc_rect_t& scissor, int orient) { |
| 383 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 384 | int& crop_l = crop.left; |
| 385 | int& crop_t = crop.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 386 | int& crop_r = crop.right; |
| 387 | int& crop_b = crop.bottom; |
| 388 | int crop_w = crop.right - crop.left; |
| 389 | int crop_h = crop.bottom - crop.top; |
| 390 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 391 | int& dst_l = dst.left; |
| 392 | int& dst_t = dst.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 393 | int& dst_r = dst.right; |
| 394 | int& dst_b = dst.bottom; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 395 | int dst_w = abs(dst.right - dst.left); |
| 396 | int dst_h = abs(dst.bottom - dst.top); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 397 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 398 | const int& sci_l = scissor.left; |
| 399 | const int& sci_t = scissor.top; |
| 400 | const int& sci_r = scissor.right; |
| 401 | const int& sci_b = scissor.bottom; |
| 402 | int sci_w = abs(sci_r - sci_l); |
| 403 | int sci_h = abs(sci_b - sci_t); |
| 404 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 405 | float leftCutRatio = 0.0f, rightCutRatio = 0.0f, topCutRatio = 0.0f, |
| 406 | bottomCutRatio = 0.0f; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 407 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 408 | if(dst_l < sci_l) { |
| 409 | leftCutRatio = (float)(sci_l - dst_l) / (float)dst_w; |
| 410 | dst_l = sci_l; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 411 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 412 | |
| 413 | if(dst_r > sci_r) { |
| 414 | rightCutRatio = (float)(dst_r - sci_r) / (float)dst_w; |
| 415 | dst_r = sci_r; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 416 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 417 | |
| 418 | if(dst_t < sci_t) { |
| 419 | topCutRatio = (float)(sci_t - dst_t) / (float)dst_h; |
| 420 | dst_t = sci_t; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 421 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 422 | |
| 423 | if(dst_b > sci_b) { |
| 424 | bottomCutRatio = (float)(dst_b - sci_b) / (float)dst_h; |
| 425 | dst_b = sci_b; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 426 | } |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 427 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 428 | calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient); |
| 429 | crop_l += crop_w * leftCutRatio; |
| 430 | crop_t += crop_h * topCutRatio; |
| 431 | crop_r -= crop_w * rightCutRatio; |
| 432 | crop_b -= crop_h * bottomCutRatio; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 433 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 434 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 435 | void getNonWormholeRegion(hwc_display_contents_1_t* list, |
| 436 | hwc_rect_t& nwr) |
| 437 | { |
| 438 | uint32_t last = list->numHwLayers - 1; |
| 439 | hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame; |
| 440 | //Initiliaze nwr to first frame |
| 441 | nwr.left = list->hwLayers[0].displayFrame.left; |
| 442 | nwr.top = list->hwLayers[0].displayFrame.top; |
| 443 | nwr.right = list->hwLayers[0].displayFrame.right; |
| 444 | nwr.bottom = list->hwLayers[0].displayFrame.bottom; |
| 445 | |
| 446 | for (uint32_t i = 1; i < last; i++) { |
| 447 | hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; |
| 448 | nwr.left = min(nwr.left, displayFrame.left); |
| 449 | nwr.top = min(nwr.top, displayFrame.top); |
| 450 | nwr.right = max(nwr.right, displayFrame.right); |
| 451 | nwr.bottom = max(nwr.bottom, displayFrame.bottom); |
| 452 | } |
| 453 | |
| 454 | //Intersect with the framebuffer |
| 455 | nwr.left = max(nwr.left, fbDisplayFrame.left); |
| 456 | nwr.top = max(nwr.top, fbDisplayFrame.top); |
| 457 | nwr.right = min(nwr.right, fbDisplayFrame.right); |
| 458 | nwr.bottom = min(nwr.bottom, fbDisplayFrame.bottom); |
| 459 | |
| 460 | } |
| 461 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 462 | bool isExternalActive(hwc_context_t* ctx) { |
| 463 | return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive; |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 466 | void closeAcquireFds(hwc_display_contents_1_t* list) { |
| 467 | for(uint32_t i = 0; list && i < list->numHwLayers; i++) { |
| 468 | //Close the acquireFenceFds |
| 469 | //HWC_FRAMEBUFFER are -1 already by SF, rest we close. |
| 470 | if(list->hwLayers[i].acquireFenceFd >= 0) { |
| 471 | close(list->hwLayers[i].acquireFenceFd); |
| 472 | list->hwLayers[i].acquireFenceFd = -1; |
| 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 477 | int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy, |
| 478 | int fd) { |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 479 | int ret = 0; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 480 | struct mdp_buf_sync data; |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 481 | int acquireFd[MAX_NUM_LAYERS]; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 482 | int count = 0; |
| 483 | int releaseFd = -1; |
| 484 | int fbFd = -1; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 485 | memset(&data, 0, sizeof(data)); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 486 | bool swapzero = false; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 487 | data.flags = MDP_BUF_SYNC_FLAG_WAIT; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 488 | data.acq_fen_fd = acquireFd; |
| 489 | data.rel_fen_fd = &releaseFd; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 490 | char property[PROPERTY_VALUE_MAX]; |
| 491 | if(property_get("debug.egl.swapinterval", property, "1") > 0) { |
| 492 | if(atoi(property) == 0) |
| 493 | swapzero = true; |
| 494 | } |
| 495 | |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 496 | //Accumulate acquireFenceFds |
| 497 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 498 | if(list->hwLayers[i].compositionType == HWC_OVERLAY && |
| 499 | list->hwLayers[i].acquireFenceFd != -1) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 500 | if(UNLIKELY(swapzero)) |
| 501 | acquireFd[count++] = -1; |
| 502 | else |
| 503 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 504 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 505 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 506 | if(UNLIKELY(swapzero)) |
| 507 | acquireFd[count++] = -1; |
| 508 | else if(fd != -1) { |
| 509 | //set the acquireFD from fd - which is coming from c2d |
| 510 | acquireFd[count++] = fd; |
| 511 | // Buffer sync IOCTL should be async when using c2d fence is |
| 512 | // used |
| 513 | data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT; |
| 514 | } else if(list->hwLayers[i].acquireFenceFd != -1) |
| 515 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
| 516 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 519 | data.acq_fen_fd_cnt = count; |
| 520 | fbFd = ctx->dpyAttr[dpy].fd; |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 521 | //Waits for acquire fences, returns a release fence |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 522 | if(LIKELY(!swapzero)) { |
| 523 | uint64_t start = systemTime(); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 524 | ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 525 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d", |
| 526 | __FUNCTION__, (size_t) ns2ms(systemTime() - start)); |
| 527 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 528 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 529 | if(ret < 0) { |
| 530 | ALOGE("ioctl MSMFB_BUFFER_SYNC failed, err=%s", |
| 531 | strerror(errno)); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 532 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 533 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 534 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 535 | if(list->hwLayers[i].compositionType == HWC_OVERLAY || |
| 536 | list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 537 | //Populate releaseFenceFds. |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 538 | if(UNLIKELY(swapzero)) |
| 539 | list->hwLayers[i].releaseFenceFd = -1; |
| 540 | else |
| 541 | list->hwLayers[i].releaseFenceFd = dup(releaseFd); |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 544 | |
| 545 | if(fd >= 0) { |
| 546 | close(fd); |
| 547 | fd = -1; |
| 548 | } |
| 549 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 550 | if (ctx->mCopyBit[dpy]) |
| 551 | ctx->mCopyBit[dpy]->setReleaseFd(releaseFd); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 552 | if(UNLIKELY(swapzero)){ |
| 553 | list->retireFenceFd = -1; |
| 554 | close(releaseFd); |
| 555 | } else { |
| 556 | list->retireFenceFd = releaseFd; |
| 557 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 558 | |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 559 | return ret; |
| 560 | } |
| 561 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 562 | void trimLayer(hwc_context_t *ctx, const int& dpy, const int& transform, |
| 563 | hwc_rect_t& crop, hwc_rect_t& dst) { |
| 564 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 565 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 566 | if(dst.left < 0 || dst.top < 0 || |
| 567 | dst.right > hw_w || dst.bottom > hw_h) { |
| 568 | hwc_rect_t scissor = {0, 0, hw_w, hw_h }; |
| 569 | qhwc::calculate_crop_rects(crop, dst, scissor, transform); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | void setMdpFlags(hwc_layer_1_t *layer, |
| 574 | ovutils::eMdpFlags &mdpFlags, |
| 575 | int rotDownscale) { |
| 576 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 577 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 578 | const int& transform = layer->transform; |
| 579 | |
| 580 | if(layer->blending == HWC_BLENDING_PREMULT) { |
| 581 | ovutils::setMdpFlags(mdpFlags, |
| 582 | ovutils::OV_MDP_BLEND_FG_PREMULT); |
| 583 | } |
| 584 | |
| 585 | if(isYuvBuffer(hnd)) { |
| 586 | if(isSecureBuffer(hnd)) { |
| 587 | ovutils::setMdpFlags(mdpFlags, |
| 588 | ovutils::OV_MDP_SECURE_OVERLAY_SESSION); |
| 589 | } |
| 590 | if(metadata && (metadata->operation & PP_PARAM_INTERLACED) && |
| 591 | metadata->interlaced) { |
| 592 | ovutils::setMdpFlags(mdpFlags, |
| 593 | ovutils::OV_MDP_DEINTERLACE); |
| 594 | } |
| 595 | //Pre-rotation will be used using rotator. |
| 596 | if(transform & HWC_TRANSFORM_ROT_90) { |
| 597 | ovutils::setMdpFlags(mdpFlags, |
| 598 | ovutils::OV_MDP_SOURCE_ROTATED_90); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | //No 90 component and no rot-downscale then flips done by MDP |
| 603 | //If we use rot then it might as well do flips |
| 604 | if(!(layer->transform & HWC_TRANSFORM_ROT_90) && !rotDownscale) { |
| 605 | if(layer->transform & HWC_TRANSFORM_FLIP_H) { |
| 606 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_H); |
| 607 | } |
| 608 | |
| 609 | if(layer->transform & HWC_TRANSFORM_FLIP_V) { |
| 610 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_FLIP_V); |
| 611 | } |
| 612 | } |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 613 | |
| 614 | if(metadata && |
| 615 | ((metadata->operation & PP_PARAM_HSIC) |
| 616 | || (metadata->operation & PP_PARAM_IGC) |
| 617 | || (metadata->operation & PP_PARAM_SHARP2))) { |
| 618 | ovutils::setMdpFlags(mdpFlags, ovutils::OV_MDP_PP_EN); |
| 619 | } |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static inline int configRotator(Rotator *rot, const Whf& whf, |
| 623 | const eMdpFlags& mdpFlags, const eTransform& orient, |
| 624 | const int& downscale) { |
| 625 | rot->setSource(whf); |
| 626 | rot->setFlags(mdpFlags); |
| 627 | rot->setTransform(orient); |
| 628 | rot->setDownscale(downscale); |
| 629 | if(!rot->commit()) return -1; |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | static inline int configMdp(Overlay *ov, const PipeArgs& parg, |
| 634 | const eTransform& orient, const hwc_rect_t& crop, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 635 | const hwc_rect_t& pos, const MetaData_t *metadata, |
| 636 | const eDest& dest) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 637 | ov->setSource(parg, dest); |
| 638 | ov->setTransform(orient, dest); |
| 639 | |
| 640 | int crop_w = crop.right - crop.left; |
| 641 | int crop_h = crop.bottom - crop.top; |
| 642 | Dim dcrop(crop.left, crop.top, crop_w, crop_h); |
| 643 | ov->setCrop(dcrop, dest); |
| 644 | |
| 645 | int posW = pos.right - pos.left; |
| 646 | int posH = pos.bottom - pos.top; |
| 647 | Dim position(pos.left, pos.top, posW, posH); |
| 648 | ov->setPosition(position, dest); |
| 649 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 650 | if (metadata) |
| 651 | ov->setVisualParams(*metadata, dest); |
| 652 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 653 | if (!ov->commit(dest)) { |
| 654 | return -1; |
| 655 | } |
| 656 | return 0; |
| 657 | } |
| 658 | |
| 659 | static inline void updateSource(eTransform& orient, Whf& whf, |
| 660 | hwc_rect_t& crop) { |
| 661 | Dim srcCrop(crop.left, crop.top, |
| 662 | crop.right - crop.left, |
| 663 | crop.bottom - crop.top); |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 664 | //getMdpOrient will switch the flips if the source is 90 rotated. |
| 665 | //Clients in Android dont factor in 90 rotation while deciding the flip. |
| 666 | orient = static_cast<eTransform>(ovutils::getMdpOrient(orient)); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 667 | preRotateSource(orient, whf, srcCrop); |
| 668 | crop.left = srcCrop.x; |
| 669 | crop.top = srcCrop.y; |
| 670 | crop.right = srcCrop.x + srcCrop.w; |
| 671 | crop.bottom = srcCrop.y + srcCrop.h; |
| 672 | } |
| 673 | |
| 674 | int configureLowRes(hwc_context_t *ctx, hwc_layer_1_t *layer, |
| 675 | const int& dpy, eMdpFlags& mdpFlags, const eZorder& z, |
| 676 | const eIsFg& isFg, const eDest& dest, Rotator **rot) { |
| 677 | |
| 678 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 679 | if(!hnd) { |
| 680 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 681 | return -1; |
| 682 | } |
| 683 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 684 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 685 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 686 | hwc_rect_t crop = layer->sourceCrop; |
| 687 | hwc_rect_t dst = layer->displayFrame; |
| 688 | int transform = layer->transform; |
| 689 | eTransform orient = static_cast<eTransform>(transform); |
| 690 | int downscale = 0; |
| 691 | int rotFlags = ovutils::ROT_FLAGS_NONE; |
| 692 | Whf whf(hnd->width, hnd->height, |
| 693 | getMdpFormat(hnd->format), hnd->size); |
| 694 | |
| 695 | if(isYuvBuffer(hnd) && ctx->mMDP.version >= qdutils::MDP_V4_2 && |
| 696 | ctx->mMDP.version < qdutils::MDSS_V5) { |
| 697 | downscale = getDownscaleFactor( |
| 698 | crop.right - crop.left, |
| 699 | crop.bottom - crop.top, |
| 700 | dst.right - dst.left, |
| 701 | dst.bottom - dst.top); |
| 702 | if(downscale) { |
| 703 | rotFlags = ROT_DOWNSCALE_ENABLED; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | setMdpFlags(layer, mdpFlags, downscale); |
| 708 | trimLayer(ctx, dpy, transform, crop, dst); |
| 709 | |
| 710 | if(isYuvBuffer(hnd) && //if 90 component or downscale, use rot |
| 711 | ((transform & HWC_TRANSFORM_ROT_90) || downscale)) { |
| 712 | *rot = ctx->mRotMgr->getNext(); |
| 713 | if(*rot == NULL) return -1; |
| 714 | //Configure rotator for pre-rotation |
| 715 | if(configRotator(*rot, whf, mdpFlags, orient, downscale) < 0) |
| 716 | return -1; |
| 717 | whf.format = (*rot)->getDstFormat(); |
| 718 | updateSource(orient, whf, crop); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 719 | rotFlags |= ovutils::ROT_PREROTATED; |
| 720 | } |
| 721 | |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 722 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 723 | orient = OVERLAY_TRANSFORM_0; |
| 724 | transform = 0; |
| 725 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 726 | PipeArgs parg(mdpFlags, whf, z, isFg, static_cast<eRotFlags>(rotFlags)); |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 727 | if(configMdp(ctx->mOverlay, parg, orient, crop, dst, metadata, dest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 728 | ALOGE("%s: commit failed for low res panel", __FUNCTION__); |
| 729 | return -1; |
| 730 | } |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | int configureHighRes(hwc_context_t *ctx, hwc_layer_1_t *layer, |
| 735 | const int& dpy, eMdpFlags& mdpFlagsL, const eZorder& z, |
| 736 | const eIsFg& isFg, const eDest& lDest, const eDest& rDest, |
| 737 | Rotator **rot) { |
| 738 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
| 739 | if(!hnd) { |
| 740 | ALOGE("%s: layer handle is NULL", __FUNCTION__); |
| 741 | return -1; |
| 742 | } |
| 743 | |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 744 | MetaData_t *metadata = (MetaData_t *)hnd->base_metadata; |
| 745 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 746 | int hw_w = ctx->dpyAttr[dpy].xres; |
| 747 | int hw_h = ctx->dpyAttr[dpy].yres; |
| 748 | hwc_rect_t crop = layer->sourceCrop; |
| 749 | hwc_rect_t dst = layer->displayFrame; |
| 750 | int transform = layer->transform; |
| 751 | eTransform orient = static_cast<eTransform>(transform); |
| 752 | const int downscale = 0; |
| 753 | int rotFlags = ROT_FLAGS_NONE; |
| 754 | |
| 755 | Whf whf(hnd->width, hnd->height, |
| 756 | getMdpFormat(hnd->format), hnd->size); |
| 757 | |
| 758 | setMdpFlags(layer, mdpFlagsL); |
| 759 | trimLayer(ctx, dpy, transform, crop, dst); |
| 760 | |
| 761 | if(isYuvBuffer(hnd) && (transform & HWC_TRANSFORM_ROT_90)) { |
| 762 | (*rot) = ctx->mRotMgr->getNext(); |
| 763 | if((*rot) == NULL) return -1; |
| 764 | //Configure rotator for pre-rotation |
| 765 | if(configRotator(*rot, whf, mdpFlagsL, orient, downscale) < 0) |
| 766 | return -1; |
| 767 | whf.format = (*rot)->getDstFormat(); |
| 768 | updateSource(orient, whf, crop); |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 769 | rotFlags |= ROT_PREROTATED; |
| 770 | } |
| 771 | |
| 772 | eMdpFlags mdpFlagsR = mdpFlagsL; |
| 773 | setMdpFlags(mdpFlagsR, OV_MDSS_MDP_RIGHT_MIXER); |
| 774 | |
| 775 | hwc_rect_t tmp_cropL, tmp_dstL; |
| 776 | hwc_rect_t tmp_cropR, tmp_dstR; |
| 777 | |
| 778 | if(lDest != OV_INVALID) { |
| 779 | tmp_cropL = crop; |
| 780 | tmp_dstL = dst; |
| 781 | hwc_rect_t scissor = {0, 0, hw_w/2, hw_h }; |
| 782 | qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0); |
| 783 | } |
| 784 | if(rDest != OV_INVALID) { |
| 785 | tmp_cropR = crop; |
| 786 | tmp_dstR = dst; |
| 787 | hwc_rect_t scissor = {hw_w/2, 0, hw_w, hw_h }; |
| 788 | qhwc::calculate_crop_rects(tmp_cropR, tmp_dstR, scissor, 0); |
| 789 | } |
| 790 | |
| 791 | //When buffer is flipped, contents of mixer config also needs to swapped. |
| 792 | //Not needed if the layer is confined to one half of the screen. |
| 793 | //If rotator has been used then it has also done the flips, so ignore them. |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 794 | if((orient & OVERLAY_TRANSFORM_FLIP_V) && lDest != OV_INVALID |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 795 | && rDest != OV_INVALID && rot == NULL) { |
| 796 | hwc_rect_t new_cropR; |
| 797 | new_cropR.left = tmp_cropL.left; |
| 798 | new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left); |
| 799 | |
| 800 | hwc_rect_t new_cropL; |
| 801 | new_cropL.left = new_cropR.right; |
| 802 | new_cropL.right = tmp_cropR.right; |
| 803 | |
| 804 | tmp_cropL.left = new_cropL.left; |
| 805 | tmp_cropL.right = new_cropL.right; |
| 806 | |
| 807 | tmp_cropR.left = new_cropR.left; |
| 808 | tmp_cropR.right = new_cropR.right; |
| 809 | |
| 810 | } |
| 811 | |
Saurabh Shah | 76fd655 | 2013-03-14 14:45:38 -0700 | [diff] [blame] | 812 | //For the mdp, since either we are pre-rotating or MDP does flips |
| 813 | orient = OVERLAY_TRANSFORM_0; |
| 814 | transform = 0; |
| 815 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 816 | //configure left mixer |
| 817 | if(lDest != OV_INVALID) { |
| 818 | PipeArgs pargL(mdpFlagsL, whf, z, isFg, |
| 819 | static_cast<eRotFlags>(rotFlags)); |
| 820 | if(configMdp(ctx->mOverlay, pargL, orient, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 821 | tmp_cropL, tmp_dstL, metadata, lDest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 822 | ALOGE("%s: commit failed for left mixer config", __FUNCTION__); |
| 823 | return -1; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | //configure right mixer |
| 828 | if(rDest != OV_INVALID) { |
| 829 | PipeArgs pargR(mdpFlagsR, whf, z, isFg, |
| 830 | static_cast<eRotFlags>(rotFlags)); |
Arun Kumar K.R | 0e8efb8 | 2013-03-18 17:31:50 -0700 | [diff] [blame] | 831 | tmp_dstR.right = tmp_dstR.right - tmp_dstR.left; |
| 832 | tmp_dstR.left = 0; |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 833 | if(configMdp(ctx->mOverlay, pargR, orient, |
Saurabh Shah | 5daeee5 | 2013-01-23 16:52:26 +0800 | [diff] [blame] | 834 | tmp_cropR, tmp_dstR, metadata, rDest) < 0) { |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 835 | ALOGE("%s: commit failed for right mixer config", __FUNCTION__); |
| 836 | return -1; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return 0; |
| 841 | } |
| 842 | |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 843 | void LayerCache::resetLayerCache(int num) { |
| 844 | for(uint32_t i = 0; i < MAX_NUM_LAYERS; i++) { |
| 845 | hnd[i] = NULL; |
| 846 | } |
| 847 | numHwLayers = num; |
| 848 | } |
| 849 | |
| 850 | void LayerCache::updateLayerCache(hwc_display_contents_1_t* list) { |
| 851 | |
| 852 | int numFbLayers = 0; |
| 853 | int numCacheableLayers = 0; |
| 854 | |
| 855 | canUseLayerCache = false; |
| 856 | //Bail if geometry changed or num of layers changed |
| 857 | if(list->flags & HWC_GEOMETRY_CHANGED || |
| 858 | list->numHwLayers != numHwLayers ) { |
| 859 | resetLayerCache(list->numHwLayers); |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
| 864 | //Bail on skip layers |
| 865 | if(list->hwLayers[i].flags & HWC_SKIP_LAYER) { |
| 866 | resetLayerCache(list->numHwLayers); |
| 867 | return; |
| 868 | } |
| 869 | |
| 870 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER) { |
| 871 | numFbLayers++; |
| 872 | if(hnd[i] == NULL) { |
| 873 | hnd[i] = list->hwLayers[i].handle; |
| 874 | } else if (hnd[i] == |
| 875 | list->hwLayers[i].handle) { |
| 876 | numCacheableLayers++; |
| 877 | } else { |
| 878 | hnd[i] = NULL; |
| 879 | return; |
| 880 | } |
| 881 | } else { |
| 882 | hnd[i] = NULL; |
| 883 | } |
| 884 | } |
| 885 | if(numFbLayers == numCacheableLayers) |
| 886 | canUseLayerCache = true; |
| 887 | |
| 888 | //XXX: The marking part is separate, if MDP comp wants |
| 889 | // to use it in the future. Right now getting MDP comp |
| 890 | // to use this is more trouble than it is worth. |
| 891 | markCachedLayersAsOverlay(list); |
| 892 | } |
| 893 | |
| 894 | void LayerCache::markCachedLayersAsOverlay(hwc_display_contents_1_t* list) { |
| 895 | //This optimization only works if ALL the layer handles |
| 896 | //that were on the framebuffer didn't change. |
| 897 | if(canUseLayerCache){ |
| 898 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
| 899 | if (list->hwLayers[i].handle && |
| 900 | list->hwLayers[i].handle == hnd[i] && |
| 901 | list->hwLayers[i].compositionType != HWC_FRAMEBUFFER_TARGET) |
| 902 | { |
| 903 | list->hwLayers[i].compositionType = HWC_OVERLAY; |
| 904 | } |
| 905 | } |
| 906 | } |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 907 | } |
| 908 | |
Saurabh Shah | acf1020 | 2013-02-26 10:15:15 -0800 | [diff] [blame] | 909 | };//namespace qhwc |