blob: 52e9cc4440985e1b9861405f4b45fd854c596de1 [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>
22#ifdef HAVE_ANDROID_OS // just want PAGE_SIZE define
23# include <asm/page.h>
24#else
25# include <sys/user.h>
26#endif
27#include <limits.h>
28#include <sys/cdefs.h>
29#include <hardware/gralloc.h>
30#include <pthread.h>
31#include <errno.h>
32
33#include <cutils/native_handle.h>
Naomi Luisa44100c2013-02-08 12:42:03 -080034#include <utils/Singleton.h>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070035
36/*****************************************************************************/
37
38struct private_module_t;
39struct private_handle_t;
40
41inline size_t roundUpToPageSize(size_t x) {
42 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
43}
44
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080045template <class Type>
46inline Type ALIGN(Type x, Type align) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070047 return (x + align-1) & ~(align-1);
48}
49
50#define FALSE 0
51#define TRUE 1
52
53int mapFrameBufferLocked(struct private_module_t* module);
54int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070055size_t getBufferSizeAndDimensions(int width, int height, int format, int usage,
56 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070057size_t getBufferSizeAndDimensions(int width, int height, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -070058 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070059
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070060
61// Attributes include aligned width, aligned height, tileEnabled and size of the buffer
62void getBufferAttributes(int width, int height, int format, int usage,
63 int& alignedw, int &alignedh,
64 int& tileEnabled, size_t &size);
65
66
67bool isMacroTileEnabled(int format, int usage);
68
Iliyan Malchev202a77d2012-06-11 14:41:12 -070069int decideBufferHandlingMechanism(int format, const char *compositionUsed,
Naseer Ahmed29a26812012-06-14 00:56:20 -070070 int hasBlitEngine, int *needConversion,
71 int *useBufferDirectly);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070072
73// Allocate buffer from width, height, format into a private_handle_t
74// It is the responsibility of the caller to free the buffer
75int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
76void free_buffer(private_handle_t *hnd);
77
78/*****************************************************************************/
79
80class Locker {
81 pthread_mutex_t mutex;
Naseer Ahmed29a26812012-06-14 00:56:20 -070082 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070083 class Autolock {
84 Locker& locker;
Naseer Ahmed29a26812012-06-14 00:56:20 -070085 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070086 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
87 inline ~Autolock() { locker.unlock(); }
88 };
89 inline Locker() { pthread_mutex_init(&mutex, 0); }
90 inline ~Locker() { pthread_mutex_destroy(&mutex); }
91 inline void lock() { pthread_mutex_lock(&mutex); }
92 inline void unlock() { pthread_mutex_unlock(&mutex); }
93};
94
Naomi Luisa44100c2013-02-08 12:42:03 -080095
96class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
97{
98 public:
Naomi Luis01f5c8e2013-02-11 12:46:24 -080099 AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -0800100
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800101 ~AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -0800102
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800103 /*
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800104 * Function to compute the adreno aligned width and aligned height
105 * based on the width and format.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800106 *
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800107 * @return aligned width, aligned height
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800108 */
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800109 void getAlignedWidthAndHeight(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700110 int tileEnabled, int& alignedw, int &alignedh);
111
112 /*
113 * Function to return whether GPU support MacroTile feature
114 *
115 * @return >0 : supported
116 * 0 : not supported
117 */
118 int isMacroTilingSupportedByGPU();
119
Naomi Luisa44100c2013-02-08 12:42:03 -0800120 private:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800121 // Pointer to the padding library.
122 void *libadreno_utils;
123
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800124 // link(s)to adreno surface padding library.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800125 int (*LINK_adreno_compute_padding) (int width, int bpp,
126 int surface_tile_height,
127 int screen_tile_height,
128 int padding_threshold);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800129
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800130 void (*LINK_adreno_compute_aligned_width_and_height) (int width,
131 int height,
132 int bpp,
133 int tile_mode,
134 int raster_mode,
135 int padding_threshold,
136 int *aligned_w,
137 int *aligned_h);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800138
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700139 int (*LINK_adreno_isMacroTilingSupportedByGpu) (void);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800140
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800141 void(*LINK_adreno_compute_compressedfmt_aligned_width_and_height)(
142 int width,
143 int height,
144 int format,
145 int tile_mode,
146 int raster_mode,
147 int padding_threshold,
148 int *aligned_w,
149 int *aligned_h,
150 int *bpp);
Naomi Luisa44100c2013-02-08 12:42:03 -0800151};
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700152#endif /* GR_H_ */