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 #ifndef _GL_ENCODER_H_
17 #define _GL_ENCODER_H_
18 
19 #include "gl_enc.h"
20 #include "GLClientState.h"
21 #include "GLSharedGroup.h"
22 #include "FixedBuffer.h"
23 #include "ChecksumCalculator.h"
24 
25 class GLEncoder : public gl_encoder_context_t {
26 
27 public:
28     GLEncoder(IOStream *stream, ChecksumCalculator* protocol);
29     virtual ~GLEncoder();
setClientState(GLClientState * state)30     void setClientState(GLClientState *state) {
31         m_state = state;
32     }
setSharedGroup(GLSharedGroupPtr shared)33     void setSharedGroup(GLSharedGroupPtr shared) { m_shared = shared; }
flush()34     void flush() { m_stream->flush(); }
35     size_t pixelDataSize(GLsizei width, GLsizei height, GLenum format, GLenum type, int pack);
36 
setInitialized()37     void setInitialized(){ m_initialized = true; };
isInitialized()38     bool isInitialized(){ return m_initialized; };
39 
setError(GLenum error)40     virtual void setError(GLenum error){ m_error = error; };
getError()41     virtual GLenum getError() { return m_error; };
42 
43     void override2DTextureTarget(GLenum target);
44     void restore2DTextureTarget();
45 
46 private:
47 
48     bool    m_initialized;
49     GLClientState *m_state;
50     GLSharedGroupPtr m_shared;
51     GLenum  m_error;
52     FixedBuffer m_fixedBuffer;
53     GLint *m_compressedTextureFormats;
54     GLint m_num_compressedTextureFormats;
55 
56     GLint *getCompressedTextureFormats();
57     // original functions;
58     glGetError_client_proc_t    m_glGetError_enc;
59     glGetIntegerv_client_proc_t m_glGetIntegerv_enc;
60     glGetFloatv_client_proc_t m_glGetFloatv_enc;
61     glGetFixedv_client_proc_t m_glGetFixedv_enc;
62     glGetBooleanv_client_proc_t m_glGetBooleanv_enc;
63     glGetPointerv_client_proc_t m_glGetPointerv_enc;
64 
65     glPixelStorei_client_proc_t m_glPixelStorei_enc;
66     glVertexPointer_client_proc_t m_glVertexPointer_enc;
67     glNormalPointer_client_proc_t m_glNormalPointer_enc;
68     glColorPointer_client_proc_t m_glColorPointer_enc;
69     glPointSizePointerOES_client_proc_t m_glPointSizePointerOES_enc;
70     glTexCoordPointer_client_proc_t m_glTexCoordPointer_enc;
71     glClientActiveTexture_client_proc_t m_glClientActiveTexture_enc;
72     glMatrixIndexPointerOES_client_proc_t m_glMatrixIndexPointerOES_enc;
73     glWeightPointerOES_client_proc_t m_glWeightPointerOES_enc;
74 
75     glBindBuffer_client_proc_t m_glBindBuffer_enc;
76     glBufferData_client_proc_t m_glBufferData_enc;
77     glBufferSubData_client_proc_t m_glBufferSubData_enc;
78     glDeleteBuffers_client_proc_t m_glDeleteBuffers_enc;
79 
80     glEnableClientState_client_proc_t m_glEnableClientState_enc;
81     glDisableClientState_client_proc_t m_glDisableClientState_enc;
82     glIsEnabled_client_proc_t m_glIsEnabled_enc;
83     glDrawArrays_client_proc_t m_glDrawArrays_enc;
84     glDrawElements_client_proc_t m_glDrawElements_enc;
85     glFlush_client_proc_t m_glFlush_enc;
86 
87     glActiveTexture_client_proc_t m_glActiveTexture_enc;
88     glBindTexture_client_proc_t m_glBindTexture_enc;
89     glDeleteTextures_client_proc_t m_glDeleteTextures_enc;
90     glDisable_client_proc_t m_glDisable_enc;
91     glEnable_client_proc_t m_glEnable_enc;
92     glGetTexParameterfv_client_proc_t m_glGetTexParameterfv_enc;
93     glGetTexParameteriv_client_proc_t m_glGetTexParameteriv_enc;
94     glGetTexParameterxv_client_proc_t m_glGetTexParameterxv_enc;
95     glTexParameterf_client_proc_t m_glTexParameterf_enc;
96     glTexParameterfv_client_proc_t m_glTexParameterfv_enc;
97     glTexParameteri_client_proc_t m_glTexParameteri_enc;
98     glTexParameterx_client_proc_t m_glTexParameterx_enc;
99     glTexParameteriv_client_proc_t m_glTexParameteriv_enc;
100     glTexParameterxv_client_proc_t m_glTexParameterxv_enc;
101 
102     // statics
103     static GLenum s_glGetError(void * self);
104     static void s_glGetIntegerv(void *self, GLenum pname, GLint *ptr);
105     static void s_glGetBooleanv(void *self, GLenum pname, GLboolean *ptr);
106     static void s_glGetFloatv(void *self, GLenum pname, GLfloat *ptr);
107     static void s_glGetFixedv(void *self, GLenum pname, GLfixed *ptr);
108     static void s_glGetPointerv(void *self, GLenum pname, GLvoid **params);
109 
110     static void s_glFlush(void * self);
111     static const GLubyte * s_glGetString(void *self, GLenum name);
112     static void s_glVertexPointer(void *self, int size, GLenum type, GLsizei stride, const void *data);
113     static void s_glNormalPointer(void *self, GLenum type, GLsizei stride, const void *data);
114     static void s_glColorPointer(void *self, int size, GLenum type, GLsizei stride, const void *data);
115     static void s_glPointSizePointerOES(void *self, GLenum type, GLsizei stride, const void *data);
116     static void s_glClientActiveTexture(void *self, GLenum texture);
117     static void s_glTexCoordPointer(void *self, int size, GLenum type, GLsizei stride, const void *data);
118     static void s_glMatrixIndexPointerOES(void *self, int size, GLenum type, GLsizei stride, const void * data);
119     static void s_glWeightPointerOES(void *self, int size, GLenum type, GLsizei stride, const void * data);
120     static void s_glDisableClientState(void *self, GLenum state);
121     static void s_glEnableClientState(void *self, GLenum state);
122     static GLboolean s_glIsEnabled(void *self, GLenum cap);
123     static void s_glBindBuffer(void *self, GLenum target, GLuint id);
124     static void s_glBufferData(void *self, GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
125     static void s_glBufferSubData(void *self, GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data);
126     static void s_glDeleteBuffers(void *self, GLsizei n, const GLuint * buffers);
127 
128     static void s_glDrawArrays(void *self, GLenum mode, GLint first, GLsizei count);
129     static void s_glDrawElements(void *self, GLenum mode, GLsizei count, GLenum type, const void *indices);
130     static void s_glPixelStorei(void *self, GLenum param, GLint value);
131 
132     static void s_glFinish(void *self);
133     void sendVertexData(unsigned first, unsigned count);
134 
135     static void s_glActiveTexture(void* self, GLenum texture);
136     static void s_glBindTexture(void* self, GLenum target, GLuint texture);
137     static void s_glDeleteTextures(void* self, GLsizei n, const GLuint* textures);
138     static void s_glDisable(void* self, GLenum cap);
139     static void s_glEnable(void* self, GLenum cap);
140     static void s_glGetTexParameterfv(void* self, GLenum target, GLenum pname, GLfloat* params);
141     static void s_glGetTexParameteriv(void* self, GLenum target, GLenum pname, GLint* params);
142     static void s_glGetTexParameterxv(void* self, GLenum target, GLenum pname, GLfixed* params);
143     static void s_glTexParameterf(void* self, GLenum target, GLenum pname, GLfloat param);
144     static void s_glTexParameterfv(void* self, GLenum target, GLenum pname, const GLfloat* params);
145     static void s_glTexParameteri(void* self, GLenum target, GLenum pname, GLint param);
146     static void s_glTexParameterx(void* self, GLenum target, GLenum pname, GLfixed param);
147     static void s_glTexParameteriv(void* self, GLenum target, GLenum pname, const GLint* params);
148     static void s_glTexParameterxv(void* self, GLenum target, GLenum pname, const GLfixed* params);
149 
150 public:
151     glEGLImageTargetTexture2DOES_client_proc_t m_glEGLImageTargetTexture2DOES_enc;
152 
153 };
154 #endif
155