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