1 /*
2 * Copyright (C) 2008 The Android Open Source Project
3 * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
4 *
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 #include <sys/user.h>
23 #include <limits.h>
24 #include <sys/cdefs.h>
25 #include <hardware/gralloc.h>
26 #include <pthread.h>
27 #include <errno.h>
28
29 #include <cutils/native_handle.h>
30 #include <utils/Singleton.h>
31
32 /*****************************************************************************/
33
34 struct private_module_t;
35 struct private_handle_t;
36
roundUpToPageSize(size_t x)37 inline size_t roundUpToPageSize(size_t x) {
38 return (x + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1);
39 }
40
ALIGN(size_t x,size_t align)41 inline size_t ALIGN(size_t x, size_t align) {
42 return (x + align-1) & ~(align-1);
43 }
44
45 #define FALSE 0
46 #define TRUE 1
47
48 int mapFrameBufferLocked(struct private_module_t* module);
49 int terminateBuffer(gralloc_module_t const* module, private_handle_t* hnd);
50 size_t getBufferSizeAndDimensions(int width, int height, int format,
51 int& alignedw, int &alignedh);
52
53 int decideBufferHandlingMechanism(int format, const char *compositionUsed,
54 int hasBlitEngine, int *needConversion,
55 int *useBufferDirectly);
56
57 // Allocate buffer from width, height, format into a private_handle_t
58 // It is the responsibility of the caller to free the buffer
59 int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage);
60 void free_buffer(private_handle_t *hnd);
61
62 /*****************************************************************************/
63
64 class Locker {
65 pthread_mutex_t mutex;
66 public:
67 class Autolock {
68 Locker& locker;
69 public:
Autolock(Locker & locker)70 inline Autolock(Locker& locker) : locker(locker) { locker.lock(); }
~Autolock()71 inline ~Autolock() { locker.unlock(); }
72 };
Locker()73 inline Locker() { pthread_mutex_init(&mutex, 0); }
~Locker()74 inline ~Locker() { pthread_mutex_destroy(&mutex); }
lock()75 inline void lock() { pthread_mutex_lock(&mutex); }
unlock()76 inline void unlock() { pthread_mutex_unlock(&mutex); }
77 };
78
79
80 class AdrenoMemInfo : public android::Singleton <AdrenoMemInfo>
81 {
82 public:
83 AdrenoMemInfo();
84
85 ~AdrenoMemInfo();
86
87 /*
88 * Function to compute the adreno stride based on the width and format.
89 *
90 * @return stride.
91 */
92 int getStride(int width, int format);
93
94 private:
95 // Pointer to the padding library.
96 void *libadreno_utils;
97
98 // link to the surface padding library.
99 int (*LINK_adreno_compute_padding) (int width, int bpp,
100 int surface_tile_height,
101 int screen_tile_height,
102 int padding_threshold);
103 };
104 #endif /* GR_H_ */
105