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