1 #ifndef __RIMINIEGL_H |
|
2 #define __RIMINIEGL_H |
|
3 |
|
4 /*------------------------------------------------------------------------ |
|
5 * |
|
6 * EGL 1.3 |
|
7 * ------- |
|
8 * |
|
9 * Copyright (c) 2007 The Khronos Group Inc. |
|
10 * |
|
11 * Permission is hereby granted, free of charge, to any person obtaining a |
|
12 * copy of this software and /or associated documentation files |
|
13 * (the "Materials "), to deal in the Materials without restriction, |
|
14 * including without limitation the rights to use, copy, modify, merge, |
|
15 * publish, distribute, sublicense, and/or sell copies of the Materials, |
|
16 * and to permit persons to whom the Materials are furnished to do so, |
|
17 * subject to the following conditions: |
|
18 * |
|
19 * The above copyright notice and this permission notice shall be included |
|
20 * in all copies or substantial portions of the Materials. |
|
21 * |
|
22 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
|
26 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
|
27 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR |
|
28 * THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
29 * |
|
30 *//** |
|
31 * \file |
|
32 * \brief Simple implementation of EGL 1.3 |
|
33 * \note caveats: |
|
34 - always renders into the backbuffer and blits it to window (no single buffered rendering) |
|
35 - no native Windows or Mac OS X pixmap support |
|
36 - no power management events |
|
37 - no support for swap interval |
|
38 * \todo what happens in egl functions when eglTerminate has been called but the context and surface are still in use? |
|
39 * \todo OSDeinitMutex should be called in case getEGL fails. |
|
40 *//*-------------------------------------------------------------------*/ |
|
41 #include "egl.h" |
|
42 #include "riContext.h" |
|
43 |
|
44 #ifdef BUILD_WITH_PRIVATE_EGL |
|
45 #include "eglinternal.h" |
|
46 #endif |
|
47 |
|
48 #ifdef BUILD_WITH_PRIVATE_OPENVG |
|
49 #include "openvginternal.h" |
|
50 #endif |
|
51 |
|
52 //============================================================================================== |
|
53 |
|
54 namespace OpenVGRI |
|
55 { |
|
56 class RIEGLSurface; |
|
57 class RIEGLContext; |
|
58 class RIEGLThread; |
|
59 |
|
60 /*-------------------------------------------------------------------*//*! |
|
61 * \brief |
|
62 * \param |
|
63 * \return |
|
64 * \note |
|
65 *//*-------------------------------------------------------------------*/ |
|
66 |
|
67 class RIEGLConfig |
|
68 { |
|
69 public: |
|
70 RIEGLConfig() : m_desc(Color::formatToDescriptor(VG_sRGBA_8888)), m_configID(0) {} |
|
71 ~RIEGLConfig() {} |
|
72 void set(int r, int g, int b, int a, int l, int bpp, int samples, int maskBits, int ID) |
|
73 { |
|
74 m_desc.redBits = r; |
|
75 m_desc.greenBits = g; |
|
76 m_desc.blueBits = b; |
|
77 m_desc.alphaBits = a; |
|
78 m_desc.luminanceBits = l; |
|
79 m_desc.alphaShift = 0; |
|
80 m_desc.luminanceShift = 0; |
|
81 m_desc.blueShift = b ? a : 0; |
|
82 m_desc.greenShift = g ? a + b : 0; |
|
83 m_desc.redShift = r ? a + b + g : 0; |
|
84 m_desc.format = (VGImageFormat)-1; |
|
85 m_desc.internalFormat = l ? Color::sLA : Color::sRGBA; |
|
86 m_desc.bitsPerPixel = bpp; |
|
87 RI_ASSERT(Color::isValidDescriptor(m_desc)); |
|
88 m_samples = samples; |
|
89 m_maskBits = maskBits; |
|
90 m_configID = ID; |
|
91 m_config = (EGLConfig)ID; |
|
92 } |
|
93 |
|
94 Color::Descriptor configToDescriptor(bool sRGB, bool premultiplied) const |
|
95 { |
|
96 Color::Descriptor desc = m_desc; |
|
97 unsigned int f = m_desc.luminanceBits ? Color::LUMINANCE : 0; |
|
98 f |= sRGB ? Color::NONLINEAR : 0; |
|
99 f |= premultiplied ? Color::PREMULTIPLIED : 0; |
|
100 desc.internalFormat = (Color::InternalFormat)f; |
|
101 return desc; |
|
102 } |
|
103 |
|
104 //EGL RED SIZE bits of Red in the color buffer |
|
105 //EGL GREEN SIZE bits of Green in the color buffer |
|
106 //EGL BLUE SIZE bits of Blue in the color buffer |
|
107 //EGL ALPHA SIZE bits of Alpha in the color buffer |
|
108 //EGL LUMINANCE SIZE bits of Luminance in the color buffer |
|
109 Color::Descriptor m_desc; |
|
110 int m_samples; |
|
111 int m_maskBits; |
|
112 EGLint m_configID; //EGL CONFIG ID unique EGLConfig identifier |
|
113 EGLConfig m_config; |
|
114 //EGL BUFFER SIZE depth of the color buffer (sum of channel bits) |
|
115 //EGL ALPHA MASK SIZE number alpha mask bits (always 8) |
|
116 //EGL BIND TO TEXTURE RGB boolean True if bindable to RGB textures. (always EGL_FALSE) |
|
117 //EGL BIND TO TEXTURE RGBA boolean True if bindable to RGBA textures. (always EGL_FALSE) |
|
118 //EGL COLOR BUFFER TYPE enum color buffer type (EGL_RGB_BUFFER, EGL_LUMINANCE_BUFFER) |
|
119 //EGL CONFIG CAVEAT enum any caveats for the configuration (always EGL_NONE) |
|
120 //EGL DEPTH SIZE integer bits of Z in the depth buffer (always 0) |
|
121 //EGL LEVEL integer frame buffer level (always 0) |
|
122 //EGL MAX PBUFFER WIDTH integer maximum width of pbuffer (always INT_MAX) |
|
123 //EGL MAX PBUFFER HEIGHT integer maximum height of pbuffer (always INT_MAX) |
|
124 //EGL MAX PBUFFER PIXELS integer maximum size of pbuffer (always INT_MAX) |
|
125 //EGL MAX SWAP INTERVAL integer maximum swap interval (always 1) |
|
126 //EGL MIN SWAP INTERVAL integer minimum swap interval (always 1) |
|
127 //EGL NATIVE RENDERABLE boolean EGL TRUE if native rendering APIs can render to surface (always EGL_FALSE) |
|
128 //EGL NATIVE VISUAL ID integer handle of corresponding native visual (always 0) |
|
129 //EGL NATIVE VISUAL TYPE integer native visual type of the associated visual (always EGL_NONE) |
|
130 //EGL RENDERABLE TYPE bitmask which client rendering APIs are supported. (always EGL_OPENVG_BIT) |
|
131 //EGL SAMPLE BUFFERS integer number of multisample buffers (always 0) |
|
132 //EGL SAMPLES integer number of samples per pixel (always 0) |
|
133 //EGL STENCIL SIZE integer bits of Stencil in the stencil buffer (always 0) |
|
134 //EGL SURFACE TYPE bitmask which types of EGL surfaces are supported. (always EGL WINDOW BIT | EGL PIXMAP BIT | EGL PBUFFER BIT) |
|
135 //EGL TRANSPARENT TYPE enum type of transparency supported (always EGL_NONE) |
|
136 //EGL TRANSPARENT RED VALUE integer transparent red value (undefined) |
|
137 //EGL TRANSPARENT GREEN VALUE integer transparent green value (undefined) |
|
138 //EGL TRANSPARENT BLUE VALUE integer transparent blue value (undefined) |
|
139 }; |
|
140 |
|
141 |
|
142 /*-------------------------------------------------------------------*//*! |
|
143 * \brief |
|
144 * \param |
|
145 * \return |
|
146 * \note |
|
147 *//*-------------------------------------------------------------------*/ |
|
148 |
|
149 #define EGL_NUMCONFIGS 60 |
|
150 |
|
151 class RIEGLDisplay |
|
152 { |
|
153 public: |
|
154 RIEGLDisplay(EGLDisplay id); |
|
155 ~RIEGLDisplay(); |
|
156 |
|
157 int getNumConfigs() const { return EGL_NUMCONFIGS; } |
|
158 const RIEGLConfig& getConfigByIdx(int i) const { RI_ASSERT(i >= 0 && i < EGL_NUMCONFIGS); return m_configs[i]; } |
|
159 const RIEGLConfig& getConfig(const EGLConfig config) const { for(int i=0;i<EGL_NUMCONFIGS;i++) { if(m_configs[i].m_config == config) return m_configs[i]; } RI_ASSERT(0); return m_configs[0]; } |
|
160 |
|
161 EGLDisplay getID() const { return m_id; } |
|
162 |
|
163 void addContext(RIEGLContext* ctx) { RI_ASSERT(ctx); m_contexts.push_back(ctx); } //throws bad_alloc |
|
164 void removeContext(RIEGLContext* ctx) { RI_ASSERT(ctx); bool res = m_contexts.remove(ctx); RI_ASSERT(res); RI_UNREF(res); } |
|
165 |
|
166 void addSurface(RIEGLSurface* srf) { RI_ASSERT(srf); m_surfaces.push_back(srf); } //throws bad_alloc |
|
167 void removeSurface(RIEGLSurface* srf) { RI_ASSERT(srf); bool res = m_surfaces.remove(srf); RI_ASSERT(res); RI_UNREF(res); } |
|
168 |
|
169 EGLBoolean contextExists(const EGLContext ctx) const; |
|
170 EGLBoolean surfaceExists(const EGLSurface srf) const; |
|
171 EGLBoolean configExists(const EGLConfig cfg) const; |
|
172 |
|
173 private: |
|
174 RIEGLDisplay(const RIEGLDisplay& t); |
|
175 RIEGLDisplay& operator=(const RIEGLDisplay&t); |
|
176 |
|
177 EGLDisplay m_id; |
|
178 |
|
179 Array<RIEGLContext*> m_contexts; |
|
180 Array<RIEGLSurface*> m_surfaces; |
|
181 |
|
182 RIEGLConfig m_configs[EGL_NUMCONFIGS]; |
|
183 }; |
|
184 |
|
185 /*-------------------------------------------------------------------*//*! |
|
186 * \brief |
|
187 * \param |
|
188 * \return |
|
189 * \note |
|
190 *//*-------------------------------------------------------------------*/ |
|
191 |
|
192 class EGL |
|
193 { |
|
194 public: |
|
195 EGL(); |
|
196 ~EGL(); |
|
197 |
|
198 void addReference() { m_referenceCount++; } |
|
199 int removeReference() { m_referenceCount--; RI_ASSERT(m_referenceCount >= 0); return m_referenceCount; } |
|
200 |
|
201 void addDisplay(RIEGLDisplay* display) { RI_ASSERT(display); m_displays.push_back(display); } //throws bad alloc |
|
202 void removeDisplay(RIEGLDisplay* display) { RI_ASSERT(display); bool res = m_displays.remove(display); RI_ASSERT(res); RI_UNREF(res); } |
|
203 RIEGLDisplay* getDisplay(const EGLDisplay displayID) const; |
|
204 EGLDisplay findDisplay(const EGLContext ctx) const; |
|
205 |
|
206 void addCurrentThread(RIEGLThread* thread) { RI_ASSERT(thread); m_currentThreads.push_back(thread); } //throws bad alloc |
|
207 void removeCurrentThread(RIEGLThread* thread) { RI_ASSERT(thread); bool res = m_currentThreads.remove(thread); RI_ASSERT(res); RI_UNREF(res); } |
|
208 RIEGLThread* getCurrentThread() const; |
|
209 |
|
210 RIEGLThread* getThread(); |
|
211 void destroyThread(); |
|
212 |
|
213 bool isInUse(const void* image) const; |
|
214 |
|
215 private: |
|
216 EGL(const EGL&); // Not allowed. |
|
217 const EGL& operator=(const EGL&); // Not allowed. |
|
218 |
|
219 Array<RIEGLThread*> m_threads; //threads that have called EGL |
|
220 Array<RIEGLThread*> m_currentThreads; //threads that have a bound context |
|
221 Array<RIEGLDisplay*> m_displays; |
|
222 |
|
223 int m_referenceCount; |
|
224 }; |
|
225 |
|
226 void* eglvgGetCurrentVGContext(void); |
|
227 bool eglvgIsInUse(void* image); |
|
228 |
|
229 } //end of namespace |
|
230 |
|
231 #endif /* __RIMINIEGL_H */ |
|
232 |
|
233 |
|