Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Duy Truong | 73d36df | 2013-02-09 20:33:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -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 GR_H_ |
| 19 | #define GR_H_ |
| 20 | |
| 21 | #include <stdint.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 22 | #include <limits.h> |
| 23 | #include <sys/cdefs.h> |
| 24 | #include <hardware/gralloc.h> |
| 25 | #include <pthread.h> |
| 26 | #include <errno.h> |
| 27 | |
| 28 | #include <cutils/native_handle.h> |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 29 | #include <utils/Singleton.h> |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 30 | |
| 31 | /*****************************************************************************/ |
| 32 | |
| 33 | struct private_module_t; |
| 34 | struct private_handle_t; |
| 35 | |
Saurabh Shah | 8f0ea6f | 2014-05-19 16:48:53 -0700 | [diff] [blame] | 36 | inline unsigned int roundUpToPageSize(unsigned int x) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 37 | return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); |
| 38 | } |
| 39 | |
Arun Kumar K.R | 6c85f05 | 2014-01-21 21:47:41 -0800 | [diff] [blame] | 40 | template <class Type> |
| 41 | inline Type ALIGN(Type x, Type align) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 42 | return (x + align-1) & ~(align-1); |
| 43 | } |
| 44 | |
| 45 | #define FALSE 0 |
| 46 | #define TRUE 1 |
| 47 | |
| 48 | int mapFrameBufferLocked(struct private_module_t* module); |
| 49 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); |
Saurabh Shah | 8f0ea6f | 2014-05-19 16:48:53 -0700 | [diff] [blame] | 50 | unsigned int getBufferSizeAndDimensions(int width, int height, int format, |
| 51 | int usage, int& alignedw, int &alignedh); |
| 52 | unsigned int getBufferSizeAndDimensions(int width, int height, int format, |
| 53 | int& alignedw, int &alignedh); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 54 | |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 55 | |
| 56 | // Attributes include aligned width, aligned height, tileEnabled and size of the buffer |
| 57 | void getBufferAttributes(int width, int height, int format, int usage, |
| 58 | int& alignedw, int &alignedh, |
Saurabh Shah | 8f0ea6f | 2014-05-19 16:48:53 -0700 | [diff] [blame] | 59 | int& tileEnabled, unsigned int &size); |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 60 | |
| 61 | |
| 62 | bool isMacroTileEnabled(int format, int usage); |
| 63 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 64 | int decideBufferHandlingMechanism(int format, const char *compositionUsed, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 65 | int hasBlitEngine, int *needConversion, |
| 66 | int *useBufferDirectly); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 67 | |
| 68 | // Allocate buffer from width, height, format into a private_handle_t |
| 69 | // It is the responsibility of the caller to free the buffer |
| 70 | int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage); |
| 71 | void free_buffer(private_handle_t *hnd); |
Naseer Ahmed | b29fdfd | 2014-04-08 20:23:47 -0400 | [diff] [blame] | 72 | int getYUVPlaneInfo(private_handle_t* pHnd, struct android_ycbcr* ycbcr); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 73 | |
| 74 | /*****************************************************************************/ |
| 75 | |
| 76 | class Locker { |
| 77 | pthread_mutex_t mutex; |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 78 | pthread_cond_t cond; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 79 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 80 | class Autolock { |
| 81 | Locker& locker; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 82 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 83 | inline Autolock(Locker& locker) : locker(locker) { locker.lock(); } |
| 84 | inline ~Autolock() { locker.unlock(); } |
| 85 | }; |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 86 | inline Locker() { |
| 87 | pthread_mutex_init(&mutex, 0); |
| 88 | pthread_cond_init(&cond, 0); |
| 89 | } |
| 90 | inline ~Locker() { |
| 91 | pthread_mutex_destroy(&mutex); |
| 92 | pthread_cond_destroy(&cond); |
| 93 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 94 | inline void lock() { pthread_mutex_lock(&mutex); } |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 95 | inline void wait() { pthread_cond_wait(&cond, &mutex); } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 96 | inline void unlock() { pthread_mutex_unlock(&mutex); } |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 97 | inline void signal() { pthread_cond_signal(&cond); } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 100 | |
| 101 | class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo> |
| 102 | { |
| 103 | public: |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 104 | AdrenoMemInfo(); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 105 | |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 106 | ~AdrenoMemInfo(); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 107 | |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 108 | /* |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 109 | * Function to compute the adreno aligned width and aligned height |
| 110 | * based on the width and format. |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 111 | * |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 112 | * @return aligned width, aligned height |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 113 | */ |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 114 | void getAlignedWidthAndHeight(int width, int height, int format, |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 115 | int tileEnabled, int& alignedw, int &alignedh); |
| 116 | |
| 117 | /* |
| 118 | * Function to return whether GPU support MacroTile feature |
| 119 | * |
| 120 | * @return >0 : supported |
| 121 | * 0 : not supported |
| 122 | */ |
| 123 | int isMacroTilingSupportedByGPU(); |
| 124 | |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 125 | private: |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 126 | // Pointer to the padding library. |
| 127 | void *libadreno_utils; |
| 128 | |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 129 | // link(s)to adreno surface padding library. |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 130 | int (*LINK_adreno_compute_padding) (int width, int bpp, |
| 131 | int surface_tile_height, |
| 132 | int screen_tile_height, |
| 133 | int padding_threshold); |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 134 | |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 135 | void (*LINK_adreno_compute_aligned_width_and_height) (int width, |
| 136 | int height, |
| 137 | int bpp, |
| 138 | int tile_mode, |
| 139 | int raster_mode, |
| 140 | int padding_threshold, |
| 141 | int *aligned_w, |
| 142 | int *aligned_h); |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 143 | |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 144 | int (*LINK_adreno_isMacroTilingSupportedByGpu) (void); |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 145 | |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 146 | void(*LINK_adreno_compute_compressedfmt_aligned_width_and_height)( |
| 147 | int width, |
| 148 | int height, |
| 149 | int format, |
| 150 | int tile_mode, |
| 151 | int raster_mode, |
| 152 | int padding_threshold, |
| 153 | int *aligned_w, |
| 154 | int *aligned_h, |
| 155 | int *bpp); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 156 | }; |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 157 | #endif /* GR_H_ */ |