Add a http performance test script based on wrk
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / libs / GLESv2_dec / GLESv2Decoder.cpp
1 /*
2 * Copyright 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
17 #include "GLESv2Decoder.h"
18
19 #include <EGL/egl.h>
20 #include <GLES2/gl2.h>
21 #include <GLES2/gl2ext.h>
22
23 static inline void* SafePointerFromUInt(GLuint value) {
24   return (void*)(uintptr_t)value;
25 }
26
27 GLESv2Decoder::GLESv2Decoder()
28 {
29     m_contextData = NULL;
30     m_GL2library = NULL;
31 }
32
33 GLESv2Decoder::~GLESv2Decoder()
34 {
35     delete m_GL2library;
36 }
37
38 void *GLESv2Decoder::s_getProc(const char *name, void *userData)
39 {
40     GLESv2Decoder *ctx = (GLESv2Decoder *) userData;
41
42     if (ctx == NULL || ctx->m_GL2library == NULL) {
43         return NULL;
44     }
45
46     void *func = NULL;
47 #ifdef USE_EGL_GETPROCADDRESS
48     func = (void *) eglGetProcAddress(name);
49 #endif
50     if (func == NULL) {
51         func = (void *) ctx->m_GL2library->findSymbol(name);
52     }
53     return func;
54 }
55
56 int GLESv2Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
57 {
58     this->initDispatchByName(getProcFunc, getProcFuncData);
59
60     glGetCompressedTextureFormats = s_glGetCompressedTextureFormats;
61     glVertexAttribPointerData = s_glVertexAttribPointerData;
62     glVertexAttribPointerOffset = s_glVertexAttribPointerOffset;
63
64     glDrawElementsOffset = s_glDrawElementsOffset;
65     glDrawElementsData = s_glDrawElementsData;
66     glShaderString = s_glShaderString;
67     glFinishRoundTrip = s_glFinishRoundTrip;
68     return 0;
69
70 }
71
72 int GLESv2Decoder::s_glFinishRoundTrip(void *self)
73 {
74     GLESv2Decoder *ctx = (GLESv2Decoder *)self;
75     ctx->glFinish();
76     return 0;
77 }
78
79 void GLESv2Decoder::s_glGetCompressedTextureFormats(void *self, int count, GLint *formats)
80 {
81     GLESv2Decoder *ctx = (GLESv2Decoder *) self;
82
83     int nFormats;
84     ctx->glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &nFormats);
85     if (nFormats > count) {
86         fprintf(stderr, "%s: GetCompressedTextureFormats: The requested number of formats does not match the number that is reported by OpenGL\n", __FUNCTION__);
87     } else {
88         ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
89     }
90 }
91
92 void GLESv2Decoder::s_glVertexAttribPointerData(void *self, GLuint indx, GLint size, GLenum type,
93                                              GLboolean normalized, GLsizei stride,  void * data, GLuint datalen)
94 {
95     GLESv2Decoder *ctx = (GLESv2Decoder *) self;
96     if (ctx->m_contextData != NULL) {
97         ctx->m_contextData->storePointerData(indx, data, datalen);
98         // note - the stride of the data is always zero when it comes out of the codec.
99         // See gl2.attrib for the packing function call.
100         ctx->glVertexAttribPointer(indx, size, type, normalized, 0, ctx->m_contextData->pointerData(indx));
101     }
102 }
103
104 void GLESv2Decoder::s_glVertexAttribPointerOffset(void *self, GLuint indx, GLint size, GLenum type,
105                                                GLboolean normalized, GLsizei stride,  GLuint data)
106 {
107     GLESv2Decoder *ctx = (GLESv2Decoder *) self;
108     ctx->glVertexAttribPointer(indx, size, type, normalized, stride, SafePointerFromUInt(data));
109 }
110
111
112 void GLESv2Decoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen)
113 {
114     GLESv2Decoder *ctx = (GLESv2Decoder *)self;
115     ctx->glDrawElements(mode, count, type, data);
116 }
117
118
119 void GLESv2Decoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset)
120 {
121     GLESv2Decoder *ctx = (GLESv2Decoder *)self;
122     ctx->glDrawElements(mode, count, type, SafePointerFromUInt(offset));
123 }
124
125 void GLESv2Decoder::s_glShaderString(void *self, GLuint shader, const GLchar* string, GLsizei len)
126 {
127     GLESv2Decoder *ctx = (GLESv2Decoder *)self;
128     ctx->glShaderSource(shader, 1, &string, NULL);
129 }