Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * Copyright (C) 2012, Code Aurora Forum. All rights reserved. |
| 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" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 26 | #include "hwc_qbuf.h" |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 27 | #include "hwc_copybit.h" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 28 | #include "hwc_external.h" |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 29 | #include "hwc_mdpcomp.h" |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 30 | #include "hwc_extonly.h" |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 31 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 32 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 33 | |
| 34 | // Opens Framebuffer device |
| 35 | static void openFramebufferDevice(hwc_context_t *ctx) |
| 36 | { |
| 37 | hw_module_t const *module; |
| 38 | if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module) == 0) { |
| 39 | framebuffer_open(module, &(ctx->mFbDev)); |
| 40 | } |
| 41 | } |
| 42 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 43 | void initContext(hwc_context_t *ctx) |
| 44 | { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 45 | openFramebufferDevice(ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 46 | ctx->mOverlay = overlay::Overlay::getInstance(); |
| 47 | ctx->qbuf = new QueuedBufferStore(); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 48 | ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); |
| 49 | ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); |
| 50 | ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 51 | ctx->mCopybitEngine = CopybitEngine::getInstance(); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 52 | ctx->mExtDisplay = new ExternalDisplay(ctx); |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 53 | memset(ctx->dpys,(int)EGL_NO_DISPLAY, MAX_NUM_DISPLAYS); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 54 | MDPComp::init(ctx); |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 55 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 56 | ALOGI("Initializing Qualcomm Hardware Composer"); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 57 | ALOGI("MDP version: %d", ctx->mMDP.version); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void closeContext(hwc_context_t *ctx) |
| 61 | { |
| 62 | if(ctx->mOverlay) { |
| 63 | delete ctx->mOverlay; |
| 64 | ctx->mOverlay = NULL; |
| 65 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 66 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 67 | if(ctx->mCopybitEngine) { |
| 68 | delete ctx->mCopybitEngine; |
| 69 | ctx->mCopybitEngine = NULL; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 70 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 71 | |
| 72 | if(ctx->mFbDev) { |
| 73 | framebuffer_close(ctx->mFbDev); |
| 74 | ctx->mFbDev = NULL; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 75 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 76 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 77 | if(ctx->qbuf) { |
| 78 | delete ctx->qbuf; |
| 79 | ctx->qbuf = NULL; |
| 80 | } |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 81 | |
| 82 | if(ctx->mExtDisplay) { |
| 83 | delete ctx->mExtDisplay; |
| 84 | ctx->mExtDisplay = NULL; |
| 85 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 88 | void dumpLayer(hwc_layer_1_t const* l) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 89 | { |
| 90 | ALOGD("\ttype=%d, flags=%08x, handle=%p, tr=%02x, blend=%04x, {%d,%d,%d,%d}" |
| 91 | ", {%d,%d,%d,%d}", |
| 92 | l->compositionType, l->flags, l->handle, l->transform, l->blending, |
| 93 | l->sourceCrop.left, |
| 94 | l->sourceCrop.top, |
| 95 | l->sourceCrop.right, |
| 96 | l->sourceCrop.bottom, |
| 97 | l->displayFrame.left, |
| 98 | l->displayFrame.top, |
| 99 | l->displayFrame.right, |
| 100 | l->displayFrame.bottom); |
| 101 | } |
| 102 | |
Naseer Ahmed | 5b6708a | 2012-08-02 13:46:08 -0700 | [diff] [blame] | 103 | void getLayerStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 104 | { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 105 | //Video specific stats |
| 106 | int yuvCount = 0; |
| 107 | int yuvLayerIndex = -1; |
| 108 | bool isYuvLayerSkip = false; |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 109 | int skipCount = 0; |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 110 | int ccLayerIndex = -1; //closed caption |
| 111 | int extLayerIndex = -1; //ext-only or block except closed caption |
| 112 | int extCount = 0; //ext-only except closed caption |
| 113 | bool isExtBlockPresent = false; //is BLOCK layer present |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 114 | |
| 115 | for (size_t i = 0; i < list->numHwLayers; i++) { |
| 116 | private_handle_t *hnd = |
| 117 | (private_handle_t *)list->hwLayers[i].handle; |
| 118 | |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 119 | if (UNLIKELY(isYuvBuffer(hnd))) { |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 120 | yuvCount++; |
| 121 | yuvLayerIndex = i; |
| 122 | //Animating |
| 123 | if (isSkipLayer(&list->hwLayers[i])) { |
| 124 | isYuvLayerSkip = true; |
| 125 | } |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 126 | } else if(UNLIKELY(isExtCC(hnd))) { |
| 127 | ccLayerIndex = i; |
| 128 | } else if(UNLIKELY(isExtBlock(hnd))) { |
| 129 | extCount++; |
| 130 | extLayerIndex = i; |
| 131 | isExtBlockPresent = true; |
| 132 | } else if(UNLIKELY(isExtOnly(hnd))) { |
| 133 | extCount++; |
| 134 | //If BLOCK layer present, dont cache index, display BLOCK only. |
| 135 | if(isExtBlockPresent == false) extLayerIndex = i; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 136 | } else if (isSkipLayer(&list->hwLayers[i])) { //Popups |
| 137 | //If video layer is below a skip layer |
| 138 | if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) { |
| 139 | isYuvLayerSkip = true; |
| 140 | } |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 141 | skipCount++; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 144 | |
Naseer Ahmed | 4c588a2 | 2012-07-31 19:12:17 -0700 | [diff] [blame] | 145 | VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip, |
| 146 | ccLayerIndex); |
| 147 | ExtOnly::setStats(extCount, extLayerIndex, isExtBlockPresent); |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 148 | CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip); |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 149 | MDPComp::setStats(skipCount); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 150 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 151 | ctx->numHwLayers = list->numHwLayers; |
| 152 | return; |
| 153 | } |
| 154 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 155 | //Crops source buffer against destination and FB boundaries |
| 156 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
| 157 | const int fbWidth, const int fbHeight) { |
| 158 | |
| 159 | int& crop_x = crop.left; |
| 160 | int& crop_y = crop.top; |
| 161 | int& crop_r = crop.right; |
| 162 | int& crop_b = crop.bottom; |
| 163 | int crop_w = crop.right - crop.left; |
| 164 | int crop_h = crop.bottom - crop.top; |
| 165 | |
| 166 | int& dst_x = dst.left; |
| 167 | int& dst_y = dst.top; |
| 168 | int& dst_r = dst.right; |
| 169 | int& dst_b = dst.bottom; |
| 170 | int dst_w = dst.right - dst.left; |
| 171 | int dst_h = dst.bottom - dst.top; |
| 172 | |
| 173 | if(dst_x < 0) { |
| 174 | float scale_x = crop_w * 1.0f / dst_w; |
| 175 | float diff_factor = (scale_x * abs(dst_x)); |
| 176 | crop_x = crop_x + (int)diff_factor; |
| 177 | crop_w = crop_r - crop_x; |
| 178 | |
| 179 | dst_x = 0; |
| 180 | dst_w = dst_r - dst_x;; |
| 181 | } |
| 182 | if(dst_r > fbWidth) { |
| 183 | float scale_x = crop_w * 1.0f / dst_w; |
| 184 | float diff_factor = scale_x * (dst_r - fbWidth); |
| 185 | crop_r = crop_r - diff_factor; |
| 186 | crop_w = crop_r - crop_x; |
| 187 | |
| 188 | dst_r = fbWidth; |
| 189 | dst_w = dst_r - dst_x; |
| 190 | } |
| 191 | if(dst_y < 0) { |
| 192 | float scale_y = crop_h * 1.0f / dst_h; |
| 193 | float diff_factor = scale_y * abs(dst_y); |
| 194 | crop_y = crop_y + diff_factor; |
| 195 | crop_h = crop_b - crop_y; |
| 196 | |
| 197 | dst_y = 0; |
| 198 | dst_h = dst_b - dst_y; |
| 199 | } |
| 200 | if(dst_b > fbHeight) { |
| 201 | float scale_y = crop_h * 1.0f / dst_h; |
| 202 | float diff_factor = scale_y * (dst_b - fbHeight); |
| 203 | crop_b = crop_b - diff_factor; |
| 204 | crop_h = crop_b - crop_y; |
| 205 | |
| 206 | dst_b = fbHeight; |
| 207 | dst_h = dst_b - dst_y; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 208 | } |
| 209 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 210 | |
Saurabh Shah | fc2acbe | 2012-08-17 19:47:52 -0700 | [diff] [blame] | 211 | void wait4fbPost(hwc_context_t* ctx) { |
| 212 | framebuffer_device_t *fbDev = ctx->mFbDev; |
| 213 | if(fbDev) { |
| 214 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 215 | fbDev->common.module); |
| 216 | //wait for the fb_post to be called |
| 217 | pthread_mutex_lock(&m->fbPostLock); |
| 218 | while(m->fbPostDone == false) { |
| 219 | pthread_cond_wait(&(m->fbPostCond), &(m->fbPostLock)); |
| 220 | } |
| 221 | m->fbPostDone = false; |
| 222 | pthread_mutex_unlock(&m->fbPostLock); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | void wait4Pan(hwc_context_t* ctx) { |
| 227 | framebuffer_device_t *fbDev = ctx->mFbDev; |
| 228 | if(fbDev) { |
| 229 | private_module_t* m = reinterpret_cast<private_module_t*>( |
| 230 | fbDev->common.module); |
| 231 | //wait for the fb_post's PAN to finish |
| 232 | pthread_mutex_lock(&m->fbPanLock); |
| 233 | while(m->fbPanDone == false) { |
| 234 | pthread_cond_wait(&(m->fbPanCond), &(m->fbPanLock)); |
| 235 | } |
| 236 | m->fbPanDone = false; |
| 237 | pthread_mutex_unlock(&m->fbPanLock); |
| 238 | } |
| 239 | } |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 240 | };//namespace |