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 JPARKS_BROKE_IT = -EPIPE, 67 BAD_INDEX = -E2BIG, 68 NOT_ENOUGH_DATA = (UNKNOWN_ERROR + 3), 69 WOULD_BLOCK = (UNKNOWN_ERROR + 4), 70 TIMED_OUT = (UNKNOWN_ERROR + 5), 71 UNKNOWN_TRANSACTION = (UNKNOWN_ERROR + 6), 72 FDS_NOT_ALLOWED = (UNKNOWN_ERROR + 7), 73 }; 74 75 typedef deInt32 status_t; 76 77 // ui/PixelFormat.h, system/graphics.h 78 enum 79 { 80 PIXEL_FORMAT_UNKNOWN = 0, 81 PIXEL_FORMAT_NONE = 0, 82 PIXEL_FORMAT_CUSTOM = -4, 83 PIXEL_FORMAT_TRANSLUCENT = -3, 84 PIXEL_FORMAT_TRANSPARENT = -2, 85 PIXEL_FORMAT_OPAQUE = -1, 86 PIXEL_FORMAT_RGBA_8888 = 1, 87 PIXEL_FORMAT_RGBX_8888 = 2, 88 PIXEL_FORMAT_RGB_888 = 3, 89 PIXEL_FORMAT_RGB_565 = 4, 90 PIXEL_FORMAT_BGRA_8888 = 5, 91 PIXEL_FORMAT_RGBA_5551 = 6, 92 PIXEL_FORMAT_RGBA_4444 = 7, 93 }; 94 95 typedef deInt32 PixelFormat; 96 97 // ui/GraphicBuffer.h 98 struct GraphicBufferFunctions 99 { 100 typedef void (*genericFunc) (); 101 typedef status_t (*initCheckFunc) (android::GraphicBuffer* buffer); 102 typedef status_t (*lockFunc) (android::GraphicBuffer* buffer, deUint32 usage, void** vaddr); 103 typedef status_t (*unlockFunc) (android::GraphicBuffer* buffer); 104 typedef ANativeWindowBuffer* (*getNativeBufferFunc) (const android::GraphicBuffer* buffer); 105 106 genericFunc constructor; 107 genericFunc destructor; 108 lockFunc lock; 109 unlockFunc unlock; 110 getNativeBufferFunc getNativeBuffer; 111 initCheckFunc initCheck; 112 }; 113 114 // system/window.h 115 struct NativeBaseFunctions 116 { 117 typedef void (*incRefFunc) (android::android_native_base_t* base); 118 typedef void (*decRefFunc) (android::android_native_base_t* base); 119 120 incRefFunc incRef; 121 decRefFunc decRef; 122 }; 123 124 struct LibUIFunctions 125 { 126 GraphicBufferFunctions graphicBuffer; 127 }; 128 129 class LibUI 130 { 131 public: 132 struct Functions 133 { 134 GraphicBufferFunctions graphicBuffer; 135 }; 136 137 LibUI (void); getFunctions(void) const138 const Functions& getFunctions (void) const { return m_functions; } 139 140 private: 141 Functions m_functions; 142 de::DynamicLibrary m_library; 143 }; 144 145 class GraphicBuffer 146 { 147 public: 148 // ui/GraphicBuffer.h, hardware/gralloc.h 149 enum { 150 USAGE_SW_READ_NEVER = 0x00000000, 151 USAGE_SW_READ_RARELY = 0x00000002, 152 USAGE_SW_READ_OFTEN = 0x00000003, 153 USAGE_SW_READ_MASK = 0x0000000f, 154 155 USAGE_SW_WRITE_NEVER = 0x00000000, 156 USAGE_SW_WRITE_RARELY = 0x00000020, 157 USAGE_SW_WRITE_OFTEN = 0x00000030, 158 USAGE_SW_WRITE_MASK = 0x000000f0, 159 160 USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK | USAGE_SW_WRITE_MASK, 161 162 USAGE_PROTECTED = 0x00004000, 163 164 USAGE_HW_TEXTURE = 0x00000100, 165 USAGE_HW_RENDER = 0x00000200, 166 USAGE_HW_2D = 0x00000400, 167 USAGE_HW_COMPOSER = 0x00000800, 168 USAGE_HW_VIDEO_ENCODER = 0x00010000, 169 USAGE_HW_MASK = 0x00071F00, 170 }; 171 172 GraphicBuffer (const LibUI& lib, deUint32 width, deUint32 height, PixelFormat format, deUint32 usage); 173 ~GraphicBuffer (); 174 175 status_t lock (deUint32 usage, void** vaddr); 176 status_t unlock (void); 177 ANativeWindowBuffer* getNativeBuffer (void) const; 178 179 private: 180 const GraphicBufferFunctions& m_functions; 181 NativeBaseFunctions m_baseFunctions; 182 android::GraphicBuffer* m_impl; 183 }; 184 185 } // internal 186 } // Android 187 } // tcu 188 189 #endif // _TCUANDROIDINTERNALS_HPP 190