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