• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _RENDERING_THREAD_H_
17 #define _RENDERING_THREAD_H_
18 
19 #include "SocketStream.h"
20 #include "GLDecoder.h"
21 #include "GL2Decoder.h"
22 #include "ut_rendercontrol_dec.h"
23 #include <pthread.h>
24 
25 #define GL_API
26 #define GL_APIENTRY
27 
28 #include <GLES/egl.h>
29 #include <GLES/gl.h>
30 
31 
32 #define WINDOW_WIDTH    320
33 #define WINDOW_HEIGHT   480
34 
35 #define DECODER_BUF_SIZE (4 * 1024 * 1024)
36 
37 class RendererContext;
38 
39 class RenderingThread {
40 public:
41     RenderingThread(SocketStream *stream);
42     int start();
43     void *thread();
currentContext()44     RendererContext *currentContext() { return m_currentContext; }
setCurrentContext(RendererContext * ctx)45     void setCurrentContext(RendererContext *ctx) { m_currentContext = ctx; }
glDecoder()46     GLDecoder & glDecoder() { return m_glDec; }
gl2Decoder()47     GL2Decoder & gl2Decoder() { return m_gl2Dec; }
48 
49 private:
50     void initBackendCaps();
51 
52 private:
53     GLDecoder   m_glDec;
54     ut_rendercontrol_decoder_context_t m_utDec;
55     GL2Decoder m_gl2Dec;
56 
57     SocketStream   *m_stream;
58     pthread_t m_thread;
59     RendererContext * m_currentContext;
60 
61     struct BackendCaps {
62         bool initialized;
63         GLuint maxTextureUnits;
64     } m_backendCaps;
65 
66     static void * s_thread(void *data);
67     static __thread RenderingThread *m_tls;
68 
69     static int s_createContext(uint32_t pid, uint32_t handle, uint32_t shareCtx, int version);
70     static int s_createSurface(uint32_t pid, uint32_t handle);
71     static int s_destroySurface(uint32_t pid, uint32_t handle);
72     static int s_destroyContext(uint32_t pid, uint32_t handle);
73     static int s_makeCurrent(uint32_t pid, uint32_t drawSurface, uint32_t readSurface, uint32_t ctx);
74     static void s_swapBuffers(uint32_t pid, uint32_t surface);
75 #ifdef PVR_WAR
76     static void s_glTexParameteriv(GLenum target, GLenum param, const int *p);
77     static void s_glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLfloat h);
78     static void s_glDrawTexsOES(GLshort x, GLshort y, GLshort z, GLshort w, GLshort h);
79     static void s_glDrawTexiOES(GLint x, GLint y, GLint z, GLint w, GLint h);
80     static void s_glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z, GLfixed w, GLfixed h);
81     static void s_glDrawTexfvOES(const GLfloat *coords);
82     static void s_glDrawTexsvOES(const GLshort *coords);
83     static void s_glDrawTexivOES(const GLint *coords);
84     static void s_glDrawTexxvOES(const GLfixed *coords);
85 
86     static void s_glActiveTexture(GLenum texture);
87     static void s_glBindTexture(GLenum target, GLuint texture);
88     static void s_glEnable(GLenum cap);
89     static void s_glDisable(GLenum cap);
90     static void s_glClientActiveTexture(GLenum texture);
91     static void s_glEnableClientState(GLenum cap);
92     static void s_glDisableClientState(GLenum cap);
93 
94     void applyPendingCropRects();
95     void fixTextureEnable();
96 
97     glTexParameteriv_server_proc_t m_glTexParameteriv;
98     glDrawTexfOES_server_proc_t m_glDrawTexfOES;
99     glDrawTexiOES_server_proc_t m_glDrawTexiOES;
100     glDrawTexsOES_server_proc_t m_glDrawTexsOES;
101     glDrawTexxOES_server_proc_t m_glDrawTexxOES;
102     glDrawTexfvOES_server_proc_t m_glDrawTexfvOES;
103     glDrawTexivOES_server_proc_t m_glDrawTexivOES;
104     glDrawTexsvOES_server_proc_t m_glDrawTexsvOES;
105     glDrawTexxvOES_server_proc_t m_glDrawTexxvOES;
106     glActiveTexture_server_proc_t m_glActiveTexture;
107     glBindTexture_server_proc_t m_glBindTexture;
108     glEnable_server_proc_t m_glEnable;
109     glDisable_server_proc_t m_glDisable;
110     glClientActiveTexture_server_proc_t m_glClientActiveTexture;
111     glEnableClientState_server_proc_t m_glEnableClientState;
112     glDisableClientState_server_proc_t m_glDisableClientState;
113 #endif
114 
115 };
116 
117 #endif
118