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