blob: edeca3f6a6218baec229f16aa1be91f9b56dc510 [file] [log] [blame]
Iliyan Malchev202a77d2012-06-11 14:41:12 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
Saurabh Shahc5b2b702016-10-24 17:16:01 -07003 * Copyright (c) 2011 - 2017, 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>
Dileep Marchya5b4eaed2016-09-22 12:31:11 +053027#include <unistd.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070028
29#include <cutils/native_handle.h>
Naomi Luisa44100c2013-02-08 12:42:03 -080030#include <utils/Singleton.h>
Sushil Chauhan082acd62015-01-14 16:49:29 -080031#include "adreno_utils.h"
Iliyan Malchev202a77d2012-06-11 14:41:12 -070032
33/*****************************************************************************/
34
35struct private_module_t;
36struct private_handle_t;
37
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070038inline unsigned int roundUpToPageSize(unsigned int x) {
Dileep Marchya5b4eaed2016-09-22 12:31:11 +053039 return (x + (getpagesize()-1)) & ~(getpagesize()-1);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070040}
41
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080042template <class Type>
43inline Type ALIGN(Type x, Type align) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070044 return (x + align-1) & ~(align-1);
45}
46
47#define FALSE 0
48#define TRUE 1
49
50int mapFrameBufferLocked(struct private_module_t* module);
51int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
Saurabh Shah8f0ea6f2014-05-19 16:48:53 -070052unsigned int getBufferSizeAndDimensions(int width, int height, int format,
53 int usage, int& alignedw, int &alignedh);
54unsigned int getBufferSizeAndDimensions(int width, int height, int format,
55 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070056
57int decideBufferHandlingMechanism(int format, const char *compositionUsed,
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 int hasBlitEngine, int *needConversion,
59 int *useBufferDirectly);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070060
61// Allocate buffer from width, height, format into a private_handle_t
62// It is the responsibility of the caller to free the buffer
63int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
64void free_buffer(private_handle_t *hnd);
Naseer Ahmedb29fdfd2014-04-08 20:23:47 -040065int getYUVPlaneInfo(private_handle_t* pHnd, struct android_ycbcr* ycbcr);
Sushil Chauhanc85b65b2015-04-30 11:05:36 -070066int getRgbDataAddress(private_handle_t* pHnd, void** rgb_data);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070067
Sushil Chauhan65e26302015-01-14 10:48:57 -080068// To query if UBWC is enabled, based on format and usage flags
69bool isUBwcEnabled(int format, int usage);
70
Ramkumar Radhakrishnandb89d1f2016-03-07 20:15:52 -080071// Function to check if the format is an RGB format
Naomi Luiscffc5bd2015-08-28 14:57:31 -070072bool isUncompressedRgbFormat(int format);
73
Saurabh Shaha228f122017-01-23 15:55:25 -080074#ifdef COMPILE_DRM
75int getPlaneStrideOffset(private_handle_t *hnd, uint32_t *stride,
76 uint32_t *offset, uint32_t *num_planes);
77
78void getDRMFormat(int hal_format, int flags, uint32_t *drm_format,
79 uint64_t *drm_format_modifier);
80#endif
Iliyan Malchev202a77d2012-06-11 14:41:12 -070081/*****************************************************************************/
82
83class Locker {
84 pthread_mutex_t mutex;
Raj kamal59fea562014-04-01 16:52:19 +053085 pthread_cond_t cond;
Naseer Ahmed29a26812012-06-14 00:56:20 -070086 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070087 class Autolock {
88 Locker& locker;
Naseer Ahmed29a26812012-06-14 00:56:20 -070089 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070090 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
91 inline ~Autolock() { locker.unlock(); }
92 };
Raj kamal59fea562014-04-01 16:52:19 +053093 inline Locker() {
94 pthread_mutex_init(&mutex, 0);
95 pthread_cond_init(&cond, 0);
96 }
97 inline ~Locker() {
98 pthread_mutex_destroy(&mutex);
99 pthread_cond_destroy(&cond);
100 }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700101 inline void lock() { pthread_mutex_lock(&mutex); }
Raj kamal59fea562014-04-01 16:52:19 +0530102 inline void wait() { pthread_cond_wait(&cond, &mutex); }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700103 inline void unlock() { pthread_mutex_unlock(&mutex); }
Raj kamal59fea562014-04-01 16:52:19 +0530104 inline void signal() { pthread_cond_signal(&cond); }
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700105};
106
Naomi Luisa44100c2013-02-08 12:42:03 -0800107
108class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
109{
110 public:
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 ~AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -0800114
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800115 /*
Sushil Chauhan65e26302015-01-14 10:48:57 -0800116 * Function to compute aligned width and aligned height based on
117 * width, height, format and usage flags.
118 *
119 * @return aligned width, aligned height
120 */
121 void getAlignedWidthAndHeight(int width, int height, int format,
122 int usage, int& aligned_w, int& aligned_h);
123
124 /*
Manoj Kumar AVM8e1aa182015-08-05 19:45:16 -0700125 * Function to compute aligned width and aligned height based on
126 * private handle
127 *
128 * @return aligned width, aligned height
129 */
130 void getAlignedWidthAndHeight(const private_handle_t *hnd, int& aligned_w, int& aligned_h);
131
132 /*
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800133 * Function to compute the adreno aligned width and aligned height
134 * based on the width and format.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800135 *
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800136 * @return aligned width, aligned height
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800137 */
Sushil Chauhan65e26302015-01-14 10:48:57 -0800138 void getGpuAlignedWidthHeight(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700139 int tileEnabled, int& alignedw, int &alignedh);
140
141 /*
Ramkumar Radhakrishnanba55eac2016-08-26 22:33:48 -0700142 * Function to compute unaligned width and unaligned height based on
143 * private handle
144 *
145 * @return unaligned width, unaligned height
146 */
147 void getUnalignedWidthAndHeight(const private_handle_t *hnd, int& unaligned_w,
148 int& unaligned_h);
Sushil Chauhan65e26302015-01-14 10:48:57 -0800149 /*
150 * Function to query whether GPU supports UBWC for given HAL format
151 * @return > 0 : supported
152 * 0 : not supported
153 */
154 int isUBWCSupportedByGPU(int format);
155
Sushil Chauhan082acd62015-01-14 16:49:29 -0800156 /*
157 * Function to get the corresponding Adreno format for given HAL format
158 */
159 ADRENOPIXELFORMAT getGpuPixelFormat(int hal_format);
160
Naomi Luisa44100c2013-02-08 12:42:03 -0800161 private:
Mohan Maiyacbeab9e2015-04-20 09:20:44 -0700162 // Overriding flag to disable UBWC alloc for graphics stack
163 int gfx_ubwc_disable;
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800164 // Pointer to the padding library.
165 void *libadreno_utils;
166
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800167 // link(s)to adreno surface padding library.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800168 int (*LINK_adreno_compute_padding) (int width, int bpp,
169 int surface_tile_height,
170 int screen_tile_height,
171 int padding_threshold);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800172
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800173 void (*LINK_adreno_compute_aligned_width_and_height) (int width,
174 int height,
175 int bpp,
176 int tile_mode,
177 int raster_mode,
178 int padding_threshold,
179 int *aligned_w,
180 int *aligned_h);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -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};
Ramakant Singhc85ccee2016-04-01 15:25:17 +0530197
198
199class MDPCapabilityInfo : public android::Singleton <MDPCapabilityInfo>
200{
Sushil Chauhan01361412016-04-25 16:36:18 -0700201 int isUBwcSupported = 0;
Jeykumar Sankaran9bc1a782015-12-14 18:36:27 -0800202 int isWBUBWCSupported = 0;
Sushil Chauhan01361412016-04-25 16:36:18 -0700203
Ramakant Singhc85ccee2016-04-01 15:25:17 +0530204 public:
205 MDPCapabilityInfo();
206 /*
Sushil Chauhan01361412016-04-25 16:36:18 -0700207 * Function to return whether MDP supports UBWC feature
208 *
209 * @return 1 : supported
210 * 0 : not supported
211 */
212 int isUBwcSupportedByMDP() { return isUBwcSupported; }
Jeykumar Sankaran9bc1a782015-12-14 18:36:27 -0800213 /*
214 * Function to return whether MDP WB block outputs UBWC format
215 *
216 * @return 1 : supported
217 * 0 : not supported
218 */
219 int isWBUBWCSupportedByMDP() { return isWBUBWCSupported; }
Ramakant Singhc85ccee2016-04-01 15:25:17 +0530220};
221
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700222#endif /* GR_H_ */