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 | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 29 | #include <genlock.h> |
| 30 | #include "hwc_qbuf.h" |
| 31 | |
| 32 | #define ALIGN(x, align) (((x) + ((align)-1)) & ~((align)-1)) |
| 33 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 34 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 35 | |
| 36 | struct hwc_context_t; |
| 37 | namespace qhwc { |
| 38 | |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame^] | 39 | class ExtDisplayObserver; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 40 | // ----------------------------------------------------------------------------- |
| 41 | // Utility functions - implemented in hwc_utils.cpp |
| 42 | void dumpLayer(hwc_layer_t const* l); |
| 43 | void getLayerStats(hwc_context_t *ctx, const hwc_layer_list_t *list); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 44 | void initContext(hwc_context_t *ctx); |
| 45 | void closeContext(hwc_context_t *ctx); |
| 46 | void openFramebufferDevice(hwc_context_t *ctx); |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 47 | //Crops source buffer against destination and FB boundaries |
| 48 | void calculate_crop_rects(hwc_rect_t& crop, hwc_rect_t& dst, |
| 49 | const int fbWidth, const int fbHeight); |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 50 | |
| 51 | // Inline utility functions |
| 52 | static inline bool isSkipLayer(const hwc_layer_t* l) { |
| 53 | return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER))); |
| 54 | } |
| 55 | |
| 56 | // Returns true if the buffer is yuv |
| 57 | static inline bool isYuvBuffer(const private_handle_t* hnd) { |
| 58 | return (hnd && (hnd->bufferType == BUFFER_TYPE_VIDEO)); |
| 59 | } |
| 60 | |
| 61 | //Return true if buffer is marked locked |
| 62 | static inline bool isBufferLocked(const private_handle_t* hnd) { |
| 63 | return (hnd && (private_handle_t::PRIV_FLAGS_HWC_LOCK & hnd->flags)); |
| 64 | } |
| 65 | |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 66 | }; //qhwc namespace |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 67 | |
| 68 | |
| 69 | // ----------------------------------------------------------------------------- |
| 70 | // HWC context |
| 71 | // This structure contains overall state |
| 72 | struct hwc_context_t { |
| 73 | hwc_composer_device_t device; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 74 | int numHwLayers; |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 75 | int mdpVersion; |
| 76 | bool hasOverlay; |
Naseer Ahmed | f48aef6 | 2012-07-20 09:05:53 -0700 | [diff] [blame] | 77 | int overlayInUse; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 78 | |
| 79 | //Framebuffer device |
| 80 | framebuffer_device_t *fbDev; |
| 81 | |
| 82 | //Overlay object - NULL for non overlay devices |
| 83 | overlay::Overlay *mOverlay; |
| 84 | |
| 85 | //QueuedBufferStore to hold buffers for overlay |
| 86 | qhwc::QueuedBufferStore *qbuf; |
Naseer Ahmed | 0c8b7b5 | 2012-07-20 09:06:13 -0700 | [diff] [blame^] | 87 | |
| 88 | // External display related information |
| 89 | qhwc::ExtDisplayObserver*mExtDisplayObserver; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 92 | #endif //HWC_UTILS_H |