blob: 8c68e1692e4cb3891e32bcefaa1e1398a84cada7 [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
45inline size_t ALIGN(size_t x, size_t align) {
46 return (x + align-1) & ~(align-1);
47}
48
49#define FALSE 0
50#define TRUE 1
51
52int mapFrameBufferLocked(struct private_module_t* module);
53int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070054size_t getBufferSizeAndDimensions(int width, int height, int format, int usage,
55 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070056size_t getBufferSizeAndDimensions(int width, int height, int format,
Naseer Ahmed29a26812012-06-14 00:56:20 -070057 int& alignedw, int &alignedh);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070058
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070059
60// Attributes include aligned width, aligned height, tileEnabled and size of the buffer
61void getBufferAttributes(int width, int height, int format, int usage,
62 int& alignedw, int &alignedh,
63 int& tileEnabled, size_t &size);
64
65
66bool isMacroTileEnabled(int format, int usage);
67
Iliyan Malchev202a77d2012-06-11 14:41:12 -070068int decideBufferHandlingMechanism(int format, const char *compositionUsed,
Naseer Ahmed29a26812012-06-14 00:56:20 -070069 int hasBlitEngine, int *needConversion,
70 int *useBufferDirectly);
Iliyan Malchev202a77d2012-06-11 14:41:12 -070071
72// Allocate buffer from width, height, format into a private_handle_t
73// It is the responsibility of the caller to free the buffer
74int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
75void free_buffer(private_handle_t *hnd);
76
77/*****************************************************************************/
78
79class Locker {
80 pthread_mutex_t mutex;
Naseer Ahmed29a26812012-06-14 00:56:20 -070081 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070082 class Autolock {
83 Locker& locker;
Naseer Ahmed29a26812012-06-14 00:56:20 -070084 public:
Iliyan Malchev202a77d2012-06-11 14:41:12 -070085 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
86 inline ~Autolock() { locker.unlock(); }
87 };
88 inline Locker() { pthread_mutex_init(&mutex, 0); }
89 inline ~Locker() { pthread_mutex_destroy(&mutex); }
90 inline void lock() { pthread_mutex_lock(&mutex); }
91 inline void unlock() { pthread_mutex_unlock(&mutex); }
92};
93
Naomi Luisa44100c2013-02-08 12:42:03 -080094
95class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
96{
97 public:
Naomi Luis01f5c8e2013-02-11 12:46:24 -080098 AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -080099
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800100 ~AdrenoMemInfo();
Naomi Luisa44100c2013-02-08 12:42:03 -0800101
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800102 /*
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800103 * Function to compute the adreno aligned width and aligned height
104 * based on the width and format.
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800105 *
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800106 * @return aligned width, aligned height
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800107 */
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800108 void getAlignedWidthAndHeight(int width, int height, int format,
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700109 int tileEnabled, int& alignedw, int &alignedh);
110
111 /*
112 * Function to return whether GPU support MacroTile feature
113 *
114 * @return >0 : supported
115 * 0 : not supported
116 */
117 int isMacroTilingSupportedByGPU();
118
Naomi Luisa44100c2013-02-08 12:42:03 -0800119 private:
Naomi Luis01f5c8e2013-02-11 12:46:24 -0800120 // Pointer to the padding library.
121 void *libadreno_utils;
122
123 // link to the surface padding library.
124 int (*LINK_adreno_compute_padding) (int width, int bpp,
125 int surface_tile_height,
126 int screen_tile_height,
127 int padding_threshold);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800128 // link to the surface padding library.
129 void (*LINK_adreno_compute_aligned_width_and_height) (int width,
130 int height,
131 int bpp,
132 int tile_mode,
133 int raster_mode,
134 int padding_threshold,
135 int *aligned_w,
136 int *aligned_h);
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700137 // link to the surface padding library.
138 int (*LINK_adreno_isMacroTilingSupportedByGpu) (void);
Ramkumar Radhakrishnan473f4082013-11-04 14:29:18 -0800139
Naomi Luisa44100c2013-02-08 12:42:03 -0800140};
Iliyan Malchev202a77d2012-06-11 14:41:12 -0700141#endif /* GR_H_ */