Home | History | Annotate | Download | only in android
      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 
     33 struct ANativeWindowBuffer;
     34 
     35 namespace android
     36 {
     37 class GraphicBuffer;
     38 class android_native_base_t;
     39 }
     40 
     41 namespace tcu
     42 {
     43 
     44 namespace Android
     45 {
     46 
     47 // These classes and enums reflect internal android definitions
     48 namespace internal
     49 {
     50 
     51 // utils/Errors.h
     52 enum
     53 {
     54 	OK					= 0,
     55 	UNKNOWN_ERROR		= (-2147483647-1),
     56 	NO_MEMORY			= -ENOMEM,
     57 	INVALID_OPERATION	= -ENOSYS,
     58 	BAD_VALUE			= -EINVAL,
     59 	BAD_TYPE			= (UNKNOWN_ERROR + 1),
     60 	NAME_NOT_FOUND		= -ENOENT,
     61 	PERMISSION_DENIED	= -EPERM,
     62 	NO_INIT				= -ENODEV,
     63 	ALREADY_EXISTS		= -EEXIST,
     64 	DEAD_OBJECT			= -EPIPE,
     65 	FAILED_TRANSACTION	= (UNKNOWN_ERROR + 2),
     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 
     74 typedef deInt32 status_t;
     75 
     76 // ui/PixelFormat.h, system/graphics.h
     77 enum
     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 
     94 typedef deInt32 PixelFormat;
     95 
     96 // ui/GraphicBuffer.h
     97 struct GraphicBufferFunctions
     98 {
     99 	typedef void					(*genericFunc)			();
    100 	typedef status_t				(*initCheckFunc)		(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 	genericFunc						constructor;
    106 	genericFunc						destructor;
    107 	lockFunc						lock;
    108 	unlockFunc						unlock;
    109 	getNativeBufferFunc				getNativeBuffer;
    110 	initCheckFunc					initCheck;
    111 };
    112 
    113 // system/window.h
    114 struct NativeBaseFunctions
    115 {
    116 	typedef void	(*incRefFunc)			(android::android_native_base_t* base);
    117 	typedef void	(*decRefFunc)			(android::android_native_base_t* base);
    118 
    119 	incRefFunc		incRef;
    120 	decRefFunc		decRef;
    121 };
    122 
    123 struct LibUIFunctions
    124 {
    125 	GraphicBufferFunctions graphicBuffer;
    126 };
    127 
    128 class LibUI
    129 {
    130 public:
    131 	struct Functions
    132 	{
    133 		GraphicBufferFunctions graphicBuffer;
    134 	};
    135 
    136 							LibUI			(void);
    137 	const Functions&		getFunctions	(void) const { return m_functions; }
    138 
    139 private:
    140 	Functions				m_functions;
    141 	de::DynamicLibrary		m_library;
    142 };
    143 
    144 class GraphicBuffer
    145 {
    146 public:
    147 	// ui/GraphicBuffer.h, hardware/gralloc.h
    148 	enum {
    149 		USAGE_SW_READ_NEVER		= 0x00000000,
    150 		USAGE_SW_READ_RARELY	= 0x00000002,
    151 		USAGE_SW_READ_OFTEN		= 0x00000003,
    152 		USAGE_SW_READ_MASK		= 0x0000000f,
    153 
    154 		USAGE_SW_WRITE_NEVER	= 0x00000000,
    155 		USAGE_SW_WRITE_RARELY	= 0x00000020,
    156 		USAGE_SW_WRITE_OFTEN	= 0x00000030,
    157 		USAGE_SW_WRITE_MASK		= 0x000000f0,
    158 
    159 		USAGE_SOFTWARE_MASK		= USAGE_SW_READ_MASK | USAGE_SW_WRITE_MASK,
    160 
    161 		USAGE_PROTECTED			= 0x00004000,
    162 
    163 		USAGE_HW_TEXTURE		= 0x00000100,
    164 		USAGE_HW_RENDER			= 0x00000200,
    165 		USAGE_HW_2D				= 0x00000400,
    166 		USAGE_HW_COMPOSER		= 0x00000800,
    167 		USAGE_HW_VIDEO_ENCODER	= 0x00010000,
    168 		USAGE_HW_MASK			= 0x00071F00,
    169 	};
    170 
    171 									GraphicBuffer			(const LibUI& lib, deUint32 width, deUint32 height, PixelFormat format, deUint32 usage);
    172 									~GraphicBuffer			();
    173 
    174 	status_t						lock					(deUint32 usage, void** vaddr);
    175 	status_t						unlock					(void);
    176 	ANativeWindowBuffer*			getNativeBuffer			(void) const;
    177 
    178 private:
    179 	const GraphicBufferFunctions&	m_functions;
    180 	NativeBaseFunctions				m_baseFunctions;
    181 	android::GraphicBuffer*			m_impl;
    182 };
    183 
    184 } // internal
    185 } // Android
    186 } // tcu
    187 
    188 #endif // _TCUANDROIDINTERNALS_HPP
    189