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