hwc_utils.h revision 56f610dd235b577725198e9341caae92379fdf23
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * Copyright (C) 2012, The Linux Foundation. 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#ifndef HWC_UTILS_H 19#define HWC_UTILS_H 20 21#define HWC_REMOVE_DEPRECATED_VERSIONS 1 22#include <hardware/hwcomposer.h> 23#include <gralloc_priv.h> 24 25#define ALIGN_TO(x, align) (((x) + ((align)-1)) & ~((align)-1)) 26#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) 27#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) 28#define FINAL_TRANSFORM_MASK 0x000F 29#define MAX_NUM_DISPLAYS 4 //Yes, this is ambitious 30 31//Fwrd decls 32struct hwc_context_t; 33struct framebuffer_device_t; 34 35namespace qService { 36class QService; 37} 38 39namespace overlay { 40class Overlay; 41} 42 43namespace qhwc { 44//fwrd decl 45class QueuedBufferStore; 46class ExternalDisplay; 47class CopybitEngine; 48 49struct MDPInfo { 50 int version; 51 char panel; 52 bool hasOverlay; 53}; 54 55enum external_display_type { 56 EXT_TYPE_NONE, 57 EXT_TYPE_HDMI, 58 EXT_TYPE_WIFI 59}; 60enum HWCCompositionType { 61 HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by 62 // Surfaceflinger 63 HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay 64 HWC_USE_COPYBIT // This layer is to be handled by copybit 65}; 66 67enum { 68 HWC_MDPCOMP = 0x00000002, 69 HWC_LAYER_RESERVED_0 = 0x00000004, 70 HWC_LAYER_RESERVED_1 = 0x00000008 71}; 72 73 74// ----------------------------------------------------------------------------- 75// Utility functions - implemented in hwc_utils.cpp 76void dumpLayer(hwc_layer_1_t const* l); 77void getLayerStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list); 78void initContext(hwc_context_t *ctx); 79void closeContext(hwc_context_t *ctx); 80//Crops source buffer against destination and FB boundaries 81void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, 82 const int fbWidth, const int fbHeight); 83 84// Waits for the fb_post to be called 85void wait4fbPost(hwc_context_t* ctx); 86 87// Waits for the fb_post to finish PAN (primary commit) 88void wait4Pan(hwc_context_t* ctx); 89 90// Inline utility functions 91static inline bool isSkipLayer(const hwc_layer_1_t* l) { 92 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER))); 93} 94 95// Returns true if the buffer is yuv 96static inline bool isYuvBuffer(const private_handle_t* hnd) { 97 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO)); 98} 99 100// Returns true if the buffer is secure 101static inline bool isSecureBuffer(const private_handle_t* hnd) { 102 return (hnd && (private_handle_t::PRIV_FLAGS_SECURE_BUFFER & hnd->flags)); 103} 104//Return true if buffer is marked locked 105static inline bool isBufferLocked(const private_handle_t* hnd) { 106 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags)); 107} 108 109//Return true if buffer is for external display only 110static inline bool isExtOnly(const private_handle_t* hnd) { 111 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY)); 112} 113 114//Return true if buffer is for external display only with a BLOCK flag. 115static inline bool isExtBlock(const private_handle_t* hnd) { 116 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_BLOCK)); 117} 118 119//Return true if buffer is for external display only with a Close Caption flag. 120static inline bool isExtCC(const private_handle_t* hnd) { 121 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_CC)); 122} 123 124// Initialize uevent thread 125void init_uevent_thread(hwc_context_t* ctx); 126 127inline void getLayerResolution(const hwc_layer_1_t* layer, 128 int& width, int& height) 129{ 130 hwc_rect_t displayFrame = layer->displayFrame; 131 width = displayFrame.right - displayFrame.left; 132 height = displayFrame.bottom - displayFrame.top; 133} 134}; //qhwc namespace 135 136// ----------------------------------------------------------------------------- 137// HWC context 138// This structure contains overall state 139struct hwc_context_t { 140 hwc_composer_device_1_t device; 141 const hwc_procs_t* proc; 142 int numHwLayers; 143 int overlayInUse; 144 hwc_display_t dpys[MAX_NUM_DISPLAYS]; 145 146 //Framebuffer device 147 framebuffer_device_t *mFbDev; 148 149 //Copybit Engine 150 qhwc::CopybitEngine* mCopybitEngine; 151 152 //Overlay object - NULL for non overlay devices 153 overlay::Overlay *mOverlay; 154 155 //QueuedBufferStore to hold buffers for overlay 156 qhwc::QueuedBufferStore *qbuf; 157 158 //QService object 159 qService::QService *mQService; 160 161 // External display related information 162 qhwc::ExternalDisplay *mExtDisplay; 163 164 qhwc::MDPInfo mMDP; 165 166 bool isPoweredDown; 167 168 //Securing in progress indicator 169 bool mSecuring; 170 171 //Display in secure mode indicator 172 bool mSecureMode; 173}; 174 175#endif //HWC_UTILS_H 176