2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef GRALLOC_PRIV_H_
18 #define GRALLOC_PRIV_H_
22 #include <sys/cdefs.h>
23 #include <hardware/gralloc.h>
28 #include <cutils/native_handle.h>
31 #include <linux/ion.h>
34 PREFER_COMPRESSION_NO_CHANGE
= 0x00,
35 PREFER_COMPRESSION_ENABLE
= 0x01,
36 PREFER_COMPRESSION_DISABLE
= 0x02,
39 /*****************************************************************************/
41 struct private_module_t
;
42 struct private_handle_t
;
44 struct private_module_t
{
45 gralloc_module_t base
;
47 private_handle_t
* framebuffer
;
52 buffer_handle_t currentBuffer
;
55 struct fb_var_screeninfo info
;
56 struct fb_fix_screeninfo finfo
;
64 pthread_mutex_t queue_lock
;
68 /*****************************************************************************/
71 struct private_handle_t
: public native_handle
{
73 struct private_handle_t
{
74 struct native_handle nativeHandle
;
78 PRIV_FLAGS_FRAMEBUFFER
= 0x00000001,
79 PRIV_FLAGS_USES_UMP
= 0x00000002,
80 PRIV_FLAGS_USES_ION
= 0x00000020
100 ion_user_handle_t handle
;
101 ion_user_handle_t handle1
;
102 ion_user_handle_t handle2
;
104 // FIXME: the attributes below should be out-of-line
105 uint64_t base
__attribute__((aligned(8)));
106 uint64_t base1
__attribute__((aligned(8)));
107 uint64_t base2
__attribute__((aligned(8)));
110 static inline int sNumInts() {
111 return (((sizeof(private_handle_t
) - sizeof(native_handle_t
))/sizeof(int)) - sNumFds
);
113 static const int sNumFds
= 3;
114 static const int sMagic
= 0x3141592;
116 private_handle_t(int fd
, int size
, int flags
) :
117 fd(fd
), fd1(-1), fd2(-1), magic(sMagic
), flags(flags
), size(size
),
118 offset(0), format(0), width(0), height(0), stride(0), vstride(0), frameworkFormat(0),
119 handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0),
120 dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE
),
121 internal_format(0), is_compressible(0), compressed_out(0)
124 version
= sizeof(native_handle
);
125 numInts
= sNumInts() + 2;
126 numFds
= sNumFds
-2 ;
129 private_handle_t(int fd
, int size
, int flags
, int w
,
130 int h
, int format
, uint64_t internal_format
, int frameworkFormat
, int stride
, int vstride
, int is_compressible
) :
131 fd(fd
), fd1(-1), fd2(-1), magic(sMagic
), flags(flags
), size(size
),
132 offset(0), format(format
), width(w
), height(h
), stride(stride
), vstride(vstride
), frameworkFormat(frameworkFormat
),
133 handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0),
134 dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE
),
135 internal_format(internal_format
), is_compressible(is_compressible
), compressed_out(0)
138 version
= sizeof(native_handle
);
139 numInts
= sNumInts() + 2;
140 numFds
= sNumFds
- 2;
143 private_handle_t(int fd
, int fd1
, int size
, int flags
, int w
,
144 int h
, int format
, uint64_t internal_format
, int frameworkFormat
, int stride
, int vstride
, int is_compressible
) :
145 fd(fd
), fd1(fd1
), fd2(-1), magic(sMagic
), flags(flags
), size(size
),
146 offset(0), format(format
), width(w
), height(h
), stride(stride
), vstride(vstride
), frameworkFormat(frameworkFormat
),
147 handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0),
148 dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE
),
149 internal_format(internal_format
), is_compressible(is_compressible
), compressed_out(0)
152 version
= sizeof(native_handle
);
153 numInts
= sNumInts() + 1;
154 numFds
= sNumFds
- 1;
157 private_handle_t(int fd
, int fd1
, int fd2
, int size
, int flags
, int w
,
158 int h
, int format
, uint64_t internal_format
, int frameworkFormat
, int stride
, int vstride
, int is_compressible
) :
159 fd(fd
), fd1(fd1
), fd2(fd2
), magic(sMagic
), flags(flags
), size(size
),
160 offset(0), format(format
), width(w
), height(h
), stride(stride
), vstride(vstride
), frameworkFormat(frameworkFormat
),
161 handle(0), handle1(0), handle2(0), base(0), base1(0), base2(0),
162 dssRatio(0), prefer_compression(PREFER_COMPRESSION_NO_CHANGE
),
163 internal_format(internal_format
), is_compressible(is_compressible
), compressed_out(0)
166 version
= sizeof(native_handle
);
167 numInts
= sNumInts();
170 ~private_handle_t() {
174 static int validate(const native_handle
* h
) {
175 const private_handle_t
* hnd
= (const private_handle_t
*)h
;
176 if (!h
|| h
->version
!= sizeof(native_handle
) ||
177 hnd
->numInts
+ hnd
->numFds
!= sNumInts() + sNumFds
||
178 hnd
->magic
!= sMagic
)
180 ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle
*>(h
)));
186 static private_handle_t
* dynamicCast(const native_handle
* in
)
188 if (validate(in
) == 0)
189 return (private_handle_t
*) in
;
204 int prefer_compression
;
205 uint64_t internal_format
;
213 #define DSS_CROP_Y 360
214 #define DSS_CROP_W 1920
215 #define DSS_CROP_H 1080
218 PRIVATE_DATA_DSS_STATUS
= 0x00000001,
219 PRIVATE_DATA_DSS_CROP
= 0x00000002
222 #define CRC_LIMIT_WIDTH (720)
223 #define CRC_LIMIT_HEIGHT (1280)
224 #define CRC_TILE_SIZE (16)
225 #define CRC_BUFFER_KEY (0x12131415)
226 struct gralloc_crc_header
{
232 #endif /* GRALLOC_PRIV_H_ */