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 |
| 20 | #include <cutils/log.h> |
| 21 | #include <gralloc_priv.h> |
| 22 | #include <hardware/hwcomposer.h> |
| 23 | #include <hardware/hardware.h> |
| 24 | #include <hardware/gralloc.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <fb_priv.h> |
| 28 | #include <overlay.h> |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 29 | #include <copybit.h> |
| 30 | #include <hwc_copybitEngine.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 31 | #include <genlock.h> |
| 32 | #include "hwc_qbuf.h" |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 33 | #include <EGL/egl.h> |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 34 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 35 | #define ALIGN_TO(x, align) (((x) + ((align)-1)) & ~((align)-1)) |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 36 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 37 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 38 | #define FINAL_TRANSFORM_MASK 0x000F |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 39 | |
| 40 | struct hwc_context_t; |
| 41 | namespace qhwc { |
| 42 | |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 43 | enum external_display_type { |
| 44 | EXT_TYPE_NONE, |
| 45 | EXT_TYPE_HDMI, |
| 46 | EXT_TYPE_WIFI |
| 47 | }; |
| 48 | enum HWCCompositionType { |
| 49 | HWC_USE_GPU = HWC_FRAMEBUFFER, // This layer is to be handled by |
| 50 | // Surfaceflinger |
| 51 | HWC_USE_OVERLAY = HWC_OVERLAY, // This layer is to be handled by the overlay |
| 52 | HWC_USE_COPYBIT // This layer is to be handled by copybit |
| 53 | }; |
| 54 | |
| 55 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 56 | class ExtDisplayObserver; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 57 | // ----------------------------------------------------------------------------- |
| 58 | // Utility functions - implemented in hwc_utils.cpp |
| 59 | void dumpLayer(hwc_layer_t const* l); |
| 60 | void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 61 | void initContext(hwc_context_t *ctx); |
| 62 | void closeContext(hwc_context_t *ctx); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 63 | //Crops source buffer against destination and FB boundaries |
| 64 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
| 65 | const int fbWidth, const int fbHeight); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 66 | |
| 67 | // Inline utility functions |
| 68 | static inline bool isSkipLayer(const hwc_layer_t* l) { |
| 69 | return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER))); |
| 70 | } |
| 71 | |
| 72 | // Returns true if the buffer is yuv |
| 73 | static inline bool isYuvBuffer(const private_handle_t* hnd) { |
| 74 | return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO)); |
| 75 | } |
| 76 | |
| 77 | //Return true if buffer is marked locked |
| 78 | static inline bool isBufferLocked(const private_handle_t* hnd) { |
| 79 | return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags)); |
| 80 | } |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 81 | // ----------------------------------------------------------------------------- |
| 82 | // Copybit specific - inline or implemented in hwc_copybit.cpp |
| 83 | typedef EGLClientBuffer (*functype_eglGetRenderBufferANDROID) ( |
| 84 | EGLDisplay dpy, |
| 85 | EGLSurface draw); |
| 86 | typedef EGLSurface (*functype_eglGetCurrentSurface)(EGLint readdraw); |
| 87 | |
| 88 | // ----------------------------------------------------------------------------- |
| 89 | // Singleton for Framebuffer device |
| 90 | class FbDevice{ |
| 91 | public: |
| 92 | ~FbDevice(); |
| 93 | // API to get Fb device(non static) |
| 94 | struct framebuffer_device_t *getFb(); |
| 95 | // API to get singleton |
| 96 | static FbDevice* getInstance(); |
| 97 | |
| 98 | private: |
| 99 | FbDevice(); |
| 100 | struct framebuffer_device_t *sFb; |
| 101 | static FbDevice* sInstance; // singleton |
| 102 | }; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 103 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 104 | }; //qhwc namespace |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 105 | |
| 106 | |
| 107 | // ----------------------------------------------------------------------------- |
| 108 | // HWC context |
| 109 | // This structure contains overall state |
| 110 | struct hwc_context_t { |
| 111 | hwc_composer_device_t device; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 112 | int numHwLayers; |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 113 | int mdpVersion; |
| 114 | bool hasOverlay; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 115 | int overlayInUse; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 116 | |
| 117 | //Framebuffer device |
Naseer Ahmed | 31da0b1 | 2012-07-31 18:55:33 -0700 | [diff] [blame^] | 118 | qhwc::FbDevice* mFbDevice; |
| 119 | |
| 120 | //Copybit Engine |
| 121 | qhwc::CopybitEngine* mCopybitEngine; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 122 | |
| 123 | //Overlay object - NULL for non overlay devices |
| 124 | overlay::Overlay *mOverlay; |
| 125 | |
| 126 | //QueuedBufferStore to hold buffers for overlay |
| 127 | qhwc::QueuedBufferStore *qbuf; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame] | 128 | |
| 129 | // External display related information |
| 130 | qhwc::ExtDisplayObserver*mExtDisplayObserver; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 133 | #endif //HWC_UTILS_H |