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 | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 22 | #include <EGL/egl.h> |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 23 | #include <cutils/properties.h> |
| 24 | #include <gralloc_priv.h> |
| 25 | #include <fb_priv.h> |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 26 | #include <overlay.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 27 | #include "hwc_utils.h" |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 28 | #include "hwc_mdpcomp.h" |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 29 | #include "hwc_fbupdate.h" |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 30 | #include "mdp_version.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 31 | #include "hwc_copybit.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 32 | #include "external.h" |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 33 | #include "QService.h" |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 34 | #include "comptype.h" |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 35 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 36 | |
| 37 | // Opens Framebuffer device |
| 38 | static void openFramebufferDevice(hwc_context_t *ctx) |
| 39 | { |
| 40 | hw_module_t const *module; |
| 41 | if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { |
| 42 | framebuffer_open(module, &(ctx->mFbDev)); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 43 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 44 | ctx->mFbDev->common.module); |
| 45 | //xres, yres may not be 32 aligned |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 46 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].stride = m->finfo.line_length / |
| 47 | (m->info.xres/8); |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 48 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres = m->info.xres; |
| 49 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].yres = m->info.yres; |
| 50 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xdpi = ctx->mFbDev->xdpi; |
| 51 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].ydpi = ctx->mFbDev->ydpi; |
| 52 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period = |
| 53 | 1000000000l / ctx->mFbDev->fps; |
| 54 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = openFb(HWC_DISPLAY_PRIMARY); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 55 | } |
| 56 | } |
| 57 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 58 | void initContext(hwc_context_t *ctx) |
| 59 | { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 60 | openFramebufferDevice(ctx); |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 61 | overlay::Overlay::initOverlay(); |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 62 | ctx->mOverlay = overlay::Overlay::getInstance(); |
Saurabh Shah | 56f610d | 2012-08-07 15:27:06 -0700 | [diff] [blame] | 63 | ctx->mQService = qService::QService::getInstance(ctx); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 64 | ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 65 | ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); |
| 66 | ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 67 | //Is created and destroyed only once for primary |
| 68 | //For external it could get created and destroyed multiple times depending |
| 69 | //on what external we connect to. |
| 70 | ctx->mFBUpdate[HWC_DISPLAY_PRIMARY] = |
| 71 | IFBUpdate::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres, |
| 72 | HWC_DISPLAY_PRIMARY); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 73 | |
| 74 | char value[PROPERTY_VALUE_MAX]; |
| 75 | // Check if the target supports copybit compostion (dyn/mdp/c2d) to |
| 76 | // decide if we need to open the copybit module. |
| 77 | int compositionType = |
| 78 | qdutils::QCCompositionType::getInstance().getCompositionType(); |
| 79 | |
| 80 | if (compositionType & (qdutils::COMPOSITION_TYPE_DYN | |
| 81 | qdutils::COMPOSITION_TYPE_MDP | |
| 82 | qdutils::COMPOSITION_TYPE_C2D)) { |
| 83 | ctx->mCopyBit[HWC_DISPLAY_PRIMARY] = new CopyBit(); |
| 84 | } |
| 85 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 86 | ctx->mExtDisplay = new ExternalDisplay(ctx); |
Naseer Ahmed | e78f052 | 2012-12-07 18:24:28 -0500 | [diff] [blame] | 87 | for (uint32_t i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) |
| 88 | ctx->mLayerCache[i] = new LayerCache(); |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 89 | ctx->mMDPComp = MDPComp::getObject(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].xres); |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 90 | MDPComp::init(ctx); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 91 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 92 | pthread_mutex_init(&(ctx->vstate.lock), NULL); |
| 93 | pthread_cond_init(&(ctx->vstate.cond), NULL); |
| 94 | ctx->vstate.enable = false; |
Amara Venkata Mastan Manoj Kumar | 75526f5 | 2012-12-27 18:27:01 -0800 | [diff] [blame] | 95 | ctx->mExtDispConfiguring = false; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 96 | ALOGI("Initializing Qualcomm Hardware Composer"); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 97 | ALOGI("MDP version: %d", ctx->mMDP.version); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | void closeContext(hwc_context_t *ctx) |
| 101 | { |
Naseer Ahmed | 758bfc5 | 2012-11-28 17:02:08 -0500 | [diff] [blame] | 102 | if(ctx->mOverlay) { |
| 103 | delete ctx->mOverlay; |
| 104 | ctx->mOverlay = NULL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 105 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 106 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 107 | for(int i = 0; i< HWC_NUM_DISPLAY_TYPES; i++) { |
| 108 | if(ctx->mCopyBit[i]) { |
| 109 | delete ctx->mCopyBit[i]; |
| 110 | ctx->mCopyBit[i] = NULL; |
| 111 | } |
| 112 | } |
| 113 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 114 | if(ctx->mFbDev) { |
| 115 | framebuffer_close(ctx->mFbDev); |
| 116 | ctx->mFbDev = NULL; |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 117 | close(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd); |
| 118 | ctx->dpyAttr[HWC_DISPLAY_PRIMARY].fd = -1; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 119 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 120 | |
| 121 | if(ctx->mExtDisplay) { |
| 122 | delete ctx->mExtDisplay; |
| 123 | ctx->mExtDisplay = NULL; |
| 124 | } |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 125 | |
Saurabh Shah | cf053c6 | 2012-12-13 12:32:55 -0800 | [diff] [blame] | 126 | for(int i = 0; i < HWC_NUM_DISPLAY_TYPES; i++) { |
| 127 | if(ctx->mFBUpdate[i]) { |
| 128 | delete ctx->mFBUpdate[i]; |
| 129 | ctx->mFBUpdate[i] = NULL; |
| 130 | } |
| 131 | } |
| 132 | |
Saurabh Shah | cbf7ccc | 2012-12-19 16:45:51 -0800 | [diff] [blame] | 133 | if(ctx->mMDPComp) { |
| 134 | delete ctx->mMDPComp; |
| 135 | ctx->mMDPComp = NULL; |
| 136 | } |
| 137 | |
Naseer Ahmed | ff4f025 | 2012-10-01 13:03:01 -0400 | [diff] [blame] | 138 | pthread_mutex_destroy(&(ctx->vstate.lock)); |
| 139 | pthread_cond_destroy(&(ctx->vstate.cond)); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 142 | |
| 143 | void dumpsys_log(android::String8& buf, const char* fmt, ...) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 144 | { |
Naseer Ahmed | 1d183f5 | 2012-11-26 12:35:16 -0500 | [diff] [blame] | 145 | va_list varargs; |
| 146 | va_start(varargs, fmt); |
| 147 | buf.appendFormatV(fmt, varargs); |
| 148 | va_end(varargs); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 151 | static inline bool isAlphaScaled(hwc_layer_1_t const* layer) { |
| 152 | int dst_w, dst_h, src_w, src_h; |
| 153 | |
| 154 | hwc_rect_t displayFrame = layer->displayFrame; |
| 155 | hwc_rect_t sourceCrop = layer->sourceCrop; |
| 156 | |
| 157 | dst_w = displayFrame.right - displayFrame.left; |
| 158 | dst_h = displayFrame.bottom - displayFrame.top; |
| 159 | |
| 160 | src_w = sourceCrop.right - sourceCrop.left; |
| 161 | src_h = sourceCrop.bottom - sourceCrop.top; |
| 162 | |
| 163 | if(((src_w != dst_w) || (src_h != dst_h))) { |
| 164 | if(layer->blending != HWC_BLENDING_NONE) |
| 165 | return true; |
| 166 | } |
| 167 | return false; |
| 168 | } |
| 169 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 170 | void setListStats(hwc_context_t *ctx, |
| 171 | const hwc_display_contents_1_t *list, int dpy) { |
| 172 | |
| 173 | ctx->listStats[dpy].numAppLayers = list->numHwLayers - 1; |
| 174 | ctx->listStats[dpy].fbLayerIndex = list->numHwLayers - 1; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 175 | ctx->listStats[dpy].yuvCount = 0; |
| 176 | ctx->listStats[dpy].yuvIndex = -1; |
| 177 | ctx->listStats[dpy].skipCount = 0; |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 178 | ctx->listStats[dpy].needsAlphaScale = false; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 179 | |
| 180 | for (size_t i = 0; i < list->numHwLayers; i++) { |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 181 | hwc_layer_1_t const* layer = &list->hwLayers[i]; |
| 182 | private_handle_t *hnd = (private_handle_t *)layer->handle; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 183 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 184 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 185 | continue; |
| 186 | //We disregard FB being skip for now! so the else if |
Saurabh Shah | 35712cb | 2012-09-14 10:28:18 -0700 | [diff] [blame] | 187 | } else if (isSkipLayer(&list->hwLayers[i])) { |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 188 | ctx->listStats[dpy].skipCount++; |
| 189 | } |
| 190 | |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 191 | if(!ctx->listStats[dpy].needsAlphaScale) |
| 192 | ctx->listStats[dpy].needsAlphaScale = isAlphaScaled(layer); |
| 193 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 194 | if (UNLIKELY(isYuvBuffer(hnd))) { |
| 195 | ctx->listStats[dpy].yuvCount++; |
| 196 | ctx->listStats[dpy].yuvIndex = i; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 197 | } |
| 198 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Naseer Ahmed | 018e545 | 2012-12-03 14:46:15 -0500 | [diff] [blame] | 201 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 202 | static inline void calc_cut(float& leftCutRatio, float& topCutRatio, |
| 203 | float& rightCutRatio, float& bottomCutRatio, int orient) { |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 204 | if(orient & HAL_TRANSFORM_FLIP_H) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 205 | swap(leftCutRatio, rightCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 206 | } |
| 207 | if(orient & HAL_TRANSFORM_FLIP_V) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 208 | swap(topCutRatio, bottomCutRatio); |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 209 | } |
| 210 | if(orient & HAL_TRANSFORM_ROT_90) { |
| 211 | //Anti clock swapping |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 212 | float tmpCutRatio = leftCutRatio; |
| 213 | leftCutRatio = topCutRatio; |
| 214 | topCutRatio = rightCutRatio; |
| 215 | rightCutRatio = bottomCutRatio; |
| 216 | bottomCutRatio = tmpCutRatio; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 220 | bool isSecuring(hwc_context_t* ctx) { |
| 221 | if((ctx->mMDP.version < qdutils::MDSS_V5) && |
| 222 | (ctx->mMDP.version > qdutils::MDP_V3_0) && |
| 223 | ctx->mSecuring) { |
| 224 | return true; |
| 225 | } |
| 226 | return false; |
| 227 | } |
| 228 | |
Sushil Chauhan | 2515abf | 2013-01-08 16:40:05 -0800 | [diff] [blame] | 229 | bool isSecureModePolicy(int mdpVersion) { |
| 230 | if (mdpVersion < qdutils::MDSS_V5) |
| 231 | return true; |
| 232 | else |
| 233 | return false; |
| 234 | } |
Naseer Ahmed | 54821fe | 2012-11-28 18:44:38 -0500 | [diff] [blame] | 235 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 236 | //Crops source buffer against destination and FB boundaries |
| 237 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 238 | const int fbWidth, const int fbHeight, int orient) { |
| 239 | int& crop_l = crop.left; |
| 240 | int& crop_t = crop.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 241 | int& crop_r = crop.right; |
| 242 | int& crop_b = crop.bottom; |
| 243 | int crop_w = crop.right - crop.left; |
| 244 | int crop_h = crop.bottom - crop.top; |
| 245 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 246 | int& dst_l = dst.left; |
| 247 | int& dst_t = dst.top; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 248 | int& dst_r = dst.right; |
| 249 | int& dst_b = dst.bottom; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 250 | int dst_w = abs(dst.right - dst.left); |
| 251 | int dst_h = abs(dst.bottom - dst.top); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 252 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 253 | float leftCutRatio = 0.0f, rightCutRatio = 0.0f, topCutRatio = 0.0f, |
| 254 | bottomCutRatio = 0.0f; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 255 | |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 256 | if(dst_l < 0) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 257 | leftCutRatio = (float)(0.0f - dst_l) / (float)dst_w; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 258 | dst_l = 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 259 | } |
| 260 | if(dst_r > fbWidth) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 261 | rightCutRatio = (float)(dst_r - fbWidth) / (float)dst_w; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 262 | dst_r = fbWidth; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 263 | } |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 264 | if(dst_t < 0) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 265 | topCutRatio = (float)(0 - dst_t) / (float)dst_h; |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 266 | dst_t = 0; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 267 | } |
| 268 | if(dst_b > fbHeight) { |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 269 | bottomCutRatio = (float)(dst_b - fbHeight) / (float)dst_h; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 270 | dst_b = fbHeight; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 271 | } |
Saurabh Shah | 27c1d65 | 2012-08-14 19:30:28 -0700 | [diff] [blame] | 272 | |
Saurabh Shah | 541b59d | 2012-10-11 11:08:12 -0700 | [diff] [blame] | 273 | calc_cut(leftCutRatio, topCutRatio, rightCutRatio, bottomCutRatio, orient); |
| 274 | crop_l += crop_w * leftCutRatio; |
| 275 | crop_t += crop_h * topCutRatio; |
| 276 | crop_r -= crop_w * rightCutRatio; |
| 277 | crop_b -= crop_h * bottomCutRatio; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 278 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 279 | |
Saurabh Shah | 3e858eb | 2012-09-17 16:53:21 -0700 | [diff] [blame] | 280 | bool isExternalActive(hwc_context_t* ctx) { |
| 281 | return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive; |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 284 | int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy, |
| 285 | int fd) { |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 286 | int ret = 0; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 287 | struct mdp_buf_sync data; |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 288 | int acquireFd[MAX_NUM_LAYERS]; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 289 | int count = 0; |
| 290 | int releaseFd = -1; |
| 291 | int fbFd = -1; |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 292 | memset(&data, 0, sizeof(data)); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 293 | bool swapzero = false; |
Saurabh Shah | c4d034f | 2012-09-27 15:55:15 -0700 | [diff] [blame] | 294 | data.flags = MDP_BUF_SYNC_FLAG_WAIT; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 295 | data.acq_fen_fd = acquireFd; |
| 296 | data.rel_fen_fd = &releaseFd; |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 297 | char property[PROPERTY_VALUE_MAX]; |
| 298 | if(property_get("debug.egl.swapinterval", property, "1") > 0) { |
| 299 | if(atoi(property) == 0) |
| 300 | swapzero = true; |
| 301 | } |
| 302 | |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 303 | //Accumulate acquireFenceFds |
| 304 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 305 | if(list->hwLayers[i].compositionType == HWC_OVERLAY && |
| 306 | list->hwLayers[i].acquireFenceFd != -1) { |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 307 | if(UNLIKELY(swapzero)) |
| 308 | acquireFd[count++] = -1; |
| 309 | else |
| 310 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 311 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 312 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
| 313 | if(UNLIKELY(swapzero)) |
| 314 | acquireFd[count++] = -1; |
| 315 | else if(fd != -1) { |
| 316 | //set the acquireFD from fd - which is coming from c2d |
| 317 | acquireFd[count++] = fd; |
| 318 | // Buffer sync IOCTL should be async when using c2d fence is |
| 319 | // used |
| 320 | data.flags &= ~MDP_BUF_SYNC_FLAG_WAIT; |
| 321 | } else if(list->hwLayers[i].acquireFenceFd != -1) |
| 322 | acquireFd[count++] = list->hwLayers[i].acquireFenceFd; |
| 323 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 326 | data.acq_fen_fd_cnt = count; |
| 327 | fbFd = ctx->dpyAttr[dpy].fd; |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 328 | //Waits for acquire fences, returns a release fence |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 329 | if(LIKELY(!swapzero)) { |
| 330 | uint64_t start = systemTime(); |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 331 | ret = ioctl(fbFd, MSMFB_BUFFER_SYNC, &data); |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 332 | ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d", |
| 333 | __FUNCTION__, (size_t) ns2ms(systemTime() - start)); |
| 334 | } |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 335 | if(ret < 0) { |
| 336 | ALOGE("ioctl MSMFB_BUFFER_SYNC failed, err=%s", |
| 337 | strerror(errno)); |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 338 | } |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 339 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 340 | if(list->hwLayers[i].compositionType == HWC_OVERLAY || |
| 341 | list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) { |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 342 | //Close the acquireFenceFds |
| 343 | if(list->hwLayers[i].acquireFenceFd > 0) { |
| 344 | close(list->hwLayers[i].acquireFenceFd); |
| 345 | list->hwLayers[i].acquireFenceFd = -1; |
| 346 | } |
Arun Kumar K.R | 361da4f | 2012-11-28 10:42:59 -0800 | [diff] [blame] | 347 | if(fd > 0) { |
| 348 | close(fd); |
| 349 | fd = -1; |
| 350 | } |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 351 | //Populate releaseFenceFds. |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 352 | if(UNLIKELY(swapzero)) |
| 353 | list->hwLayers[i].releaseFenceFd = -1; |
| 354 | else |
| 355 | list->hwLayers[i].releaseFenceFd = dup(releaseFd); |
Kinjal Bhavsar | 40a1cc5 | 2012-10-10 15:52:03 -0700 | [diff] [blame] | 356 | } |
| 357 | } |
Naseer Ahmed | 94baddc | 2012-12-17 18:51:01 -0500 | [diff] [blame] | 358 | if(UNLIKELY(swapzero)){ |
| 359 | list->retireFenceFd = -1; |
| 360 | close(releaseFd); |
| 361 | } else { |
| 362 | list->retireFenceFd = releaseFd; |
| 363 | } |
Kinjal Bhavsar | 2dd04a8 | 2012-09-18 18:27:59 -0700 | [diff] [blame] | 364 | return ret; |
| 365 | } |
| 366 | |
Naseer Ahmed | b1c7632 | 2012-10-17 00:32:50 -0400 | [diff] [blame] | 367 | void LayerCache::resetLayerCache(int num) { |
| 368 | for(uint32_t i = 0; i < MAX_NUM_LAYERS; i++) { |
| 369 | hnd[i] = NULL; |
| 370 | } |
| 371 | numHwLayers = num; |
| 372 | } |
| 373 | |
| 374 | void LayerCache::updateLayerCache(hwc_display_contents_1_t* list) { |
| 375 | |
| 376 | int numFbLayers = 0; |
| 377 | int numCacheableLayers = 0; |
| 378 | |
| 379 | canUseLayerCache = false; |
| 380 | //Bail if geometry changed or num of layers changed |
| 381 | if(list->flags & HWC_GEOMETRY_CHANGED || |
| 382 | list->numHwLayers != numHwLayers ) { |
| 383 | resetLayerCache(list->numHwLayers); |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
| 388 | //Bail on skip layers |
| 389 | if(list->hwLayers[i].flags & HWC_SKIP_LAYER) { |
| 390 | resetLayerCache(list->numHwLayers); |
| 391 | return; |
| 392 | } |
| 393 | |
| 394 | if(list->hwLayers[i].compositionType == HWC_FRAMEBUFFER) { |
| 395 | numFbLayers++; |
| 396 | if(hnd[i] == NULL) { |
| 397 | hnd[i] = list->hwLayers[i].handle; |
| 398 | } else if (hnd[i] == |
| 399 | list->hwLayers[i].handle) { |
| 400 | numCacheableLayers++; |
| 401 | } else { |
| 402 | hnd[i] = NULL; |
| 403 | return; |
| 404 | } |
| 405 | } else { |
| 406 | hnd[i] = NULL; |
| 407 | } |
| 408 | } |
| 409 | if(numFbLayers == numCacheableLayers) |
| 410 | canUseLayerCache = true; |
| 411 | |
| 412 | //XXX: The marking part is separate, if MDP comp wants |
| 413 | // to use it in the future. Right now getting MDP comp |
| 414 | // to use this is more trouble than it is worth. |
| 415 | markCachedLayersAsOverlay(list); |
| 416 | } |
| 417 | |
| 418 | void LayerCache::markCachedLayersAsOverlay(hwc_display_contents_1_t* list) { |
| 419 | //This optimization only works if ALL the layer handles |
| 420 | //that were on the framebuffer didn't change. |
| 421 | if(canUseLayerCache){ |
| 422 | for(uint32_t i = 0; i < list->numHwLayers; i++) { |
| 423 | if (list->hwLayers[i].handle && |
| 424 | list->hwLayers[i].handle == hnd[i] && |
| 425 | list->hwLayers[i].compositionType != HWC_FRAMEBUFFER_TARGET) |
| 426 | { |
| 427 | list->hwLayers[i].compositionType = HWC_OVERLAY; |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | } |
| 433 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 434 | };//namespace |