• 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 _RENDERER_CONTEXT_H_
17 #define _RENDERER_CONTEXT_H_
18 
19 #include "RendererObject.h"
20 #include "GLDecoderContextData.h"
21 
22 #include <EGL/egl.h>
23 #define GL_API
24 #define GL_APIENTRY
25 #include <GLES/gl.h>
26 #include <string.h>
27 
28 #ifdef PVR_WAR
29 #include <set>
30 struct PendingCropRect
31 {
32     GLuint texture;
33     int rect[4];
34 };
35 
36 typedef std::set<PendingCropRect *> PendingCropRectSet;
37 #endif
38 
39 class RendererContext : public RendererObject {
40 public:
41     static RendererContext *create(EGLDisplay dpy, EGLConfig config, RendererContext *shareCtx, int version);
eglContext()42     EGLContext eglContext() { return m_ctx; }
43     int destroy();
decoderContextData()44     GLDecoderContextData & decoderContextData() { return m_contextData; }
45 #ifdef PVR_WAR
46     void setActiveTexture(GLenum texture);
getActiveTexture()47     GLenum getActiveTexture() { return GL_TEXTURE0 + m_activeTexture; }
48     void setTex2DBind(GLuint texture);
setTex2DEnable(bool enable)49     void setTex2DEnable(bool enable) {
50         m_tex2DEnable[m_activeTexture] = enable;
51     }
isTex2DEnable(int texunit)52     bool isTex2DEnable(int texunit) { return m_tex2DEnable[texunit]; }
53     GLuint getTex2DBind();
54     void addPendingCropRect(const int *rect);
getPendingCropRects()55     PendingCropRectSet &getPendingCropRects() { return m_pendingCropRects; }
56 
setClientActiveTexture(GLenum texture)57     void setClientActiveTexture(GLenum texture) { m_clientActiveTexture = texture - GL_TEXTURE0; }
getClientActiveTexture()58     GLenum getClientActiveTexture() { return m_clientActiveTexture + GL_TEXTURE0; }
enableClientState(GLenum cap,bool enable)59     void enableClientState(GLenum cap, bool enable) {
60         switch(cap) {
61             case GL_VERTEX_ARRAY:
62                 m_clientStateEnable[0] = enable;
63                 break;
64             case GL_NORMAL_ARRAY:
65                 m_clientStateEnable[1] = enable;
66                 break;
67             case GL_COLOR_ARRAY:
68                 m_clientStateEnable[2] = enable;
69                 break;
70             case GL_POINT_SIZE_ARRAY_OES:
71                 m_clientStateEnable[3] = enable;
72                 break;
73             case GL_TEXTURE_COORD_ARRAY:
74                 m_clientStateEnable[4 + m_clientActiveTexture] = enable;
75                 break;
76         }
77     }
78 
getClientState(GLenum cap,int texUnit)79     bool getClientState(GLenum cap, int texUnit) {
80         switch(cap) {
81             case GL_VERTEX_ARRAY:
82                 return m_clientStateEnable[0];
83             case GL_NORMAL_ARRAY:
84                 return m_clientStateEnable[1];
85             case GL_COLOR_ARRAY:
86                 return m_clientStateEnable[2];
87             case GL_POINT_SIZE_ARRAY_OES:
88                 return m_clientStateEnable[3];
89                 break;
90             case GL_TEXTURE_COORD_ARRAY:
91                 return m_clientStateEnable[4 + texUnit];
92                 break;
93         }
94         return false;
95     }
96 #endif
97 
98 private:
99     EGLDisplay m_dpy;
100     EGLContext m_ctx;
101     GLDecoderContextData m_contextData;
102     int m_version;
103 
RendererContext(EGLDisplay dpy,EGLContext ctx,int version)104     RendererContext(EGLDisplay dpy, EGLContext ctx, int version) :
105         m_dpy(dpy),
106         m_ctx(ctx),
107         m_version(version)
108     {
109 #ifdef PVR_WAR
110         m_activeTexture = 0;
111         m_clientActiveTexture = 0;
112         memset(m_tex2DBind, 0, 8*sizeof(GLuint));
113         memset(m_tex2DEnable, 0, 8*sizeof(bool));
114         memset(m_clientStateEnable, 0, 16*sizeof(bool));
115 #endif
116     }
117 
118 #ifdef PVR_WAR
119     int m_tex2DBind[8];
120     bool m_tex2DEnable[8];
121     int m_activeTexture;
122     int m_clientActiveTexture;
123     bool m_clientStateEnable[16];
124     PendingCropRectSet m_pendingCropRects;
125 #endif
126 };
127 #endif
128