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