blob: d88db9d7fd2069a8f30b000aa207891590acc036 [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>
Iliyan Malchev202a77d2012-06-11 14:41:12 -070030
31/*****************************************************************************/
32
33struct private_module_t;
34struct private_handle_t;
35
36inline size_t roundUpToPageSize(size_t x) {
37 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
38}
39
Arun Kumar K.R6c85f052014-01-21 21:47:41 -080040template <class Type>
41inline Type ALIGN(Type x, Type align) {
Iliyan Malchev202a77d2012-06-11 14:41:12 -070042 return (x + align-1) & ~(align-1);
43}
44
45#define FALSE 0
46#define TRUE 1
47
48int mapFrameBufferLocked(struct private_module_t* module);
49int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070050size_t getBufferSizeAndDimensions(int width, int height, int format, int usage,
51 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070052size_t getBufferSizeAndDimensions(int width, int height, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -070053 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070054
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070055
56// Attributes include aligned width, aligned height, tileEnabled and size of the buffer
57void getBufferAttributes(int width, int height, int format, int usage,
58 int& alignedw, int &alignedh,
59 int& tileEnabled, size_t &size);
60
61
62bool isMacroTileEnabled(int format, int usage);
63
Iliyan Malchev202a77d2012-06-11 14:41:12 -070064int decideBufferHandlingMechanism(int format, const char *compositionUsed,
Naseer Ahmed29a26812012-06-14 00:56:20 -070065 int hasBlitEngine, int *needConversion,
66 int *useBufferDirectly);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070067
68// Allocate buffer from width, height, format into a private_handle_t
69// It is the responsibility of the caller to free the buffer
70int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
71void free_buffer(private_handle_t *hnd);
72
73/*****************************************************************************/
74
75class Locker {
76 pthread_mutex_t mutex;
Naseer Ahmed29a26812012-06-14 00:56:20 -070077 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070078 class Autolock {
79 Locker& locker;
Naseer Ahmed29a26812012-06-14 00:56:20 -070080 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070081 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
82 inline ~Autolock() { locker.unlock(); }
83 };
84 inline Locker() { pthread_mutex_init(&mutex, 0); }
85 inline ~Locker() { pthread_mutex_destroy(&mutex); }
86 inline void lock() { pthread_mutex_lock(&mutex); }
87 inline void unlock() { pthread_mutex_unlock(&mutex); }
88};
89
Naomi Luisa44100c2013-02-08 12:42:03 -080090
91class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
92{
93 public:
Naomi Luis01f5c8e2013-02-11 12:46:24 -080094 AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -080095
Naomi Luis01f5c8e2013-02-11 12:46:24 -080096 ~AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -080097
Naomi Luis01f5c8e2013-02-11 12:46:24 -080098 /*
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -080099 * Function to compute the adreno aligned width and aligned height
100 * based on the width and format.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800101 *
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800102 * @return aligned width, aligned height
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800103 */
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800104 void getAlignedWidthAndHeight(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700105 int tileEnabled, int& alignedw, int &alignedh);
106
107 /*
108 * Function to return whether GPU support MacroTile feature
109 *
110 * @return >0 : supported
111 * 0 : not supported
112 */
113 int isMacroTilingSupportedByGPU();
114
Naomi Luisa44100c2013-02-08 12:42:03 -0800115 private:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800116 // Pointer to the padding library.
117 void *libadreno_utils;
118
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800119 // link(s)to adreno surface padding library.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800120 int (*LINK_adreno_compute_padding) (int width, int bpp,
121 int surface_tile_height,
122 int screen_tile_height,
123 int padding_threshold);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800124
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800125 void (*LINK_adreno_compute_aligned_width_and_height) (int width,
126 int height,
127 int bpp,
128 int tile_mode,
129 int raster_mode,
130 int padding_threshold,
131 int *aligned_w,
132 int *aligned_h);
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800133
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700134 int (*LINK_adreno_isMacroTilingSupportedByGpu) (void);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800135
Jeykumar Sankaran2ba20512014-02-27 15:21:42 -0800136 void(*LINK_adreno_compute_compressedfmt_aligned_width_and_height)(
137 int width,
138 int height,
139 int format,
140 int tile_mode,
141 int raster_mode,
142 int padding_threshold,
143 int *aligned_w,
144 int *aligned_h,
145 int *bpp);
Naomi Luisa44100c2013-02-08 12:42:03 -0800146};
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700147#endif /* GR_H_ */