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