tcuAndroidInternals.hpp revision b035773dba9d9886d5cc0eef92feeba24b279c24
1#ifndef _TCUANDROIDINTERNALS_HPP
2#define _TCUANDROIDINTERNALS_HPP
3/*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
6 *
7 * Copyright 2014 The Android Open Source Project
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 *      http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 *//*!
22 * \file
23 * \brief Access to Android internals that are not a part of the NDK.
24 *//*--------------------------------------------------------------------*/
25
26#include "tcuDefs.hpp"
27
28#include "deDynamicLibrary.hpp"
29
30#include <vector>
31#include <errno.h>
32
33struct ANativeWindowBuffer;
34
35namespace android
36{
37class GraphicBuffer;
38}
39
40namespace tcu
41{
42
43namespace Android
44{
45
46// These classes and enums reflect internal android definitions
47namespace internal
48{
49
50// utils/Errors.h
51enum
52{
53	OK					= 0,
54	UNKNOWN_ERROR		= (-2147483647-1),
55	NO_MEMORY			= -ENOMEM,
56	INVALID_OPERATION	= -ENOSYS,
57	BAD_VALUE			= -EINVAL,
58	BAD_TYPE			= (UNKNOWN_ERROR + 1),
59	NAME_NOT_FOUND		= -ENOENT,
60	PERMISSION_DENIED	= -EPERM,
61	NO_INIT				= -ENODEV,
62	ALREADY_EXISTS		= -EEXIST,
63	DEAD_OBJECT			= -EPIPE,
64	FAILED_TRANSACTION	= (UNKNOWN_ERROR + 2),
65	JPARKS_BROKE_IT		= -EPIPE,
66	BAD_INDEX			= -E2BIG,
67	NOT_ENOUGH_DATA		= (UNKNOWN_ERROR + 3),
68	WOULD_BLOCK			= (UNKNOWN_ERROR + 4),
69	TIMED_OUT			= (UNKNOWN_ERROR + 5),
70	UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6),
71	FDS_NOT_ALLOWED		= (UNKNOWN_ERROR + 7),
72};
73
74typedef deInt32 status_t;
75
76// ui/PixelFormat.h, system/graphics.h
77enum
78{
79	PIXEL_FORMAT_UNKNOWN				= 0,
80	PIXEL_FORMAT_NONE					= 0,
81	PIXEL_FORMAT_CUSTOM					= -4,
82	PIXEL_FORMAT_TRANSLUCENT			= -3,
83	PIXEL_FORMAT_TRANSPARENT			= -2,
84	PIXEL_FORMAT_OPAQUE					= -1,
85	PIXEL_FORMAT_RGBA_8888				= 1,
86	PIXEL_FORMAT_RGBX_8888				= 2,
87	PIXEL_FORMAT_RGB_888				= 3,
88	PIXEL_FORMAT_RGB_565				= 4,
89	PIXEL_FORMAT_BGRA_8888				= 5,
90	PIXEL_FORMAT_RGBA_5551				= 6,
91	PIXEL_FORMAT_RGBA_4444				= 7,
92};
93
94typedef deInt32 PixelFormat;
95
96// ui/GraphicBuffer.h
97struct GraphicBufferFunctions
98{
99	typedef android::GraphicBuffer*	(*constructorFunc)		(void* memory, deUint32 w, deUint32 h, PixelFormat format, deUint32 usage);
100	typedef void*					(*destructorFunc)		(android::GraphicBuffer* buffer);
101	typedef status_t				(*lockFunc)				(android::GraphicBuffer* buffer, deUint32 usage, void** vaddr);
102	typedef status_t				(*unlockFunc)			(android::GraphicBuffer* buffer);
103	typedef ANativeWindowBuffer*	(*getNativeBufferFunc)	(const android::GraphicBuffer* buffer);
104
105	constructorFunc					constructor;
106	destructorFunc					destructor;
107	lockFunc						lock;
108	unlockFunc						unlock;
109	getNativeBufferFunc				getNativeBuffer;
110};
111
112struct LibUIFunctions
113{
114	GraphicBufferFunctions graphicBuffer;
115};
116
117class LibUI
118{
119public:
120	struct Functions
121	{
122		GraphicBufferFunctions graphicBuffer;
123	};
124
125							LibUI			(void);
126	const Functions&		getFunctions	(void) const { return m_functions; }
127
128private:
129	Functions				m_functions;
130	de::DynamicLibrary		m_library;
131};
132
133class GraphicBuffer
134{
135public:
136	// ui/GraphicBuffer.h, hardware/gralloc.h
137	enum {
138		USAGE_SW_READ_NEVER		= 0x00000000,
139		USAGE_SW_READ_RARELY	= 0x00000002,
140		USAGE_SW_READ_OFTEN		= 0x00000003,
141		USAGE_SW_READ_MASK		= 0x0000000f,
142
143		USAGE_SW_WRITE_NEVER	= 0x00000000,
144		USAGE_SW_WRITE_RARELY	= 0x00000020,
145		USAGE_SW_WRITE_OFTEN	= 0x00000030,
146		USAGE_SW_WRITE_MASK		= 0x000000f0,
147
148		USAGE_SOFTWARE_MASK		= USAGE_SW_READ_MASK | USAGE_SW_WRITE_MASK,
149
150		USAGE_PROTECTED			= 0x00004000,
151
152		USAGE_HW_TEXTURE		= 0x00000100,
153		USAGE_HW_RENDER			= 0x00000200,
154		USAGE_HW_2D				= 0x00000400,
155		USAGE_HW_COMPOSER		= 0x00000800,
156		USAGE_HW_VIDEO_ENCODER	= 0x00010000,
157		USAGE_HW_MASK			= 0x00071F00,
158	};
159
160									GraphicBuffer			(const LibUI& lib, deUint32 width, deUint32 height, PixelFormat format, deUint32 usage);
161									~GraphicBuffer			();
162
163	status_t						lock					(deUint32 usage, void** vaddr);
164	status_t						unlock					(void);
165	ANativeWindowBuffer*			getNativeBuffer			(void) const;
166
167private:
168	const GraphicBufferFunctions&	m_functions;
169	std::vector<deUint8>			m_memory;
170	android::GraphicBuffer*			m_impl;
171};
172
173} // internal
174} // Android
175} // tcu
176
177#endif // _TCUANDROIDINTERNALS_HPP
178