hwc_utils.h revision 77d8f24cb4fece120f062f2f997f018372338b66
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 <fcntl.h> 23#include <hardware/hwcomposer.h> 24#include <gr.h> 25#include <gralloc_priv.h> 26 27#define ALIGN_TO(x, align) (((x) + ((align)-1)) & ~((align)-1)) 28#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) 29#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) 30#define FINAL_TRANSFORM_MASK 0x000F 31#define MAX_NUM_DISPLAYS 4 //Yes, this is ambitious 32 33//Fwrd decls 34struct hwc_context_t; 35struct framebuffer_device_t; 36 37namespace qService { 38class QService; 39} 40 41namespace overlay { 42class Overlay; 43} 44 45namespace qhwc { 46//fwrd decl 47class QueuedBufferStore; 48class ExternalDisplay; 49 50struct MDPInfo { 51 int version; 52 char panel; 53 bool hasOverlay; 54}; 55 56struct DisplayAttributes { 57 uint32_t vsync_period; //nanos 58 uint32_t xres; 59 uint32_t yres; 60 float xdpi; 61 float ydpi; 62 int fd; 63 bool isActive; 64}; 65 66struct ListStats { 67 int numAppLayers; //Total - 1, excluding FB layer. 68 int skipCount; 69 int fbLayerIndex; //Always last for now. = numAppLayers 70 //Video specific 71 int yuvCount; 72 int yuvIndex; 73}; 74 75enum { 76 HWC_MDPCOMP = 0x00000002, 77 HWC_LAYER_RESERVED_0 = 0x00000004, 78 HWC_LAYER_RESERVED_1 = 0x00000008 79}; 80 81 82// ----------------------------------------------------------------------------- 83// Utility functions - implemented in hwc_utils.cpp 84void dumpLayer(hwc_layer_1_t const* l); 85void setListStats(hwc_context_t *ctx, const hwc_display_contents_1_t *list, 86 int dpy); 87void initContext(hwc_context_t *ctx); 88void closeContext(hwc_context_t *ctx); 89//Crops source buffer against destination and FB boundaries 90void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, 91 const int fbWidth, const int fbHeight); 92 93bool isExternalActive(hwc_context_t* ctx); 94 95//Sync point impl. 96int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy); 97 98// Inline utility functions 99static inline bool isSkipLayer(const hwc_layer_1_t* l) { 100 return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER))); 101} 102 103// Returns true if the buffer is yuv 104static inline bool isYuvBuffer(const private_handle_t* hnd) { 105 return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO)); 106} 107 108// Returns true if the buffer is secure 109static inline bool isSecureBuffer(const private_handle_t* hnd) { 110 return (hnd && (private_handle_t::PRIV_FLAGS_SECURE_BUFFER & hnd->flags)); 111} 112//Return true if buffer is marked locked 113static inline bool isBufferLocked(const private_handle_t* hnd) { 114 return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags)); 115} 116 117//Return true if buffer is for external display only 118static inline bool isExtOnly(const private_handle_t* hnd) { 119 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_ONLY)); 120} 121 122//Return true if buffer is for external display only with a BLOCK flag. 123static inline bool isExtBlock(const private_handle_t* hnd) { 124 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_BLOCK)); 125} 126 127//Return true if buffer is for external display only with a Close Caption flag. 128static inline bool isExtCC(const private_handle_t* hnd) { 129 return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_EXTERNAL_CC)); 130} 131 132// Initialize uevent thread 133void init_uevent_thread(hwc_context_t* ctx); 134 135inline void getLayerResolution(const hwc_layer_1_t* layer, 136 int& width, int& height) 137{ 138 hwc_rect_t displayFrame = layer->displayFrame; 139 width = displayFrame.right - displayFrame.left; 140 height = displayFrame.bottom - displayFrame.top; 141} 142 143static inline int openFb(int dpy) { 144 int fd = -1; 145 const char *devtmpl = "/dev/graphics/fb%u"; 146 char name[64] = {0}; 147 snprintf(name, 64, devtmpl, dpy); 148 fd = open(name, O_RDWR); 149 return fd; 150} 151 152}; //qhwc namespace 153 154// ----------------------------------------------------------------------------- 155// HWC context 156// This structure contains overall state 157struct hwc_context_t { 158 hwc_composer_device_1_t device; 159 const hwc_procs_t* proc; 160 int numHwLayers; 161 int overlayInUse; 162 163 //Framebuffer device 164 framebuffer_device_t *mFbDev; 165 166 //Overlay object - NULL for non overlay devices 167 overlay::Overlay *mOverlay; 168 169 //QService object 170 qService::QService *mQService; 171 172 // External display related information 173 qhwc::ExternalDisplay *mExtDisplay; 174 175 qhwc::MDPInfo mMDP; 176 177 qhwc::DisplayAttributes dpyAttr[HWC_NUM_DISPLAY_TYPES]; 178 179 qhwc::ListStats listStats[HWC_NUM_DISPLAY_TYPES]; 180 181 //Securing in progress indicator 182 bool mSecuring; 183 184 //Display in secure mode indicator 185 bool mSecureMode; 186 187 //Lock to prevent set from being called while blanking 188 mutable Locker mBlankLock; 189}; 190 191#endif //HWC_UTILS_H 192