blob: f8b1577ae30aa757fbe8796f8bb5dc31494e0575 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Duy Truong73d36df2013-02-09 20:33:23 -08003 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
Iliyan Malchev202a77d2012-06-11 14:41:12 -07004 *
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 Malchev202a77d2012-06-11 14:41:12 -070022#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 Luisa44100c2013-02-08 12:42:03 -080029#include <utils/Singleton.h>
Sushil Chauhan082acd62015-01-14 16:49:29 -080030#include "adreno_utils.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070031
32/*****************************************************************************/
33
34struct private_module_t;
35struct private_handle_t;
36
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070037inline unsigned int roundUpToPageSize(unsigned int x) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070038 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
39}
40
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080041template <class Type>
42inline Type ALIGN(Type x, Type align) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070043 return (x + align-1) & ~(align-1);
44}
45
46#define FALSE 0
47#define TRUE 1
48
49int mapFrameBufferLocked(struct private_module_t* module);
50int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070051unsigned int getBufferSizeAndDimensions(int width, int height, int format,
52 int usage, int& alignedw, int &alignedh);
53unsigned int getBufferSizeAndDimensions(int width, int height, int format,
54 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070055
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070056
57// Attributes include aligned width, aligned height, tileEnabled and size of the buffer
58void getBufferAttributes(int width, int height, int format, int usage,
59 int& alignedw, int &alignedh,
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070060 int& tileEnabled, unsigned int &size);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070061
62
63bool isMacroTileEnabled(int format, int usage);
64
Iliyan Malchev202a77d2012-06-11 14:41:12 -070065int decideBufferHandlingMechanism(int format, const char *compositionUsed,
Naseer Ahmed29a26812012-06-14 00:56:20 -070066 int hasBlitEngine, int *needConversion,
67 int *useBufferDirectly);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070068
69// Allocate buffer from width, height, format into a private_handle_t
70// It is the responsibility of the caller to free the buffer
71int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
72void free_buffer(private_handle_t *hnd);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -040073int getYUVPlaneInfo(private_handle_t* pHnd, struct android_ycbcr* ycbcr);
Sushil Chauhanc85b65b2015-04-30 11:05:36 -070074int getRgbDataAddress(private_handle_t* pHnd, void** rgb_data);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070075
Sushil Chauhan65e26302015-01-14 10:48:57 -080076// To query if UBWC is enabled, based on format and usage flags
77bool isUBwcEnabled(int format, int usage);
78
Iliyan Malchev202a77d2012-06-11 14:41:12 -070079/*****************************************************************************/
80
81class Locker {
82 pthread_mutex_t mutex;
Raj kamal59fea562014-04-01 16:52:19 +053083 pthread_cond_t cond;
Naseer Ahmed29a26812012-06-14 00:56:20 -070084 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070085 class Autolock {
86 Locker& locker;
Naseer Ahmed29a26812012-06-14 00:56:20 -070087 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070088 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
89 inline ~Autolock() { locker.unlock(); }
90 };
Raj kamal59fea562014-04-01 16:52:19 +053091 inline Locker() {
92 pthread_mutex_init(&mutex, 0);
93 pthread_cond_init(&cond, 0);
94 }
95 inline ~Locker() {
96 pthread_mutex_destroy(&mutex);
97 pthread_cond_destroy(&cond);
98 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -070099 inline void lock() { pthread_mutex_lock(&mutex); }
Raj kamal59fea562014-04-01 16:52:19 +0530100 inline void wait() { pthread_cond_wait(&cond, &mutex); }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700101 inline void unlock() { pthread_mutex_unlock(&mutex); }
Raj kamal59fea562014-04-01 16:52:19 +0530102 inline void signal() { pthread_cond_signal(&cond); }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700103};
104
Naomi Luisa44100c2013-02-08 12:42:03 -0800105
106class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
107{
108 public:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800109 AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -0800110
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800111 ~AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -0800112
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800113 /*
Sushil Chauhan65e26302015-01-14 10:48:57 -0800114 * Function to compute aligned width and aligned height based on
115 * width, height, format and usage flags.
116 *
117 * @return aligned width, aligned height
118 */
119 void getAlignedWidthAndHeight(int width, int height, int format,
120 int usage, int& aligned_w, int& aligned_h);
121
122 /*
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700123 * Function to compute aligned width and aligned height based on
124 * private handle
125 *
126 * @return aligned width, aligned height
127 */
128 void getAlignedWidthAndHeight(const private_handle_t *hnd, int& aligned_w, int& aligned_h);
129
130 /*
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800131 * Function to compute the adreno aligned width and aligned height
132 * based on the width and format.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800133 *
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800134 * @return aligned width, aligned height
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800135 */
Sushil Chauhan65e26302015-01-14 10:48:57 -0800136 void getGpuAlignedWidthHeight(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700137 int tileEnabled, int& alignedw, int &alignedh);
138
139 /*
140 * Function to return whether GPU support MacroTile feature
141 *
142 * @return >0 : supported
143 * 0 : not supported
144 */
145 int isMacroTilingSupportedByGPU();
146
Sushil Chauhan65e26302015-01-14 10:48:57 -0800147 /*
148 * Function to query whether GPU supports UBWC for given HAL format
149 * @return > 0 : supported
150 * 0 : not supported
151 */
152 int isUBWCSupportedByGPU(int format);
153
Sushil Chauhan082acd62015-01-14 16:49:29 -0800154 /*
155 * Function to get the corresponding Adreno format for given HAL format
156 */
157 ADRENOPIXELFORMAT getGpuPixelFormat(int hal_format);
158
Naomi Luisa44100c2013-02-08 12:42:03 -0800159 private:
Mohan Maiyacbeab9e2015-04-20 09:20:44 -0700160 // Overriding flag to disable UBWC alloc for graphics stack
161 int gfx_ubwc_disable;
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800162 // Pointer to the padding library.
163 void *libadreno_utils;
164
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800165 // link(s)to adreno surface padding library.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800166 int (*LINK_adreno_compute_padding) (int width, int bpp,
167 int surface_tile_height,
168 int screen_tile_height,
169 int padding_threshold);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800170
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800171 void (*LINK_adreno_compute_aligned_width_and_height) (int width,
172 int height,
173 int bpp,
174 int tile_mode,
175 int raster_mode,
176 int padding_threshold,
177 int *aligned_w,
178 int *aligned_h);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800179
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700180 int (*LINK_adreno_isMacroTilingSupportedByGpu) (void);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800181
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800182 void(*LINK_adreno_compute_compressedfmt_aligned_width_and_height)(
183 int width,
184 int height,
185 int format,
186 int tile_mode,
187 int raster_mode,
188 int padding_threshold,
189 int *aligned_w,
190 int *aligned_h,
191 int *bpp);
Sushil Chauhan082acd62015-01-14 16:49:29 -0800192
193 int (*LINK_adreno_isUBWCSupportedByGpu) (ADRENOPIXELFORMAT format);
Sushil Chauhan521ce352015-08-28 11:33:30 -0700194
195 unsigned int (*LINK_adreno_get_gpu_pixel_alignment) ();
Naomi Luisa44100c2013-02-08 12:42:03 -0800196};
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700197#endif /* GR_H_ */