Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 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 | #ifndef HWC_UTILS_H |
| 19 | #define HWC_UTILS_H |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 20 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 21 | #include <hardware/hwcomposer.h> |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 22 | #include <gralloc_priv.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 23 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 24 | #define ALIGN_TO(x, align) (((x) + ((align)-1)) & ~((align)-1)) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 25 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 26 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 27 | #define FINAL_TRANSFORM_MASK 0x000F |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 28 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 29 | //Fwrd decls |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 30 | struct hwc_context_t; |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 31 | struct framebuffer_device_t; |
| 32 | |
| 33 | namespace overlay { |
| 34 | class Overlay; |
| 35 | } |
| 36 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 37 | namespace qhwc { |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 38 | //fwrd decl |
| 39 | class QueuedBufferStore; |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame^] | 40 | class ExternalDisplay; |
| 41 | class CopybitEngine; |
| 42 | |
| 43 | struct MDPInfo { |
| 44 | int version; |
| 45 | char panel; |
| 46 | bool hasOverlay; |
| 47 | }; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 48 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 49 | enum external_display_type { |
| 50 | EXT_TYPE_NONE, |
| 51 | EXT_TYPE_HDMI, |
| 52 | EXT_TYPE_WIFI |
| 53 | }; |
| 54 | enum HWCCompositionType { |
| 55 | HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by |
| 56 | // Surfaceflinger |
| 57 | HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay |
| 58 | HWC_USE_COPYBIT // This layer is to be handled by copybit |
| 59 | }; |
| 60 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 61 | enum { |
| 62 | HWC_MDPCOMP = 0x00000002, |
| 63 | HWC_LAYER_RESERVED_0 = 0x00000004, |
| 64 | HWC_LAYER_RESERVED_1 = 0x00000008 |
| 65 | }; |
| 66 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 67 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 68 | // ----------------------------------------------------------------------------- |
| 69 | // Utility functions - implemented in hwc_utils.cpp |
| 70 | void dumpLayer(hwc_layer_t const* l); |
| 71 | void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 72 | void initContext(hwc_context_t *ctx); |
| 73 | void closeContext(hwc_context_t *ctx); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 74 | //Crops source buffer against destination and FB boundaries |
| 75 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
| 76 | const int fbWidth, const int fbHeight); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 77 | |
| 78 | // Inline utility functions |
| 79 | static inline bool isSkipLayer(const hwc_layer_t* l) { |
| 80 | return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER))); |
| 81 | } |
| 82 | |
| 83 | // Returns true if the buffer is yuv |
| 84 | static inline bool isYuvBuffer(const private_handle_t* hnd) { |
| 85 | return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO)); |
| 86 | } |
| 87 | |
| 88 | //Return true if buffer is marked locked |
| 89 | static inline bool isBufferLocked(const private_handle_t* hnd) { |
| 90 | return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags)); |
| 91 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 92 | |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 93 | // Initialize uevent thread |
| 94 | void init_uevent_thread(hwc_context_t* ctx); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 95 | |
Naseer Ahmed | 7c958d4 | 2012-07-31 18:57:03 -0700 | [diff] [blame] | 96 | inline void getLayerResolution(const hwc_layer_t* layer, |
| 97 | int& width, int& height) |
| 98 | { |
| 99 | hwc_rect_t displayFrame = layer->displayFrame; |
| 100 | width = displayFrame.right - displayFrame.left; |
| 101 | height = displayFrame.bottom - displayFrame.top; |
| 102 | } |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 103 | }; //qhwc namespace |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 104 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 105 | // ----------------------------------------------------------------------------- |
| 106 | // HWC context |
| 107 | // This structure contains overall state |
| 108 | struct hwc_context_t { |
| 109 | hwc_composer_device_t device; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 110 | int numHwLayers; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 111 | int overlayInUse; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 112 | |
| 113 | //Framebuffer device |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 114 | framebuffer_device_t *mFbDev; |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame] | 115 | |
| 116 | //Copybit Engine |
| 117 | qhwc::CopybitEngine* mCopybitEngine; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 118 | |
| 119 | //Overlay object - NULL for non overlay devices |
| 120 | overlay::Overlay *mOverlay; |
| 121 | |
| 122 | //QueuedBufferStore to hold buffers for overlay |
| 123 | qhwc::QueuedBufferStore *qbuf; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 124 | |
| 125 | // External display related information |
Naseer Ahmed | 72cf976 | 2012-07-21 12:17:13 -0700 | [diff] [blame] | 126 | qhwc::ExternalDisplay *mExtDisplay; |
| 127 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame^] | 128 | qhwc::MDPInfo mMDP; |
| 129 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 132 | #endif //HWC_UTILS_H |