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> |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 22 | #include <binder/IServiceManager.h> |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 24 | #include <cutils/properties.h> |
| 25 | #include <gralloc_priv.h> |
| 26 | #include <fb_priv.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 27 | #include <overlay.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 28 | #include "hwc_utils.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 29 | #include "hwc_mdpcomp.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 30 | #include "hwc_fbupdate.h" |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 31 | #include "mdp_version.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 32 | #include "hwc_copybit.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 33 | #include "external.h" |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 34 | #include "hwc_qclient.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 35 | #include "QService.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 36 | #include "comptype.h" |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 37 | |
| 38 | using namespace qClient; |
| 39 | using namespace qService; |
| 40 | using namespace android; |
| 41 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 42 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 43 | |
| 44 | // Opens Framebuffer device |
| 45 | static void openFramebufferDevice(hwc_context_t *ctx) |
| 46 | { |
| 47 | hw_module_t const *module; |
| 48 | if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { |
| 49 | framebuffer_open(module, &(ctx->mFbDev)); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 50 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 51 | ctx->mFbDev->common.module); |
| 52 | //xres, yres may not be 32 aligned |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 53 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = m->finfo.line_length / |
| 54 | (m->info.xres/8); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 55 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = m->info.xres; |
| 56 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = m->info.yres; |
| 57 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = ctx->mFbDev->xdpi; |
| 58 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ctx->mFbDev->ydpi; |
| 59 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = |
| 60 | 1000000000l / ctx->mFbDev->fps; |
| 61 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = openFb(HWC_DISPLAY_PRIMARY); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 65 | void initContext(hwc_context_t *ctx) |
| 66 | { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 67 | openFramebufferDevice(ctx); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 68 | overlay::Overlay::initOverlay(); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 69 | ctx->mOverlay = overlay::Overlay::getInstance(); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 70 | ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 71 | ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); |
| 72 | ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 73 | //Is created and destroyed only once for primary |
| 74 | //For external it could get created and destroyed multiple times depending |
| 75 | //on what external we connect to. |
| 76 | ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] = |
| 77 | IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres, |
| 78 | HWC_DISPLAY_PRIMARY); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 79 | |
| 80 | char value[PROPERTY_VALUE_MAX]; |
| 81 | // Check if the target supports copybit compostion (dyn/mdp/c2d) to |
| 82 | // decide if we need to open the copybit module. |
| 83 | int compositionType = |
| 84 | qdutils::QCCompositionType::getInstance().getCompositionType(); |
| 85 | |
| 86 | if (compositionType & (qdutils::COMPOSITION_TYPE_DYN | |
| 87 | qdutils::COMPOSITION_TYPE_MDP | |
| 88 | qdutils::COMPOSITION_TYPE_C2D)) { |
| 89 | ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(); |
| 90 | } |
| 91 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 92 | ctx->mExtDisplay = new ExternalDisplay(ctx); |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 93 | for (uint32_t i = 0; i < MAX_DISPLAYS; i++) |
Naseer Ahmed | e78f052 | 2012-12-07 18:24:28 -0500 | [diff] [blame] | 94 | ctx->mLayerCache[i] = new LayerCache(); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 95 | ctx->mMDPComp = MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 96 | MDPComp::init(ctx); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 97 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 98 | pthread_mutex_init(&(ctx->vstate.lock), NULL); |
| 99 | pthread_cond_init(&(ctx->vstate.cond), NULL); |
| 100 | ctx->vstate.enable = false; |
Naseer Ahmed | 56601cd | 2013-03-05 11:34:14 -0500 | [diff] [blame] | 101 | ctx->vstate.fakevsync = false; |
Amara Venkata Mastan Manoj Kumar | 75526f5 | 2012-12-27 18:27:01 -0800 | [diff] [blame] | 102 | ctx->mExtDispConfiguring = false; |
Saurabh Shah | 86c1729 | 2013-02-08 15:24:13 -0800 | [diff] [blame] | 103 | |
| 104 | //Right now hwc starts the service but anybody could do it, or it could be |
| 105 | //independent process as well. |
| 106 | QService::init(); |
| 107 | sp<IQClient> client = new QClient(ctx); |
| 108 | interface_cast<IQService>( |
| 109 | defaultServiceManager()->getService( |
| 110 | String16("display.qservice")))->connect(client); |
| 111 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 112 | ALOGI("Initializing Qualcomm Hardware Composer"); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 113 | ALOGI("MDP version: %d", ctx->mMDP.version); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void closeContext(hwc_context_t *ctx) |
| 117 | { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 118 | if(ctx->mOverlay) { |
| 119 | delete ctx->mOverlay; |
| 120 | ctx->mOverlay = NULL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 121 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 122 | |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 123 | for(int i = 0; i < MAX_DISPLAYS; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 124 | if(ctx->mCopyBit[i]) { |
| 125 | delete ctx->mCopyBit[i]; |
| 126 | ctx->mCopyBit[i] = NULL; |
| 127 | } |
| 128 | } |
| 129 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 130 | if(ctx->mFbDev) { |
| 131 | framebuffer_close(ctx->mFbDev); |
| 132 | ctx->mFbDev = NULL; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 133 | close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd); |
| 134 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 135 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 136 | |
| 137 | if(ctx->mExtDisplay) { |
| 138 | delete ctx->mExtDisplay; |
| 139 | ctx->mExtDisplay = NULL; |
| 140 | } |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 141 | |
Amara Venkata Mastan Manoj Kumar | 11a380d | 2013-01-17 09:30:56 -0800 | [diff] [blame] | 142 | for(int i = 0; i < MAX_DISPLAYS; i++) { |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 143 | if(ctx->mFBUpdate[i]) { |
| 144 | delete ctx->mFBUpdate[i]; |
| 145 | ctx->mFBUpdate[i] = NULL; |
| 146 | } |
| 147 | } |
| 148 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 149 | if(ctx->mMDPComp) { |
| 150 | delete ctx->mMDPComp; |
| 151 | ctx->mMDPComp = NULL; |
| 152 | } |
| 153 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 154 | pthread_mutex_destroy(&(ctx->vstate.lock)); |
| 155 | pthread_cond_destroy(&(ctx->vstate.cond)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 158 | |
| 159 | void dumpsys_log(android::String8& buf, const char* fmt, ...) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 160 | { |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 161 | va_list varargs; |
| 162 | va_start(varargs, fmt); |
| 163 | buf.appendFormatV(fmt, varargs); |
| 164 | va_end(varargs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Arun Kumar K.R | feb2d8a | 2013-02-01 02:53:13 -0800 | [diff] [blame] | 167 | /* Calculates the destination position based on the action safe rectangle */ |
| 168 | void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x, |
| 169 | uint32_t& y, uint32_t& w, uint32_t& h) { |
| 170 | |
| 171 | // if external supports underscan, do nothing |
| 172 | // it will be taken care in the driver |
| 173 | if(ctx->mExtDisplay->isCEUnderscanSupported()) |
| 174 | return; |
| 175 | |
| 176 | float wRatio = 1.0; |
| 177 | float hRatio = 1.0; |
| 178 | float xRatio = 1.0; |
| 179 | float yRatio = 1.0; |
| 180 | |
| 181 | float fbWidth = ctx->dpyAttr[dpy].xres; |
| 182 | float fbHeight = ctx->dpyAttr[dpy].yres; |
| 183 | |
| 184 | float asX = 0; |
| 185 | float asY = 0; |
| 186 | float asW = fbWidth; |
| 187 | float asH= fbHeight; |
| 188 | char value[PROPERTY_VALUE_MAX]; |
| 189 | |
| 190 | // Apply action safe parameters |
| 191 | property_get("hw.actionsafe.width", value, "0"); |
| 192 | int asWidthRatio = atoi(value); |
| 193 | property_get("hw.actionsafe.height", value, "0"); |
| 194 | int asHeightRatio = atoi(value); |
| 195 | // based on the action safe ratio, get the Action safe rectangle |
| 196 | asW = fbWidth * (1.0f - asWidthRatio / 100.0f); |
| 197 | asH = fbHeight * (1.0f - asHeightRatio / 100.0f); |
| 198 | asX = (fbWidth - asW) / 2; |
| 199 | asY = (fbHeight - asH) / 2; |
| 200 | |
| 201 | // calculate the position ratio |
| 202 | xRatio = (float)x/fbWidth; |
| 203 | yRatio = (float)y/fbHeight; |
| 204 | wRatio = (float)w/fbWidth; |
| 205 | hRatio = (float)h/fbHeight; |
| 206 | |
| 207 | //Calculate the position... |
| 208 | x = (xRatio * asW) + asX; |
| 209 | y = (yRatio * asH) + asY; |
| 210 | w = (wRatio * asW); |
| 211 | h = (hRatio * asH); |
| 212 | |
| 213 | return; |
| 214 | } |
| 215 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 216 | bool needsScaling(hwc_layer_1_t const* layer) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 217 | int dst_w, dst_h, src_w, src_h; |
| 218 | |
| 219 | hwc_rect_t displayFrame = layer->displayFrame; |
| 220 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 221 | |
| 222 | dst_w = displayFrame.right - displayFrame.left; |
| 223 | dst_h = displayFrame.bottom - displayFrame.top; |
| 224 | |
| 225 | src_w = sourceCrop.right - sourceCrop.left; |
| 226 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 227 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 228 | if(((src_w != dst_w) || (src_h != dst_h))) |
| 229 | return true; |
| 230 | |
| 231 | return false; |
| 232 | } |
| 233 | |
| 234 | bool isAlphaScaled(hwc_layer_1_t const* layer) { |
| 235 | if(needsScaling(layer)) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 236 | if(layer->blending != HWC_BLENDING_NONE) |
| 237 | return true; |
| 238 | } |
| 239 | return false; |
| 240 | } |
| 241 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 242 | void setListStats(hwc_context_t *ctx, |
| 243 | const hwc_display_contents_1_t *list, int dpy) { |
| 244 | |
| 245 | ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1; |
| 246 | ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 247 | ctx->listStats[dpy].skipCount = 0; |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 248 | ctx->listStats[dpy].needsAlphaScale = false; |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 249 | ctx->listStats[dpy].yuvCount = 0; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 250 | ctx->mDMAInUse = false; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 251 | |
| 252 | for (size_t i = 0; i < list->numHwLayers; i++) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 253 | hwc_layer_1_t const* layer = &list->hwLayers[i]; |
| 254 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 255 | |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 256 | //reset stored yuv index |
| 257 | ctx->listStats[dpy].yuvIndices[i] = -1; |
| 258 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 259 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 260 | continue; |
| 261 | //We disregard FB being skip for now! so the else if |
Saurabh Shah | 35712cb | 2012-09-14 10:28:18 -0700 | [diff] [blame] | 262 | } else if (isSkipLayer(&list->hwLayers[i])) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 263 | ctx->listStats[dpy].skipCount++; |
Jeykumar Sankaran | 7535aba | 2013-02-04 11:03:09 -0800 | [diff] [blame] | 264 | } else if (UNLIKELY(isYuvBuffer(hnd))) { |
Jeykumar Sankaran | cf53700 | 2013-01-21 21:19:15 -0800 | [diff] [blame] | 265 | int& yuvCount = ctx->listStats[dpy].yuvCount; |
| 266 | ctx->listStats[dpy].yuvIndices[yuvCount] = i; |
| 267 | yuvCount++; |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 268 | |
| 269 | if((layer->transform & HWC_TRANSFORM_ROT_90) && !ctx->mDMAInUse) |
| 270 | ctx->mDMAInUse = true; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 271 | } |
Jeykumar Sankaran | 7535aba | 2013-02-04 11:03:09 -0800 | [diff] [blame] | 272 | |
| 273 | if(!ctx->listStats[dpy].needsAlphaScale) |
| 274 | ctx->listStats[dpy].needsAlphaScale = isAlphaScaled(layer); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 275 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 278 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 279 | static inline void calc_cut(float& leftCutRatio, float& topCutRatio, |
| 280 | float& rightCutRatio, float& bottomCutRatio, int orient) { |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 281 | if(orient & HAL_TRANSFORM_FLIP_H) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 282 | swap(leftCutRatio, rightCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 283 | } |
| 284 | if(orient & HAL_TRANSFORM_FLIP_V) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 285 | swap(topCutRatio, bottomCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 286 | } |
| 287 | if(orient & HAL_TRANSFORM_ROT_90) { |
| 288 | //Anti clock swapping |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 289 | float tmpCutRatio = leftCutRatio; |
| 290 | leftCutRatio = topCutRatio; |
| 291 | topCutRatio = rightCutRatio; |
| 292 | rightCutRatio = bottomCutRatio; |
| 293 | bottomCutRatio = tmpCutRatio; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 297 | bool isSecuring(hwc_context_t* ctx) { |
| 298 | if((ctx->mMDP.version < qdutils::MDSS_V5) && |
| 299 | (ctx->mMDP.version > qdutils::MDP_V3_0) && |
| 300 | ctx->mSecuring) { |
| 301 | return true; |
| 302 | } |
| 303 | return false; |
| 304 | } |
| 305 | |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 306 | bool isSecureModePolicy(int mdpVersion) { |
| 307 | if (mdpVersion < qdutils::MDSS_V5) |
| 308 | return true; |
| 309 | else |
| 310 | return false; |
| 311 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 312 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 313 | //Crops source buffer against destination and FB boundaries |
| 314 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 315 | const hwc_rect_t& scissor, int orient) { |
| 316 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 317 | int& crop_l = crop.left; |
| 318 | int& crop_t = crop.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 319 | int& crop_r = crop.right; |
| 320 | int& crop_b = crop.bottom; |
| 321 | int crop_w = crop.right - crop.left; |
| 322 | int crop_h = crop.bottom - crop.top; |
| 323 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 324 | int& dst_l = dst.left; |
| 325 | int& dst_t = dst.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 326 | int& dst_r = dst.right; |
| 327 | int& dst_b = dst.bottom; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 328 | int dst_w = abs(dst.right - dst.left); |
| 329 | int dst_h = abs(dst.bottom - dst.top); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 330 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 331 | const int& sci_l = scissor.left; |
| 332 | const int& sci_t = scissor.top; |
| 333 | const int& sci_r = scissor.right; |
| 334 | const int& sci_b = scissor.bottom; |
| 335 | int sci_w = abs(sci_r - sci_l); |
| 336 | int sci_h = abs(sci_b - sci_t); |
| 337 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 338 | float leftCutRatio = 0.0f, rightCutRatio = 0.0f, topCutRatio = 0.0f, |
| 339 | bottomCutRatio = 0.0f; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 340 | |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 341 | if(dst_l < sci_l) { |
| 342 | leftCutRatio = (float)(sci_l - dst_l) / (float)dst_w; |
| 343 | dst_l = sci_l; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 344 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 345 | |
| 346 | if(dst_r > sci_r) { |
| 347 | rightCutRatio = (float)(dst_r - sci_r) / (float)dst_w; |
| 348 | dst_r = sci_r; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 349 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 350 | |
| 351 | if(dst_t < sci_t) { |
| 352 | topCutRatio = (float)(sci_t - dst_t) / (float)dst_h; |
| 353 | dst_t = sci_t; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 354 | } |
Jeykumar Sankaran | b551ce4 | 2013-01-10 16:26:48 -0800 | [diff] [blame] | 355 | |
| 356 | if(dst_b > sci_b) { |
| 357 | bottomCutRatio = (float)(dst_b - sci_b) / (float)dst_h; |
| 358 | dst_b = sci_b; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 359 | } |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 360 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 361 | calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient); |
| 362 | crop_l += crop_w * leftCutRatio; |
| 363 | crop_t += crop_h * topCutRatio; |
| 364 | crop_r -= crop_w * rightCutRatio; |
| 365 | crop_b -= crop_h * bottomCutRatio; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 366 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 367 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 368 | void getNonWormholeRegion(hwc_display_contents_1_t* list, |
| 369 | hwc_rect_t& nwr) |
| 370 | { |
| 371 | uint32_t last = list->numHwLayers - 1; |
| 372 | hwc_rect_t fbDisplayFrame = list->hwLayers[last].displayFrame; |
| 373 | //Initiliaze nwr to first frame |
| 374 | nwr.left = list->hwLayers[0].displayFrame.left; |
| 375 | nwr.top = list->hwLayers[0].displayFrame.top; |
| 376 | nwr.right = list->hwLayers[0].displayFrame.right; |
| 377 | nwr.bottom = list->hwLayers[0].displayFrame.bottom; |
| 378 | |
| 379 | for (uint32_t i = 1; i < last; i++) { |
| 380 | hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; |
| 381 | nwr.left = min(nwr.left, displayFrame.left); |
| 382 | nwr.top = min(nwr.top, displayFrame.top); |
| 383 | nwr.right = max(nwr.right, displayFrame.right); |
| 384 | nwr.bottom = max(nwr.bottom, displayFrame.bottom); |
| 385 | } |
| 386 | |
| 387 | //Intersect with the framebuffer |
| 388 | nwr.left = max(nwr.left, fbDisplayFrame.left); |
| 389 | nwr.top = max(nwr.top, fbDisplayFrame.top); |
| 390 | nwr.right = min(nwr.right, fbDisplayFrame.right); |
| 391 | nwr.bottom = min(nwr.bottom, fbDisplayFrame.bottom); |
| 392 | |
| 393 | } |
| 394 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 395 | bool isExternalActive(hwc_context_t* ctx) { |
| 396 | return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive; |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 399 | void closeAcquireFds(hwc_display_contents_1_t* list) { |
| 400 | for(uint32_t i = 0; list && i < list->numHwLayers; i++) { |
| 401 | //Close the acquireFenceFds |
| 402 | //HWC_FRAMEBUFFER are -1 already by SF, rest we close. |
| 403 | if(list->hwLayers[i].acquireFenceFd >= 0) { |
| 404 | close(list->hwLayers[i].acquireFenceFd); |
| 405 | list->hwLayers[i].acquireFenceFd = -1; |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 410 | int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy, |
| 411 | int fd) { |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 412 | int ret = 0; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 413 | struct mdp_buf_sync data; |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 414 | int acquireFd[MAX_NUM_LAYERS]; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 415 | int count = 0; |
| 416 | int releaseFd = -1; |
| 417 | int fbFd = -1; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 418 | memset(&data, 0, sizeof(data)); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 419 | bool swapzero = false; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 420 | data.flags = MDP_BUF_SYNC_FLAG_WAIT; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 421 | data.acq_fen_fd = acquireFd; |
| 422 | data.rel_fen_fd = &releaseFd; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 423 | char property[PROPERTY_VALUE_MAX]; |
| 424 | if(property_get("debug.egl.swapinterval", property, "1") > 0) { |
| 425 | if(atoi(property) == 0) |
| 426 | swapzero = true; |
| 427 | } |
| 428 | |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 429 | //Accumulate acquireFenceFds |
| 430 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 431 | if(list->hwLayers[i].compositionType == HWC_OVERLAY && |
| 432 | list->hwLayers[i].acquireFenceFd != -1) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 433 | if(UNLIKELY(swapzero)) |
| 434 | acquireFd[count++] = -1; |
| 435 | else |
| 436 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 437 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 438 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 439 | if(UNLIKELY(swapzero)) |
| 440 | acquireFd[count++] = -1; |
| 441 | else if(fd != -1) { |
| 442 | //set the acquireFD from fd - which is coming from c2d |
| 443 | acquireFd[count++] = fd; |
| 444 | // Buffer sync IOCTL should be async when using c2d fence is |
| 445 | // used |
| 446 | data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT; |
| 447 | } else if(list->hwLayers[i].acquireFenceFd != -1) |
| 448 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
| 449 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 452 | data.acq_fen_fd_cnt = count; |
| 453 | fbFd = ctx->dpyAttr[dpy].fd; |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 454 | //Waits for acquire fences, returns a release fence |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 455 | if(LIKELY(!swapzero)) { |
| 456 | uint64_t start = systemTime(); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 457 | ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 458 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d", |
| 459 | __FUNCTION__, (size_t) ns2ms(systemTime() - start)); |
| 460 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 461 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 462 | if(ret < 0) { |
| 463 | ALOGE("ioctl MSMFB_BUFFER_SYNC failed, err=%s", |
| 464 | strerror(errno)); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 465 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 466 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 467 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 468 | if(list->hwLayers[i].compositionType == HWC_OVERLAY || |
| 469 | list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 470 | //Populate releaseFenceFds. |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 471 | if(UNLIKELY(swapzero)) |
| 472 | list->hwLayers[i].releaseFenceFd = -1; |
| 473 | else |
| 474 | list->hwLayers[i].releaseFenceFd = dup(releaseFd); |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 475 | } |
| 476 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 477 | |
| 478 | if(fd >= 0) { |
| 479 | close(fd); |
| 480 | fd = -1; |
| 481 | } |
| 482 | |
Naseer Ahmed | 64b8121 | 2013-02-14 10:29:47 -0500 | [diff] [blame] | 483 | if (ctx->mCopyBit[dpy]) |
| 484 | ctx->mCopyBit[dpy]->setReleaseFd(releaseFd); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 485 | if(UNLIKELY(swapzero)){ |
| 486 | list->retireFenceFd = -1; |
| 487 | close(releaseFd); |
| 488 | } else { |
| 489 | list->retireFenceFd = releaseFd; |
| 490 | } |
Saurabh Shah | 747af1e | 2013-02-26 10:25:12 -0800 | [diff] [blame] | 491 | |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 492 | return ret; |
| 493 | } |
| 494 | |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 495 | void LayerCache::resetLayerCache(int num) { |
| 496 | for(uint32_t i = 0; i < MAX_NUM_LAYERS; i++) { |
| 497 | hnd[i] = NULL; |
| 498 | } |
| 499 | numHwLayers = num; |
| 500 | } |
| 501 | |
| 502 | void LayerCache::updateLayerCache(hwc_display_contents_1_t* list) { |
| 503 | |
| 504 | int numFbLayers = 0; |
| 505 | int numCacheableLayers = 0; |
| 506 | |
| 507 | canUseLayerCache = false; |
| 508 | //Bail if geometry changed or num of layers changed |
| 509 | if(list->flags & HWC_GEOMETRY_CHANGED || |
| 510 | list->numHwLayers != numHwLayers ) { |
| 511 | resetLayerCache(list->numHwLayers); |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
| 516 | //Bail on skip layers |
| 517 | if(list->hwLayers[i].flags & HWC_SKIP_LAYER) { |
| 518 | resetLayerCache(list->numHwLayers); |
| 519 | return; |
| 520 | } |
| 521 | |
| 522 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER) { |
| 523 | numFbLayers++; |
| 524 | if(hnd[i] == NULL) { |
| 525 | hnd[i] = list->hwLayers[i].handle; |
| 526 | } else if (hnd[i] == |
| 527 | list->hwLayers[i].handle) { |
| 528 | numCacheableLayers++; |
| 529 | } else { |
| 530 | hnd[i] = NULL; |
| 531 | return; |
| 532 | } |
| 533 | } else { |
| 534 | hnd[i] = NULL; |
| 535 | } |
| 536 | } |
| 537 | if(numFbLayers == numCacheableLayers) |
| 538 | canUseLayerCache = true; |
| 539 | |
| 540 | //XXX: The marking part is separate, if MDP comp wants |
| 541 | // to use it in the future. Right now getting MDP comp |
| 542 | // to use this is more trouble than it is worth. |
| 543 | markCachedLayersAsOverlay(list); |
| 544 | } |
| 545 | |
| 546 | void LayerCache::markCachedLayersAsOverlay(hwc_display_contents_1_t* list) { |
| 547 | //This optimization only works if ALL the layer handles |
| 548 | //that were on the framebuffer didn't change. |
| 549 | if(canUseLayerCache){ |
| 550 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
| 551 | if (list->hwLayers[i].handle && |
| 552 | list->hwLayers[i].handle == hnd[i] && |
| 553 | list->hwLayers[i].compositionType != HWC_FRAMEBUFFER_TARGET) |
| 554 | { |
| 555 | list->hwLayers[i].compositionType = HWC_OVERLAY; |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | } |
| 561 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 562 | };//namespace |