hwc_utils.cpp revision 661a58f851b67427ab55e65610fb9173562c7043
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 18#include <EGL/egl.h> 19#include <overlay.h> 20#include <cutils/properties.h> 21#include <gralloc_priv.h> 22#include <fb_priv.h> 23#include "hwc_utils.h" 24#include "mdp_version.h" 25#include "hwc_video.h" 26#include "hwc_qbuf.h" 27#include "hwc_copybit.h" 28#include "hwc_external.h" 29#include "hwc_mdpcomp.h" 30#include "hwc_extonly.h" 31 32namespace qhwc { 33 34// Opens Framebuffer device 35static 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 43void initContext(hwc_context_t *ctx) 44{ 45 openFramebufferDevice(ctx); 46 ctx->mOverlay = overlay::Overlay::getInstance(); 47 ctx->qbuf = new QueuedBufferStore(); 48 ctx->mMDP.version = qdutils::MDPVersion::getInstance().getMDPVersion(); 49 ctx->mMDP.hasOverlay = qdutils::MDPVersion::getInstance().hasOverlay(); 50 ctx->mMDP.panel = qdutils::MDPVersion::getInstance().getPanelType(); 51 ctx->mExtDisplay = new ExternalDisplay(ctx); 52 memset(ctx->dpys,(int)EGL_NO_DISPLAY, MAX_NUM_DISPLAYS); 53 MDPComp::init(ctx); 54 55 ALOGI("Initializing Qualcomm Hardware Composer"); 56 ALOGI("MDP version: %d", ctx->mMDP.version); 57} 58 59void closeContext(hwc_context_t *ctx) 60{ 61 if(ctx->mOverlay) { 62 delete ctx->mOverlay; 63 ctx->mOverlay = NULL; 64 } 65 66 if(ctx->mCopybitEngine) { 67 delete ctx->mCopybitEngine; 68 ctx->mCopybitEngine = NULL; 69 } 70 71 if(ctx->mFbDev) { 72 framebuffer_close(ctx->mFbDev); 73 ctx->mFbDev = NULL; 74 } 75 76 if(ctx->qbuf) { 77 delete ctx->qbuf; 78 ctx->qbuf = NULL; 79 } 80 81 if(ctx->mExtDisplay) { 82 delete ctx->mExtDisplay; 83 ctx->mExtDisplay = NULL; 84 } 85} 86 87void dumpLayer(hwc_layer_1_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 102void getLayerStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list) 103{ 104 //Video specific stats 105 int yuvCount = 0; 106 int yuvLayerIndex = -1; 107 bool isYuvLayerSkip = false; 108 int skipCount = 0; 109 int ccLayerIndex = -1; //closed caption 110 int extLayerIndex = -1; //ext-only or block except closed caption 111 int extCount = 0; //ext-only except closed caption 112 bool isExtBlockPresent = false; //is BLOCK layer present 113 bool yuvSecure = false; 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 119 if (UNLIKELY(isYuvBuffer(hnd))) { 120 yuvCount++; 121 yuvLayerIndex = i; 122 yuvSecure = isSecureBuffer(hnd); 123 //Animating 124 //Do not mark as SKIP if it is secure buffer 125 if (isSkipLayer(&list->hwLayers[i]) && !yuvSecure) { 126 isYuvLayerSkip = true; 127 } 128 } else if(UNLIKELY(isExtCC(hnd))) { 129 ccLayerIndex = i; 130 } else if(UNLIKELY(isExtBlock(hnd))) { 131 extCount++; 132 extLayerIndex = i; 133 isExtBlockPresent = true; 134 } else if(UNLIKELY(isExtOnly(hnd))) { 135 extCount++; 136 //If BLOCK layer present, dont cache index, display BLOCK only. 137 if(isExtBlockPresent == false) extLayerIndex = i; 138 } else if (isSkipLayer(&list->hwLayers[i])) { //Popups 139 //If video layer is below a skip layer 140 if(yuvLayerIndex != -1 && yuvLayerIndex < (ssize_t)i) { 141 //Do not mark as SKIP if it is secure buffer 142 if (!yuvSecure) { 143 isYuvLayerSkip = true; 144 skipCount++; 145 } 146 } 147 } 148 } 149 150 VideoOverlay::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip, 151 ccLayerIndex); 152 ExtOnly::setStats(extCount, extLayerIndex, isExtBlockPresent); 153 CopyBit::setStats(yuvCount, yuvLayerIndex, isYuvLayerSkip); 154 MDPComp::setStats(skipCount); 155 156 ctx->numHwLayers = list->numHwLayers; 157 return; 158} 159 160//Crops source buffer against destination and FB boundaries 161void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, 162 const int fbWidth, const int fbHeight) { 163 164 int& crop_x = crop.left; 165 int& crop_y = crop.top; 166 int& crop_r = crop.right; 167 int& crop_b = crop.bottom; 168 int crop_w = crop.right - crop.left; 169 int crop_h = crop.bottom - crop.top; 170 171 int& dst_x = dst.left; 172 int& dst_y = dst.top; 173 int& dst_r = dst.right; 174 int& dst_b = dst.bottom; 175 int dst_w = dst.right - dst.left; 176 int dst_h = dst.bottom - dst.top; 177 178 if(dst_x < 0) { 179 float scale_x = crop_w * 1.0f / dst_w; 180 float diff_factor = (scale_x * abs(dst_x)); 181 crop_x = crop_x + (int)diff_factor; 182 crop_w = crop_r - crop_x; 183 184 dst_x = 0; 185 dst_w = dst_r - dst_x;; 186 } 187 if(dst_r > fbWidth) { 188 float scale_x = crop_w * 1.0f / dst_w; 189 float diff_factor = scale_x * (dst_r - fbWidth); 190 crop_r = crop_r - diff_factor; 191 crop_w = crop_r - crop_x; 192 193 dst_r = fbWidth; 194 dst_w = dst_r - dst_x; 195 } 196 if(dst_y < 0) { 197 float scale_y = crop_h * 1.0f / dst_h; 198 float diff_factor = scale_y * abs(dst_y); 199 crop_y = crop_y + diff_factor; 200 crop_h = crop_b - crop_y; 201 202 dst_y = 0; 203 dst_h = dst_b - dst_y; 204 } 205 if(dst_b > fbHeight) { 206 float scale_y = crop_h * 1.0f / dst_h; 207 float diff_factor = scale_y * (dst_b - fbHeight); 208 crop_b = crop_b - diff_factor; 209 crop_h = crop_b - crop_y; 210 211 dst_b = fbHeight; 212 dst_h = dst_b - dst_y; 213 } 214} 215 216void wait4fbPost(hwc_context_t* ctx) { 217 framebuffer_device_t *fbDev = ctx->mFbDev; 218 if(fbDev) { 219 private_module_t* m = reinterpret_cast<private_module_t*>( 220 fbDev->common.module); 221 //wait for the fb_post to be called 222 pthread_mutex_lock(&m->fbPostLock); 223 while(m->fbPostDone == false) { 224 pthread_cond_wait(&(m->fbPostCond), &(m->fbPostLock)); 225 } 226 m->fbPostDone = false; 227 pthread_mutex_unlock(&m->fbPostLock); 228 } 229} 230 231void wait4Pan(hwc_context_t* ctx) { 232 framebuffer_device_t *fbDev = ctx->mFbDev; 233 if(fbDev) { 234 private_module_t* m = reinterpret_cast<private_module_t*>( 235 fbDev->common.module); 236 //wait for the fb_post's PAN to finish 237 pthread_mutex_lock(&m->fbPanLock); 238 while(m->fbPanDone == false) { 239 pthread_cond_wait(&(m->fbPanCond), &(m->fbPanLock)); 240 } 241 m->fbPanDone = false; 242 pthread_mutex_unlock(&m->fbPanLock); 243 } 244} 245};//namespace 246