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