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