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