2 * Copyright (C) 2008 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>
32 /*****************************************************************************/
34 struct private_module_t
;
35 struct private_handle_t
;
36 typedef int ion_user_handle_t
;
38 struct private_module_t
{
39 gralloc_module_t base
;
41 struct private_handle_t
* framebuffer
;
46 buffer_handle_t currentBuffer
;
56 pthread_mutex_t queue_lock
;
60 /*****************************************************************************/
63 struct private_handle_t
: public native_handle
{
65 struct private_handle_t
{
66 struct native_handle nativeHandle
;
69 // set if using video encoding colorspace
70 #define GRALLOC_USAGE_PRIVATE_CHROMA (GRALLOC_USAGE_PRIVATE_0)
73 PRIV_FLAGS_FRAMEBUFFER
= 0x00000001,
74 PRIV_FLAGS_USES_UMP
= 0x00000002,
75 PRIV_FLAGS_USES_ION
= 0x00000020
96 // FIXME: the attributes below should be out-of-line
100 ion_user_handle_t handle
;
101 ion_user_handle_t handle1
;
102 ion_user_handle_t handle2
;
105 static const int sNumFds
= 3;
106 static const int sNumInts
= 17;
107 static const int sMagic
= 0x3141592;
110 private_handle_t(int fd
, int size
, int flags
, int w
,
111 int h
, int format
, int stride
, int vstride
) :
112 fd(fd
), fd1(-1), fd2(-1), magic(sMagic
), flags(flags
), size(size
),
113 offset(0), format(format
), width(w
), height(h
), stride(stride
),
114 vstride(vstride
), gamut(0), chroma(0), base(0), handle(0), handle1(0),
117 version
= sizeof(native_handle
);
118 numInts
= sNumInts
+ 2;
119 numFds
= sNumFds
- 2;
122 private_handle_t(int fd
, int fd1
, int size
, int flags
, int w
,
123 int h
, int format
, int stride
, int vstride
) :
124 fd(fd
), fd1(fd1
), fd2(-1), magic(sMagic
), flags(flags
), size(size
),
125 offset(0), format(format
), width(w
), height(h
), stride(stride
),
126 vstride(vstride
), gamut(0), chroma(0), base(0), base1(0), base2(0),
127 handle(0), handle1(0), handle2(0)
129 version
= sizeof(native_handle
);
130 numInts
= sNumInts
+ 1;
131 numFds
= sNumFds
- 1;
134 private_handle_t(int fd
, int fd1
, int fd2
, int size
, int flags
, int w
,
135 int h
, int format
, int stride
, int vstride
) :
136 fd(fd
), fd1(fd1
), fd2(fd2
), magic(sMagic
), flags(flags
), size(size
),
137 offset(0), format(format
), width(w
), height(h
), stride(stride
),
138 vstride(vstride
), gamut(0), chroma(0), base(0), base1(0), base2(0),
139 handle(0), handle1(0), handle2(0)
141 version
= sizeof(native_handle
);
145 ~private_handle_t() {
149 static int validate(const native_handle
* h
) {
150 const private_handle_t
* hnd
= (const private_handle_t
*)h
;
151 if (!h
|| h
->version
!= sizeof(native_handle
) ||
152 hnd
->numInts
+ hnd
->numFds
!= sNumInts
+ sNumFds
||
153 hnd
->magic
!= sMagic
)
155 ALOGE("invalid gralloc handle (at %p)", reinterpret_cast<void *>(const_cast<native_handle
*>(h
)));
161 static private_handle_t
* dynamicCast(const native_handle
* in
)
163 if (validate(in
) == 0)
164 return (private_handle_t
*) in
;
172 #endif /* GRALLOC_PRIV_H_ */