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