• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef Extensions3D_h
27 #define Extensions3D_h
28 
29 #include "platform/PlatformExport.h"
30 #include "platform/graphics/GraphicsTypes3D.h"
31 
32 #include "wtf/text/WTFString.h"
33 
34 namespace WebCore {
35 
36 class GraphicsContext3D;
37 class ImageBuffer;
38 
39 // The supported extensions are defined below.
40 //
41 // Calling any extension function not supported by the current context
42 // must be a no-op; in particular, it may not have side effects. In
43 // this situation, if the function has a return value, 0 is returned.
44 class PLATFORM_EXPORT Extensions3D {
45 public:
46     ~Extensions3D();
47 
48     // Supported extensions:
49     //   GL_EXT_texture_format_BGRA8888
50     //   GL_EXT_read_format_bgra
51     //   GL_ARB_robustness
52     //   GL_ARB_texture_non_power_of_two / GL_OES_texture_npot
53     //   GL_EXT_packed_depth_stencil / GL_OES_packed_depth_stencil
54     //   GL_ANGLE_framebuffer_blit / GL_ANGLE_framebuffer_multisample
55     //   GL_OES_texture_float
56     //   GL_OES_texture_float_linear
57     //   GL_OES_texture_half_float
58     //   GL_OES_texture_half_float_linear
59     //   GL_OES_standard_derivatives
60     //   GL_OES_rgb8_rgba8
61     //   GL_OES_vertex_array_object
62     //   GL_OES_element_index_uint
63     //   GL_ANGLE_translated_shader_source
64     //   GL_ARB_texture_rectangle (only the subset required to
65     //     implement IOSurface binding; it's recommended to support
66     //     this only on Mac OS X to limit the amount of code dependent
67     //     on this extension)
68     //   GL_EXT_texture_compression_dxt1
69     //   GL_EXT_texture_compression_s3tc
70     //   GL_OES_compressed_ETC1_RGB8_texture
71     //   GL_IMG_texture_compression_pvrtc
72     //   EXT_texture_filter_anisotropic
73     //   GL_EXT_debug_marker
74     //   GL_CHROMIUM_copy_texture
75     //   GL_CHROMIUM_flipy
76     //   GL_ARB_draw_buffers / GL_EXT_draw_buffers
77     //   GL_ANGLE_instanced_arrays
78 
79     //   GL_CHROMIUM_shallow_flush  : only supported if an ipc command buffer is used.
80     //   GL_CHROMIUM_resource_safe  : indicating that textures/renderbuffers are always initialized before read/write.
81     //   GL_CHROMIUM_strict_attribs : indicating a GL error is generated for out-of-bounds buffer accesses.
82     //   GL_CHROMIUM_post_sub_buffer
83     //   GL_CHROMIUM_map_sub
84     //   GL_CHROMIUM_swapbuffers_complete_callback
85     //   GL_CHROMIUM_rate_limit_offscreen_context
86     //   GL_CHROMIUM_paint_framebuffer_canvas
87     //   GL_CHROMIUM_iosurface (Mac OS X specific)
88     //   GL_CHROMIUM_command_buffer_query
89     //   GL_ANGLE_texture_usage
90     //   GL_EXT_debug_marker
91     //   GL_EXT_texture_storage
92     //   GL_EXT_occlusion_query_boolean
93 
94     // Takes full name of extension; for example,
95     // "GL_EXT_texture_format_BGRA8888".
96     bool supports(const String&);
97 
98     // Certain OpenGL and WebGL implementations may support enabling
99     // extensions lazily. This method may only be called with
100     // extension names for which supports returns true.
101     void ensureEnabled(const String&);
102 
103     // Takes full name of extension: for example, "GL_EXT_texture_format_BGRA8888".
104     // Checks to see whether the given extension is actually enabled (see ensureEnabled).
105     // Has no other side-effects.
106     bool isEnabled(const String&);
107 
108     enum ExtensionsEnumType {
109         // GL_EXT_texture_format_BGRA8888 enums
110         BGRA_EXT = 0x80E1,
111 
112         // GL_ARB_robustness/GL_CHROMIUM_lose_context enums
113         GUILTY_CONTEXT_RESET_ARB = 0x8253,
114         INNOCENT_CONTEXT_RESET_ARB = 0x8254,
115         UNKNOWN_CONTEXT_RESET_ARB = 0x8255,
116 
117         // GL_EXT/OES_packed_depth_stencil enums
118         DEPTH24_STENCIL8 = 0x88F0,
119 
120         // GL_ANGLE_framebuffer_blit names
121         READ_FRAMEBUFFER = 0x8CA8,
122         DRAW_FRAMEBUFFER = 0x8CA9,
123         DRAW_FRAMEBUFFER_BINDING = 0x8CA6,
124         READ_FRAMEBUFFER_BINDING = 0x8CAA,
125 
126         // GL_ANGLE_framebuffer_multisample names
127         RENDERBUFFER_SAMPLES = 0x8CAB,
128         FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56,
129         MAX_SAMPLES = 0x8D57,
130 
131         // GL_OES_standard_derivatives names
132         FRAGMENT_SHADER_DERIVATIVE_HINT_OES = 0x8B8B,
133 
134         // GL_OES_rgb8_rgba8 names
135         RGB8_OES = 0x8051,
136         RGBA8_OES = 0x8058,
137 
138         // GL_OES_vertex_array_object names
139         VERTEX_ARRAY_BINDING_OES = 0x85B5,
140 
141         // GL_ANGLE_translated_shader_source
142         TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE = 0x93A0,
143 
144         // GL_ARB_texture_rectangle
145         TEXTURE_RECTANGLE_ARB =  0x84F5,
146         TEXTURE_BINDING_RECTANGLE_ARB = 0x84F6,
147 
148         // GL_EXT_texture_compression_dxt1
149         // GL_EXT_texture_compression_s3tc
150         COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
151         COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
152         COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
153         COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
154 
155         // GL_OES_compressed_ETC1_RGB8_texture
156         ETC1_RGB8_OES = 0x8D64,
157 
158         // GL_IMG_texture_compression_pvrtc
159         COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
160         COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
161         COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
162         COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,
163 
164         // GL_AMD_compressed_ATC_texture
165         COMPRESSED_ATC_RGB_AMD = 0x8C92,
166         COMPRESSED_ATC_RGBA_EXPLICIT_ALPHA_AMD = 0x8C93,
167         COMPRESSED_ATC_RGBA_INTERPOLATED_ALPHA_AMD = 0x87EE,
168 
169         // GL_EXT_texture_filter_anisotropic
170         TEXTURE_MAX_ANISOTROPY_EXT = 0x84FE,
171         MAX_TEXTURE_MAX_ANISOTROPY_EXT = 0x84FF,
172 
173         // GL_CHROMIUM_flipy
174         UNPACK_FLIP_Y_CHROMIUM = 0x9240,
175 
176         // GL_CHROMIUM_copy_texture
177         UNPACK_PREMULTIPLY_ALPHA_CHROMIUM = 0x9241,
178         UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM = 0x9242,
179 
180         // GL_ARB_draw_buffers / GL_EXT_draw_buffers
181         MAX_DRAW_BUFFERS_EXT = 0x8824,
182         DRAW_BUFFER0_EXT = 0x8825,
183         DRAW_BUFFER1_EXT = 0x8826,
184         DRAW_BUFFER2_EXT = 0x8827,
185         DRAW_BUFFER3_EXT = 0x8828,
186         DRAW_BUFFER4_EXT = 0x8829,
187         DRAW_BUFFER5_EXT = 0x882A,
188         DRAW_BUFFER6_EXT = 0x882B,
189         DRAW_BUFFER7_EXT = 0x882C,
190         DRAW_BUFFER8_EXT = 0x882D,
191         DRAW_BUFFER9_EXT = 0x882E,
192         DRAW_BUFFER10_EXT = 0x882F,
193         DRAW_BUFFER11_EXT = 0x8830,
194         DRAW_BUFFER12_EXT = 0x8831,
195         DRAW_BUFFER13_EXT = 0x8832,
196         DRAW_BUFFER14_EXT = 0x8833,
197         DRAW_BUFFER15_EXT = 0x8834,
198         MAX_COLOR_ATTACHMENTS_EXT = 0x8CDF,
199         COLOR_ATTACHMENT0_EXT = 0x8CE0,
200         COLOR_ATTACHMENT1_EXT = 0x8CE1,
201         COLOR_ATTACHMENT2_EXT = 0x8CE2,
202         COLOR_ATTACHMENT3_EXT = 0x8CE3,
203         COLOR_ATTACHMENT4_EXT = 0x8CE4,
204         COLOR_ATTACHMENT5_EXT = 0x8CE5,
205         COLOR_ATTACHMENT6_EXT = 0x8CE6,
206         COLOR_ATTACHMENT7_EXT = 0x8CE7,
207         COLOR_ATTACHMENT8_EXT = 0x8CE8,
208         COLOR_ATTACHMENT9_EXT = 0x8CE9,
209         COLOR_ATTACHMENT10_EXT = 0x8CEA,
210         COLOR_ATTACHMENT11_EXT = 0x8CEB,
211         COLOR_ATTACHMENT12_EXT = 0x8CEC,
212         COLOR_ATTACHMENT13_EXT = 0x8CED,
213         COLOR_ATTACHMENT14_EXT = 0x8CEE,
214         COLOR_ATTACHMENT15_EXT = 0x8CEF,
215 
216         // GL_CHROMIUM_map_sub (enums inherited from GL_ARB_vertex_buffer_object)
217         READ_ONLY = 0x88B8,
218         WRITE_ONLY = 0x88B9,
219 
220         // GL_EXT_texture_storage
221         BGRA8_EXT = 0x93A1,
222 
223         // GL_EXT_occlusion_query_boolean
224         ANY_SAMPLES_PASSED_EXT = 0x8C2F,
225         ANY_SAMPLES_PASSED_CONSERVATIVE_EXT = 0x8D6A,
226         CURRENT_QUERY_EXT = 0x8865,
227         QUERY_RESULT_EXT = 0x8866,
228         QUERY_RESULT_AVAILABLE_EXT = 0x8867,
229 
230         // GL_CHROMIUM_command_buffer_query
231         COMMANDS_ISSUED_CHROMIUM = 0x84F2,
232 
233         // GL_ANGLE_instanced_arrays
234         VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88FE
235     };
236 
237     // GL_ARB_robustness
238     // Note: This method's behavior differs from the GL_ARB_robustness
239     // specification in the following way:
240     // The implementation must not reset the error state during this call.
241     // If getGraphicsResetStatusARB returns an error, it should continue
242     // returning the same error. Restoring the GraphicsContext3D is handled
243     // externally.
244     int getGraphicsResetStatusARB();
245 
246     // GL_ANGLE_framebuffer_blit
247     void blitFramebuffer(long srcX0, long srcY0, long srcX1, long srcY1, long dstX0, long dstY0, long dstX1, long dstY1, unsigned long mask, unsigned long filter);
248 
249     // GL_ANGLE_framebuffer_multisample
250     void renderbufferStorageMultisample(unsigned long target, unsigned long samples, unsigned long internalformat, unsigned long width, unsigned long height);
251 
252     // GL_OES_vertex_array_object
253     Platform3DObject createVertexArrayOES();
254     void deleteVertexArrayOES(Platform3DObject);
255     GC3Dboolean isVertexArrayOES(Platform3DObject);
256     void bindVertexArrayOES(Platform3DObject);
257 
258     // GL_ANGLE_translated_shader_source
259     String getTranslatedShaderSourceANGLE(Platform3DObject);
260 
261     // GL_CHROMIUM_copy_texture
262     // canUseCopyTextureCHROMIUM(...) is used to check if copyTextureCHROMIUM(...) can work for the specified
263     // format, type and level for the destination texture.
264     bool canUseCopyTextureCHROMIUM(GC3Denum destFormat, GC3Denum destType, GC3Dint level);
265     void copyTextureCHROMIUM(GC3Denum, Platform3DObject, Platform3DObject, GC3Dint, GC3Denum, GC3Denum);
266 
267     // GL_EXT_debug_marker
268     void insertEventMarkerEXT(const String&);
269     void pushGroupMarkerEXT(const String&);
270     void popGroupMarkerEXT(void);
271 
272     // GL_ARB_draw_buffers / GL_EXT_draw_buffers
273     void drawBuffersEXT(GC3Dsizei n, const GC3Denum* bufs);
274 
275     // GL_CHROMIUM_map_sub
276     void* mapBufferSubDataCHROMIUM(unsigned target, int offset, int size, unsigned access);
277     void unmapBufferSubDataCHROMIUM(const void*);
278     void* mapTexSubImage2DCHROMIUM(unsigned target, int level, int xoffset, int yoffset, int width, int height, unsigned format, unsigned type, unsigned access);
279     void unmapTexSubImage2DCHROMIUM(const void*);
280 
281     // GL_CHROMIUM_rate_limit_offscreen_context
282     void rateLimitOffscreenContextCHROMIUM();
283 
284     // GL_CHROMIUM_paint_framebuffer_canvas
285     void paintFramebufferToCanvas(int framebuffer, int width, int height, bool premultiplyAlpha, ImageBuffer*);
286 
287     // GL_CHROMIUM_iosurface
288     // To avoid needing to expose extraneous enums, assumes internal format
289     // RGBA, format BGRA, and type UNSIGNED_INT_8_8_8_8_REV.
290     void texImageIOSurface2DCHROMIUM(unsigned target, int width, int height, uint32_t ioSurfaceId, unsigned plane);
291 
292     // GL_EXT_texture_storage
293     void texStorage2DEXT(unsigned target, int levels, unsigned internalformat, int width, int height);
294 
295     // GL_EXT_occlusion_query
296     Platform3DObject createQueryEXT();
297     void deleteQueryEXT(Platform3DObject);
298     GC3Dboolean isQueryEXT(Platform3DObject);
299     void beginQueryEXT(GC3Denum, Platform3DObject);
300     void endQueryEXT(GC3Denum);
301     void getQueryivEXT(GC3Denum, GC3Denum, GC3Dint*);
302     void getQueryObjectuivEXT(Platform3DObject, GC3Denum, GC3Duint*);
303 
304     // GL_CHROMIUM_shallow_flush
305     void shallowFlushCHROMIUM();
306 
307     // GL_ANGLE_instanced_arrays
308     void drawArraysInstancedANGLE(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount);
309     void drawElementsInstancedANGLE(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount);
310     void vertexAttribDivisorANGLE(GC3Duint index, GC3Duint divisor);
311 
312     // GL_CHROMIUM_lose_context
313     void loseContextCHROMIUM(GC3Denum, GC3Denum);
314 
315 private:
316     // Instances of this class are strictly owned by the GraphicsContext3D implementation and do not
317     // need to be instantiated by any other code.
318     friend class GraphicsContext3D;
319     explicit Extensions3D(GraphicsContext3D*);
320 
321     // Weak pointer back to GraphicsContext3D.
322     GraphicsContext3D* m_context;
323 };
324 
325 } // namespace WebCore
326 
327 #endif // Extensions3D_h
328