Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
Ramkumar Radhakrishnan | db89d1f | 2016-03-07 20:15:52 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011 - 2016, 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> |
Sushil Chauhan | 082acd6 | 2015-01-14 16:49:29 -0800 | [diff] [blame] | 30 | #include "adreno_utils.h" |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 31 | |
| 32 | /*****************************************************************************/ |
| 33 | |
| 34 | struct private_module_t; |
| 35 | struct private_handle_t; |
| 36 | |
Saurabh Shah | 8f0ea6f | 2014-05-19 16:48:53 -0700 | [diff] [blame] | 37 | inline unsigned int roundUpToPageSize(unsigned int x) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 38 | return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1); |
| 39 | } |
| 40 | |
Arun Kumar K.R | 6c85f05 | 2014-01-21 21:47:41 -0800 | [diff] [blame] | 41 | template <class Type> |
| 42 | inline Type ALIGN(Type x, Type align) { |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 43 | return (x + align-1) & ~(align-1); |
| 44 | } |
| 45 | |
| 46 | #define FALSE 0 |
| 47 | #define TRUE 1 |
| 48 | |
| 49 | int mapFrameBufferLocked(struct private_module_t* module); |
| 50 | int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd); |
Saurabh Shah | 8f0ea6f | 2014-05-19 16:48:53 -0700 | [diff] [blame] | 51 | unsigned int getBufferSizeAndDimensions(int width, int height, int format, |
| 52 | int usage, int& alignedw, int &alignedh); |
| 53 | unsigned int getBufferSizeAndDimensions(int width, int height, int format, |
| 54 | int& alignedw, int &alignedh); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 55 | |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 56 | |
| 57 | // Attributes include aligned width, aligned height, tileEnabled and size of the buffer |
| 58 | void getBufferAttributes(int width, int height, int format, int usage, |
| 59 | int& alignedw, int &alignedh, |
Saurabh Shah | 8f0ea6f | 2014-05-19 16:48:53 -0700 | [diff] [blame] | 60 | int& tileEnabled, unsigned int &size); |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 61 | |
| 62 | |
| 63 | bool isMacroTileEnabled(int format, int usage); |
| 64 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 65 | int decideBufferHandlingMechanism(int format, const char *compositionUsed, |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 66 | int hasBlitEngine, int *needConversion, |
| 67 | int *useBufferDirectly); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 68 | |
| 69 | // Allocate buffer from width, height, format into a private_handle_t |
| 70 | // It is the responsibility of the caller to free the buffer |
| 71 | int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage); |
| 72 | void free_buffer(private_handle_t *hnd); |
Naseer Ahmed | b29fdfd | 2014-04-08 20:23:47 -0400 | [diff] [blame] | 73 | int getYUVPlaneInfo(private_handle_t* pHnd, struct android_ycbcr* ycbcr); |
Sushil Chauhan | c85b65b | 2015-04-30 11:05:36 -0700 | [diff] [blame] | 74 | int getRgbDataAddress(private_handle_t* pHnd, void** rgb_data); |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 75 | |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 76 | // To query if UBWC is enabled, based on format and usage flags |
| 77 | bool isUBwcEnabled(int format, int usage); |
| 78 | |
Ramkumar Radhakrishnan | db89d1f | 2016-03-07 20:15:52 -0800 | [diff] [blame] | 79 | // Function to check if the format is an RGB format |
Naomi Luis | cffc5bd | 2015-08-28 14:57:31 -0700 | [diff] [blame] | 80 | bool isUncompressedRgbFormat(int format); |
| 81 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 82 | /*****************************************************************************/ |
| 83 | |
| 84 | class Locker { |
| 85 | pthread_mutex_t mutex; |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 86 | pthread_cond_t cond; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 87 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 88 | class Autolock { |
| 89 | Locker& locker; |
Naseer Ahmed | 29a2681 | 2012-06-14 00:56:20 -0700 | [diff] [blame] | 90 | public: |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 91 | inline Autolock(Locker& locker) : locker(locker) { locker.lock(); } |
| 92 | inline ~Autolock() { locker.unlock(); } |
| 93 | }; |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 94 | inline Locker() { |
| 95 | pthread_mutex_init(&mutex, 0); |
| 96 | pthread_cond_init(&cond, 0); |
| 97 | } |
| 98 | inline ~Locker() { |
| 99 | pthread_mutex_destroy(&mutex); |
| 100 | pthread_cond_destroy(&cond); |
| 101 | } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 102 | inline void lock() { pthread_mutex_lock(&mutex); } |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 103 | inline void wait() { pthread_cond_wait(&cond, &mutex); } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 104 | inline void unlock() { pthread_mutex_unlock(&mutex); } |
Raj kamal | 59fea56 | 2014-04-01 16:52:19 +0530 | [diff] [blame] | 105 | inline void signal() { pthread_cond_signal(&cond); } |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 108 | |
| 109 | class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo> |
| 110 | { |
| 111 | public: |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 112 | AdrenoMemInfo(); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 113 | |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 114 | ~AdrenoMemInfo(); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 115 | |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 116 | /* |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 117 | * Function to compute aligned width and aligned height based on |
| 118 | * width, height, format and usage flags. |
| 119 | * |
| 120 | * @return aligned width, aligned height |
| 121 | */ |
| 122 | void getAlignedWidthAndHeight(int width, int height, int format, |
| 123 | int usage, int& aligned_w, int& aligned_h); |
| 124 | |
| 125 | /* |
Manoj Kumar AVM | 8e1aa18 | 2015-08-05 19:45:16 -0700 | [diff] [blame] | 126 | * Function to compute aligned width and aligned height based on |
| 127 | * private handle |
| 128 | * |
| 129 | * @return aligned width, aligned height |
| 130 | */ |
| 131 | void getAlignedWidthAndHeight(const private_handle_t *hnd, int& aligned_w, int& aligned_h); |
| 132 | |
| 133 | /* |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 134 | * Function to compute the adreno aligned width and aligned height |
| 135 | * based on the width and format. |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 136 | * |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 137 | * @return aligned width, aligned height |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 138 | */ |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 139 | void getGpuAlignedWidthHeight(int width, int height, int format, |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 140 | int tileEnabled, int& alignedw, int &alignedh); |
| 141 | |
| 142 | /* |
| 143 | * Function to return whether GPU support MacroTile feature |
| 144 | * |
| 145 | * @return >0 : supported |
| 146 | * 0 : not supported |
| 147 | */ |
| 148 | int isMacroTilingSupportedByGPU(); |
| 149 | |
Sushil Chauhan | 65e2630 | 2015-01-14 10:48:57 -0800 | [diff] [blame] | 150 | /* |
| 151 | * Function to query whether GPU supports UBWC for given HAL format |
| 152 | * @return > 0 : supported |
| 153 | * 0 : not supported |
| 154 | */ |
| 155 | int isUBWCSupportedByGPU(int format); |
| 156 | |
Sushil Chauhan | 082acd6 | 2015-01-14 16:49:29 -0800 | [diff] [blame] | 157 | /* |
| 158 | * Function to get the corresponding Adreno format for given HAL format |
| 159 | */ |
| 160 | ADRENOPIXELFORMAT getGpuPixelFormat(int hal_format); |
| 161 | |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 162 | private: |
Mohan Maiya | cbeab9e | 2015-04-20 09:20:44 -0700 | [diff] [blame] | 163 | // Overriding flag to disable UBWC alloc for graphics stack |
| 164 | int gfx_ubwc_disable; |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 165 | // Pointer to the padding library. |
| 166 | void *libadreno_utils; |
| 167 | |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 168 | // link(s)to adreno surface padding library. |
Naomi Luis | 01f5c8e | 2013-02-11 12:46:24 -0800 | [diff] [blame] | 169 | int (*LINK_adreno_compute_padding) (int width, int bpp, |
| 170 | int surface_tile_height, |
| 171 | int screen_tile_height, |
| 172 | int padding_threshold); |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 173 | |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 174 | void (*LINK_adreno_compute_aligned_width_and_height) (int width, |
| 175 | int height, |
| 176 | int bpp, |
| 177 | int tile_mode, |
| 178 | int raster_mode, |
| 179 | int padding_threshold, |
| 180 | int *aligned_w, |
| 181 | int *aligned_h); |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 182 | |
Manoj Kumar AVM | 8a22081 | 2013-10-10 11:46:06 -0700 | [diff] [blame] | 183 | int (*LINK_adreno_isMacroTilingSupportedByGpu) (void); |
Ramkumar Radhakrishnan | 473f408 | 2013-11-04 14:29:18 -0800 | [diff] [blame] | 184 | |
Jeykumar Sankaran | 2ba2051 | 2014-02-27 15:21:42 -0800 | [diff] [blame] | 185 | void(*LINK_adreno_compute_compressedfmt_aligned_width_and_height)( |
| 186 | int width, |
| 187 | int height, |
| 188 | int format, |
| 189 | int tile_mode, |
| 190 | int raster_mode, |
| 191 | int padding_threshold, |
| 192 | int *aligned_w, |
| 193 | int *aligned_h, |
| 194 | int *bpp); |
Sushil Chauhan | 082acd6 | 2015-01-14 16:49:29 -0800 | [diff] [blame] | 195 | |
| 196 | int (*LINK_adreno_isUBWCSupportedByGpu) (ADRENOPIXELFORMAT format); |
Sushil Chauhan | 521ce35 | 2015-08-28 11:33:30 -0700 | [diff] [blame] | 197 | |
| 198 | unsigned int (*LINK_adreno_get_gpu_pixel_alignment) (); |
Naomi Luis | a44100c | 2013-02-08 12:42:03 -0800 | [diff] [blame] | 199 | }; |
Ramakant Singh | c85ccee | 2016-04-01 15:25:17 +0530 | [diff] [blame] | 200 | |
| 201 | |
| 202 | class MDPCapabilityInfo : public android::Singleton <MDPCapabilityInfo> |
| 203 | { |
Sushil Chauhan | 0136141 | 2016-04-25 16:36:18 -0700 | [diff] [blame^] | 204 | int isMacroTileSupported = 0; |
| 205 | int isUBwcSupported = 0; |
| 206 | |
Ramakant Singh | c85ccee | 2016-04-01 15:25:17 +0530 | [diff] [blame] | 207 | public: |
| 208 | MDPCapabilityInfo(); |
| 209 | /* |
| 210 | * Function to return whether MDP support MacroTile feature |
| 211 | * |
| 212 | * @return 1 : supported |
| 213 | * 0 : not supported |
| 214 | */ |
Sushil Chauhan | 0136141 | 2016-04-25 16:36:18 -0700 | [diff] [blame^] | 215 | int isMacroTilingSupportedByMDP() { return isMacroTileSupported; } |
| 216 | /* |
| 217 | * Function to return whether MDP supports UBWC feature |
| 218 | * |
| 219 | * @return 1 : supported |
| 220 | * 0 : not supported |
| 221 | */ |
| 222 | int isUBwcSupportedByMDP() { return isUBwcSupported; } |
Ramakant Singh | c85ccee | 2016-04-01 15:25:17 +0530 | [diff] [blame] | 223 | }; |
| 224 | |
Iliyan Malchev | 202a77d | 2012-06-11 14:41:12 -0700 | [diff] [blame] | 225 | #endif /* GR_H_ */ |