4a227dcfb8855ae22a05a3eef2afde21cd96b4ef
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / libs / GLESv1_dec / GLESv1Decoder.cpp
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16 #include "GLESv1Decoder.h"
17
18 #include <EGL/egl.h>
19 #include <GLES/gl.h>
20 #include <GLES/glext.h>
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 static inline void* SafePointerFromUInt(GLuint value) {
27   return (void*)(uintptr_t)value;
28 }
29
30 GLESv1Decoder::GLESv1Decoder()
31 {
32     m_contextData = NULL;
33     m_glesDso = NULL;
34 }
35
36 GLESv1Decoder::~GLESv1Decoder()
37 {
38     if (m_glesDso != NULL) {
39         delete m_glesDso;
40     }
41 }
42
43
44 int GLESv1Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
45 {
46     this->initDispatchByName(getProcFunc, getProcFuncData);
47
48     glGetCompressedTextureFormats = s_glGetCompressedTextureFormats;
49     glVertexPointerOffset = s_glVertexPointerOffset;
50     glColorPointerOffset = s_glColorPointerOffset;
51     glNormalPointerOffset = s_glNormalPointerOffset;
52     glTexCoordPointerOffset = s_glTexCoordPointerOffset;
53     glPointSizePointerOffset = s_glPointSizePointerOffset;
54     glWeightPointerOffset = s_glWeightPointerOffset;
55     glMatrixIndexPointerOffset = s_glMatrixIndexPointerOffset;
56
57     glVertexPointerData = s_glVertexPointerData;
58     glColorPointerData = s_glColorPointerData;
59     glNormalPointerData = s_glNormalPointerData;
60     glTexCoordPointerData = s_glTexCoordPointerData;
61     glPointSizePointerData = s_glPointSizePointerData;
62     glWeightPointerData = s_glWeightPointerData;
63     glMatrixIndexPointerData = s_glMatrixIndexPointerData;
64
65     glDrawElementsOffset = s_glDrawElementsOffset;
66     glDrawElementsData = s_glDrawElementsData;
67     glFinishRoundTrip = s_glFinishRoundTrip;
68
69     return 0;
70 }
71
72 int GLESv1Decoder::s_glFinishRoundTrip(void *self)
73 {
74     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
75     ctx->glFinish();
76     return 0;
77 }
78
79 void GLESv1Decoder::s_glVertexPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
80 {
81     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
82     ctx->glVertexPointer(size, type, stride, SafePointerFromUInt(offset));
83 }
84
85 void GLESv1Decoder::s_glColorPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
86 {
87     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
88     ctx->glColorPointer(size, type, stride, SafePointerFromUInt(offset));
89 }
90
91 void GLESv1Decoder::s_glTexCoordPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
92 {
93     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
94     ctx->glTexCoordPointer(size, type, stride, SafePointerFromUInt(offset));
95 }
96
97 void GLESv1Decoder::s_glNormalPointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
98 {
99     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
100     ctx->glNormalPointer(type, stride, SafePointerFromUInt(offset));
101 }
102
103 void GLESv1Decoder::s_glPointSizePointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
104 {
105     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
106     ctx->glPointSizePointerOES(type, stride, SafePointerFromUInt(offset));
107 }
108
109 void GLESv1Decoder::s_glWeightPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
110 {
111     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
112     ctx->glWeightPointerOES(size, type, stride, SafePointerFromUInt(offset));
113 }
114
115 void GLESv1Decoder::s_glMatrixIndexPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
116 {
117     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
118     ctx->glMatrixIndexPointerOES(size, type, stride, SafePointerFromUInt(offset));
119 }
120
121
122
123 #define STORE_POINTER_DATA_OR_ABORT(location)    \
124     if (ctx->m_contextData != NULL) {   \
125         ctx->m_contextData->storePointerData((location), data, datalen); \
126     } else { \
127         return; \
128     }
129
130 void GLESv1Decoder::s_glVertexPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
131 {
132     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
133
134     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::VERTEX_LOCATION);
135
136     ctx->glVertexPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::VERTEX_LOCATION));
137 }
138
139 void GLESv1Decoder::s_glColorPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
140 {
141     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
142
143     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::COLOR_LOCATION);
144
145     ctx->glColorPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::COLOR_LOCATION));
146 }
147
148 void GLESv1Decoder::s_glTexCoordPointerData(void *self, GLint unit, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
149 {
150     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
151     STORE_POINTER_DATA_OR_ABORT((GLDecoderContextData::PointerDataLocation)
152                                 (GLDecoderContextData::TEXCOORD0_LOCATION + unit));
153
154     ctx->glTexCoordPointer(size, type, 0,
155                            ctx->m_contextData->pointerData((GLDecoderContextData::PointerDataLocation)
156                                                            (GLDecoderContextData::TEXCOORD0_LOCATION + unit)));
157 }
158
159 void GLESv1Decoder::s_glNormalPointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
160 {
161     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
162
163     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::NORMAL_LOCATION);
164
165     ctx->glNormalPointer(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::NORMAL_LOCATION));
166 }
167
168 void GLESv1Decoder::s_glPointSizePointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
169 {
170     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
171
172     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::POINTSIZE_LOCATION);
173
174     ctx->glPointSizePointerOES(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::POINTSIZE_LOCATION));
175 }
176
177 void GLESv1Decoder::s_glWeightPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
178 {
179     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
180
181     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::WEIGHT_LOCATION);
182
183     ctx->glWeightPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::WEIGHT_LOCATION));
184 }
185
186 void GLESv1Decoder::s_glMatrixIndexPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
187 {
188     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
189
190     STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::MATRIXINDEX_LOCATION);
191
192     ctx->glMatrixIndexPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::MATRIXINDEX_LOCATION));
193 }
194
195 void GLESv1Decoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset)
196 {
197     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
198     ctx->glDrawElements(mode, count, type, SafePointerFromUInt(offset));
199 }
200
201 void GLESv1Decoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen)
202 {
203     GLESv1Decoder *ctx = (GLESv1Decoder *)self;
204     ctx->glDrawElements(mode, count, type, data);
205 }
206
207 void GLESv1Decoder::s_glGetCompressedTextureFormats(void *self, GLint count, GLint *data)
208 {
209     GLESv1Decoder *ctx = (GLESv1Decoder *) self;
210     ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, data);
211 }
212
213 void *GLESv1Decoder::s_getProc(const char *name, void *userData)
214 {
215     GLESv1Decoder *ctx = (GLESv1Decoder *)userData;
216
217     if (ctx == NULL || ctx->m_glesDso == NULL) {
218         return NULL;
219     }
220
221     void *func = NULL;
222 #ifdef USE_EGL_GETPROCADDRESS
223     func = (void *) eglGetProcAddress(name);
224 #endif
225     if (func == NULL) {
226         func = (void *)(ctx->m_glesDso->findSymbol(name));
227     }
228     return func;
229 }