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