1 | /* |
2 | * Copyright (C) 2009, 2014 Apple 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 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "ANGLEWebKitBridge.h" |
29 | #include "GraphicsContext3DAttributes.h" |
30 | #include "GraphicsTypes3D.h" |
31 | #include "Image.h" |
32 | #include "IntRect.h" |
33 | #include "PlatformLayer.h" |
34 | #include <memory> |
35 | #include <wtf/HashCountedSet.h> |
36 | #include <wtf/HashMap.h> |
37 | #include <wtf/ListHashSet.h> |
38 | #include <wtf/RefCounted.h> |
39 | #include <wtf/RetainPtr.h> |
40 | #include <wtf/UniqueArray.h> |
41 | #include <wtf/text/WTFString.h> |
42 | |
43 | #if USE(CA) |
44 | #include "PlatformCALayer.h" |
45 | #endif |
46 | |
47 | // FIXME: Find a better way to avoid the name confliction for NO_ERROR. |
48 | #if PLATFORM(WIN) |
49 | #undef NO_ERROR |
50 | #elif PLATFORM(GTK) |
51 | // This define is from the X11 headers, but it's used below, so we must undefine it. |
52 | #undef VERSION |
53 | #endif |
54 | |
55 | #if PLATFORM(COCOA) |
56 | |
57 | #if USE(OPENGL_ES) |
58 | #include <OpenGLES/ES2/gl.h> |
59 | #ifdef __OBJC__ |
60 | #import <OpenGLES/EAGL.h> |
61 | typedef EAGLContext* PlatformGraphicsContext3D; |
62 | #else |
63 | typedef void* PlatformGraphicsContext3D; |
64 | #endif // __OBJC__ |
65 | #endif // USE(OPENGL_ES) |
66 | |
67 | #if !USE(OPENGL_ES) |
68 | typedef struct _CGLContextObject *CGLContextObj; |
69 | typedef CGLContextObj PlatformGraphicsContext3D; |
70 | #endif |
71 | |
72 | OBJC_CLASS CALayer; |
73 | OBJC_CLASS WebGLLayer; |
74 | typedef struct __IOSurface* IOSurfaceRef; |
75 | #endif // PLATFORM(COCOA) |
76 | |
77 | #if USE(NICOSIA) |
78 | namespace Nicosia { |
79 | class GC3DLayer; |
80 | } |
81 | #endif |
82 | |
83 | #if !PLATFORM(COCOA) |
84 | typedef unsigned GLuint; |
85 | typedef void* PlatformGraphicsContext3D; |
86 | typedef void* PlatformGraphicsSurface3D; |
87 | #endif // !PLATFORM(COCOA) |
88 | |
89 | // These are currently the same among all implementations. |
90 | const PlatformGraphicsContext3D NullPlatformGraphicsContext3D = 0; |
91 | const Platform3DObject NullPlatform3DObject = 0; |
92 | |
93 | namespace WebCore { |
94 | class Extensions3D; |
95 | #if !PLATFORM(COCOA) && USE(OPENGL_ES) |
96 | class Extensions3DOpenGLES; |
97 | #else |
98 | class Extensions3DOpenGL; |
99 | #endif |
100 | class HostWindow; |
101 | class Image; |
102 | class ImageBuffer; |
103 | class ImageData; |
104 | class IntRect; |
105 | class IntSize; |
106 | class WebGLRenderingContextBase; |
107 | #if USE(TEXTURE_MAPPER) |
108 | class TextureMapperGC3DPlatformLayer; |
109 | #endif |
110 | |
111 | typedef WTF::HashMap<CString, uint64_t> ShaderNameHash; |
112 | |
113 | struct ActiveInfo { |
114 | String name; |
115 | GC3Denum type; |
116 | GC3Dint size; |
117 | }; |
118 | |
119 | class GraphicsContext3DPrivate; |
120 | |
121 | class GraphicsContext3D : public RefCounted<GraphicsContext3D> { |
122 | public: |
123 | class Client { |
124 | public: |
125 | virtual ~Client() { } |
126 | virtual void didComposite() = 0; |
127 | virtual void forceContextLost() = 0; |
128 | virtual void recycleContext() = 0; |
129 | virtual void dispatchContextChangedNotification() = 0; |
130 | }; |
131 | |
132 | enum { |
133 | // WebGL 1 constants |
134 | DEPTH_BUFFER_BIT = 0x00000100, |
135 | STENCIL_BUFFER_BIT = 0x00000400, |
136 | COLOR_BUFFER_BIT = 0x00004000, |
137 | POINTS = 0x0000, |
138 | LINES = 0x0001, |
139 | LINE_LOOP = 0x0002, |
140 | LINE_STRIP = 0x0003, |
141 | TRIANGLES = 0x0004, |
142 | TRIANGLE_STRIP = 0x0005, |
143 | TRIANGLE_FAN = 0x0006, |
144 | ZERO = 0, |
145 | ONE = 1, |
146 | SRC_COLOR = 0x0300, |
147 | ONE_MINUS_SRC_COLOR = 0x0301, |
148 | SRC_ALPHA = 0x0302, |
149 | ONE_MINUS_SRC_ALPHA = 0x0303, |
150 | DST_ALPHA = 0x0304, |
151 | ONE_MINUS_DST_ALPHA = 0x0305, |
152 | DST_COLOR = 0x0306, |
153 | ONE_MINUS_DST_COLOR = 0x0307, |
154 | SRC_ALPHA_SATURATE = 0x0308, |
155 | FUNC_ADD = 0x8006, |
156 | BLEND_EQUATION = 0x8009, |
157 | BLEND_EQUATION_RGB = 0x8009, |
158 | BLEND_EQUATION_ALPHA = 0x883D, |
159 | FUNC_SUBTRACT = 0x800A, |
160 | FUNC_REVERSE_SUBTRACT = 0x800B, |
161 | BLEND_DST_RGB = 0x80C8, |
162 | BLEND_SRC_RGB = 0x80C9, |
163 | BLEND_DST_ALPHA = 0x80CA, |
164 | BLEND_SRC_ALPHA = 0x80CB, |
165 | CONSTANT_COLOR = 0x8001, |
166 | ONE_MINUS_CONSTANT_COLOR = 0x8002, |
167 | CONSTANT_ALPHA = 0x8003, |
168 | ONE_MINUS_CONSTANT_ALPHA = 0x8004, |
169 | BLEND_COLOR = 0x8005, |
170 | ARRAY_BUFFER = 0x8892, |
171 | ELEMENT_ARRAY_BUFFER = 0x8893, |
172 | ARRAY_BUFFER_BINDING = 0x8894, |
173 | ELEMENT_ARRAY_BUFFER_BINDING = 0x8895, |
174 | STREAM_DRAW = 0x88E0, |
175 | STATIC_DRAW = 0x88E4, |
176 | DYNAMIC_DRAW = 0x88E8, |
177 | BUFFER_SIZE = 0x8764, |
178 | BUFFER_USAGE = 0x8765, |
179 | CURRENT_VERTEX_ATTRIB = 0x8626, |
180 | FRONT = 0x0404, |
181 | BACK = 0x0405, |
182 | FRONT_AND_BACK = 0x0408, |
183 | TEXTURE_2D = 0x0DE1, |
184 | CULL_FACE = 0x0B44, |
185 | BLEND = 0x0BE2, |
186 | DITHER = 0x0BD0, |
187 | STENCIL_TEST = 0x0B90, |
188 | DEPTH_TEST = 0x0B71, |
189 | SCISSOR_TEST = 0x0C11, |
190 | POLYGON_OFFSET_FILL = 0x8037, |
191 | SAMPLE_ALPHA_TO_COVERAGE = 0x809E, |
192 | SAMPLE_COVERAGE = 0x80A0, |
193 | NO_ERROR = 0, |
194 | INVALID_ENUM = 0x0500, |
195 | INVALID_VALUE = 0x0501, |
196 | INVALID_OPERATION = 0x0502, |
197 | OUT_OF_MEMORY = 0x0505, |
198 | CW = 0x0900, |
199 | CCW = 0x0901, |
200 | LINE_WIDTH = 0x0B21, |
201 | ALIASED_POINT_SIZE_RANGE = 0x846D, |
202 | ALIASED_LINE_WIDTH_RANGE = 0x846E, |
203 | CULL_FACE_MODE = 0x0B45, |
204 | FRONT_FACE = 0x0B46, |
205 | DEPTH_RANGE = 0x0B70, |
206 | DEPTH_WRITEMASK = 0x0B72, |
207 | DEPTH_CLEAR_VALUE = 0x0B73, |
208 | DEPTH_FUNC = 0x0B74, |
209 | STENCIL_CLEAR_VALUE = 0x0B91, |
210 | STENCIL_FUNC = 0x0B92, |
211 | STENCIL_FAIL = 0x0B94, |
212 | STENCIL_PASS_DEPTH_FAIL = 0x0B95, |
213 | STENCIL_PASS_DEPTH_PASS = 0x0B96, |
214 | STENCIL_REF = 0x0B97, |
215 | STENCIL_VALUE_MASK = 0x0B93, |
216 | STENCIL_WRITEMASK = 0x0B98, |
217 | STENCIL_BACK_FUNC = 0x8800, |
218 | STENCIL_BACK_FAIL = 0x8801, |
219 | STENCIL_BACK_PASS_DEPTH_FAIL = 0x8802, |
220 | STENCIL_BACK_PASS_DEPTH_PASS = 0x8803, |
221 | STENCIL_BACK_REF = 0x8CA3, |
222 | STENCIL_BACK_VALUE_MASK = 0x8CA4, |
223 | STENCIL_BACK_WRITEMASK = 0x8CA5, |
224 | VIEWPORT = 0x0BA2, |
225 | SCISSOR_BOX = 0x0C10, |
226 | COLOR_CLEAR_VALUE = 0x0C22, |
227 | COLOR_WRITEMASK = 0x0C23, |
228 | UNPACK_ALIGNMENT = 0x0CF5, |
229 | PACK_ALIGNMENT = 0x0D05, |
230 | MAX_TEXTURE_SIZE = 0x0D33, |
231 | MAX_VIEWPORT_DIMS = 0x0D3A, |
232 | SUBPIXEL_BITS = 0x0D50, |
233 | RED_BITS = 0x0D52, |
234 | GREEN_BITS = 0x0D53, |
235 | BLUE_BITS = 0x0D54, |
236 | ALPHA_BITS = 0x0D55, |
237 | DEPTH_BITS = 0x0D56, |
238 | STENCIL_BITS = 0x0D57, |
239 | POLYGON_OFFSET_UNITS = 0x2A00, |
240 | POLYGON_OFFSET_FACTOR = 0x8038, |
241 | TEXTURE_BINDING_2D = 0x8069, |
242 | SAMPLE_BUFFERS = 0x80A8, |
243 | SAMPLES = 0x80A9, |
244 | SAMPLE_COVERAGE_VALUE = 0x80AA, |
245 | SAMPLE_COVERAGE_INVERT = 0x80AB, |
246 | NUM_COMPRESSED_TEXTURE_FORMATS = 0x86A2, |
247 | COMPRESSED_TEXTURE_FORMATS = 0x86A3, |
248 | DONT_CARE = 0x1100, |
249 | FASTEST = 0x1101, |
250 | NICEST = 0x1102, |
251 | GENERATE_MIPMAP_HINT = 0x8192, |
252 | BYTE = 0x1400, |
253 | UNSIGNED_BYTE = 0x1401, |
254 | SHORT = 0x1402, |
255 | UNSIGNED_SHORT = 0x1403, |
256 | INT = 0x1404, |
257 | UNSIGNED_INT = 0x1405, |
258 | FLOAT = 0x1406, |
259 | HALF_FLOAT_OES = 0x8D61, |
260 | FIXED = 0x140C, |
261 | DEPTH_COMPONENT = 0x1902, |
262 | ALPHA = 0x1906, |
263 | RGB = 0x1907, |
264 | RGBA = 0x1908, |
265 | BGRA = 0x80E1, |
266 | LUMINANCE = 0x1909, |
267 | LUMINANCE_ALPHA = 0x190A, |
268 | UNSIGNED_SHORT_4_4_4_4 = 0x8033, |
269 | UNSIGNED_SHORT_5_5_5_1 = 0x8034, |
270 | UNSIGNED_SHORT_5_6_5 = 0x8363, |
271 | FRAGMENT_SHADER = 0x8B30, |
272 | VERTEX_SHADER = 0x8B31, |
273 | MAX_VERTEX_ATTRIBS = 0x8869, |
274 | MAX_VERTEX_UNIFORM_VECTORS = 0x8DFB, |
275 | MAX_VARYING_VECTORS = 0x8DFC, |
276 | MAX_COMBINED_TEXTURE_IMAGE_UNITS = 0x8B4D, |
277 | MAX_VERTEX_TEXTURE_IMAGE_UNITS = 0x8B4C, |
278 | MAX_TEXTURE_IMAGE_UNITS = 0x8872, |
279 | MAX_FRAGMENT_UNIFORM_VECTORS = 0x8DFD, |
280 | SHADER_TYPE = 0x8B4F, |
281 | DELETE_STATUS = 0x8B80, |
282 | LINK_STATUS = 0x8B82, |
283 | VALIDATE_STATUS = 0x8B83, |
284 | ATTACHED_SHADERS = 0x8B85, |
285 | ACTIVE_UNIFORMS = 0x8B86, |
286 | ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87, |
287 | ACTIVE_ATTRIBUTES = 0x8B89, |
288 | ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A, |
289 | SHADING_LANGUAGE_VERSION = 0x8B8C, |
290 | CURRENT_PROGRAM = 0x8B8D, |
291 | NEVER = 0x0200, |
292 | LESS = 0x0201, |
293 | EQUAL = 0x0202, |
294 | LEQUAL = 0x0203, |
295 | GREATER = 0x0204, |
296 | NOTEQUAL = 0x0205, |
297 | GEQUAL = 0x0206, |
298 | ALWAYS = 0x0207, |
299 | KEEP = 0x1E00, |
300 | REPLACE = 0x1E01, |
301 | INCR = 0x1E02, |
302 | DECR = 0x1E03, |
303 | INVERT = 0x150A, |
304 | INCR_WRAP = 0x8507, |
305 | DECR_WRAP = 0x8508, |
306 | VENDOR = 0x1F00, |
307 | RENDERER = 0x1F01, |
308 | VERSION = 0x1F02, |
309 | EXTENSIONS = 0x1F03, |
310 | NEAREST = 0x2600, |
311 | LINEAR = 0x2601, |
312 | NEAREST_MIPMAP_NEAREST = 0x2700, |
313 | LINEAR_MIPMAP_NEAREST = 0x2701, |
314 | NEAREST_MIPMAP_LINEAR = 0x2702, |
315 | LINEAR_MIPMAP_LINEAR = 0x2703, |
316 | TEXTURE_MAG_FILTER = 0x2800, |
317 | TEXTURE_MIN_FILTER = 0x2801, |
318 | TEXTURE_WRAP_S = 0x2802, |
319 | TEXTURE_WRAP_T = 0x2803, |
320 | TEXTURE = 0x1702, |
321 | TEXTURE_CUBE_MAP = 0x8513, |
322 | TEXTURE_BINDING_CUBE_MAP = 0x8514, |
323 | TEXTURE_CUBE_MAP_POSITIVE_X = 0x8515, |
324 | TEXTURE_CUBE_MAP_NEGATIVE_X = 0x8516, |
325 | TEXTURE_CUBE_MAP_POSITIVE_Y = 0x8517, |
326 | TEXTURE_CUBE_MAP_NEGATIVE_Y = 0x8518, |
327 | TEXTURE_CUBE_MAP_POSITIVE_Z = 0x8519, |
328 | TEXTURE_CUBE_MAP_NEGATIVE_Z = 0x851A, |
329 | MAX_CUBE_MAP_TEXTURE_SIZE = 0x851C, |
330 | TEXTURE0 = 0x84C0, |
331 | TEXTURE1 = 0x84C1, |
332 | TEXTURE2 = 0x84C2, |
333 | TEXTURE3 = 0x84C3, |
334 | TEXTURE4 = 0x84C4, |
335 | TEXTURE5 = 0x84C5, |
336 | TEXTURE6 = 0x84C6, |
337 | TEXTURE7 = 0x84C7, |
338 | TEXTURE8 = 0x84C8, |
339 | TEXTURE9 = 0x84C9, |
340 | TEXTURE10 = 0x84CA, |
341 | TEXTURE11 = 0x84CB, |
342 | TEXTURE12 = 0x84CC, |
343 | TEXTURE13 = 0x84CD, |
344 | TEXTURE14 = 0x84CE, |
345 | TEXTURE15 = 0x84CF, |
346 | TEXTURE16 = 0x84D0, |
347 | TEXTURE17 = 0x84D1, |
348 | TEXTURE18 = 0x84D2, |
349 | TEXTURE19 = 0x84D3, |
350 | TEXTURE20 = 0x84D4, |
351 | TEXTURE21 = 0x84D5, |
352 | TEXTURE22 = 0x84D6, |
353 | TEXTURE23 = 0x84D7, |
354 | TEXTURE24 = 0x84D8, |
355 | TEXTURE25 = 0x84D9, |
356 | TEXTURE26 = 0x84DA, |
357 | TEXTURE27 = 0x84DB, |
358 | TEXTURE28 = 0x84DC, |
359 | TEXTURE29 = 0x84DD, |
360 | TEXTURE30 = 0x84DE, |
361 | TEXTURE31 = 0x84DF, |
362 | ACTIVE_TEXTURE = 0x84E0, |
363 | REPEAT = 0x2901, |
364 | CLAMP_TO_EDGE = 0x812F, |
365 | MIRRORED_REPEAT = 0x8370, |
366 | FLOAT_VEC2 = 0x8B50, |
367 | FLOAT_VEC3 = 0x8B51, |
368 | FLOAT_VEC4 = 0x8B52, |
369 | INT_VEC2 = 0x8B53, |
370 | INT_VEC3 = 0x8B54, |
371 | INT_VEC4 = 0x8B55, |
372 | BOOL = 0x8B56, |
373 | BOOL_VEC2 = 0x8B57, |
374 | BOOL_VEC3 = 0x8B58, |
375 | BOOL_VEC4 = 0x8B59, |
376 | FLOAT_MAT2 = 0x8B5A, |
377 | FLOAT_MAT3 = 0x8B5B, |
378 | FLOAT_MAT4 = 0x8B5C, |
379 | SAMPLER_2D = 0x8B5E, |
380 | SAMPLER_CUBE = 0x8B60, |
381 | VERTEX_ATTRIB_ARRAY_ENABLED = 0x8622, |
382 | VERTEX_ATTRIB_ARRAY_SIZE = 0x8623, |
383 | VERTEX_ATTRIB_ARRAY_STRIDE = 0x8624, |
384 | VERTEX_ATTRIB_ARRAY_TYPE = 0x8625, |
385 | VERTEX_ATTRIB_ARRAY_NORMALIZED = 0x886A, |
386 | VERTEX_ATTRIB_ARRAY_POINTER = 0x8645, |
387 | VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = 0x889F, |
388 | IMPLEMENTATION_COLOR_READ_TYPE = 0x8B9A, |
389 | IMPLEMENTATION_COLOR_READ_FORMAT = 0x8B9B, |
390 | COMPILE_STATUS = 0x8B81, |
391 | INFO_LOG_LENGTH = 0x8B84, |
392 | SHADER_SOURCE_LENGTH = 0x8B88, |
393 | SHADER_COMPILER = 0x8DFA, |
394 | SHADER_BINARY_FORMATS = 0x8DF8, |
395 | NUM_SHADER_BINARY_FORMATS = 0x8DF9, |
396 | LOW_FLOAT = 0x8DF0, |
397 | MEDIUM_FLOAT = 0x8DF1, |
398 | HIGH_FLOAT = 0x8DF2, |
399 | LOW_INT = 0x8DF3, |
400 | MEDIUM_INT = 0x8DF4, |
401 | HIGH_INT = 0x8DF5, |
402 | FRAMEBUFFER = 0x8D40, |
403 | RENDERBUFFER = 0x8D41, |
404 | RGBA4 = 0x8056, |
405 | RGB5_A1 = 0x8057, |
406 | RGB565 = 0x8D62, |
407 | DEPTH_COMPONENT16 = 0x81A5, |
408 | STENCIL_INDEX = 0x1901, |
409 | STENCIL_INDEX8 = 0x8D48, |
410 | RENDERBUFFER_WIDTH = 0x8D42, |
411 | RENDERBUFFER_HEIGHT = 0x8D43, |
412 | RENDERBUFFER_INTERNAL_FORMAT = 0x8D44, |
413 | RENDERBUFFER_RED_SIZE = 0x8D50, |
414 | RENDERBUFFER_GREEN_SIZE = 0x8D51, |
415 | RENDERBUFFER_BLUE_SIZE = 0x8D52, |
416 | RENDERBUFFER_ALPHA_SIZE = 0x8D53, |
417 | RENDERBUFFER_DEPTH_SIZE = 0x8D54, |
418 | RENDERBUFFER_STENCIL_SIZE = 0x8D55, |
419 | FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = 0x8CD0, |
420 | FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = 0x8CD1, |
421 | FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = 0x8CD2, |
422 | FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = 0x8CD3, |
423 | COLOR_ATTACHMENT0 = 0x8CE0, |
424 | DEPTH_ATTACHMENT = 0x8D00, |
425 | STENCIL_ATTACHMENT = 0x8D20, |
426 | NONE = 0, |
427 | FRAMEBUFFER_COMPLETE = 0x8CD5, |
428 | FRAMEBUFFER_INCOMPLETE_ATTACHMENT = 0x8CD6, |
429 | FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = 0x8CD7, |
430 | FRAMEBUFFER_INCOMPLETE_DIMENSIONS = 0x8CD9, |
431 | FRAMEBUFFER_UNSUPPORTED = 0x8CDD, |
432 | FRAMEBUFFER_BINDING = 0x8CA6, |
433 | RENDERBUFFER_BINDING = 0x8CA7, |
434 | MAX_RENDERBUFFER_SIZE = 0x84E8, |
435 | INVALID_FRAMEBUFFER_OPERATION = 0x0506, |
436 | |
437 | // WebGL-specific enums |
438 | UNPACK_FLIP_Y_WEBGL = 0x9240, |
439 | UNPACK_PREMULTIPLY_ALPHA_WEBGL = 0x9241, |
440 | CONTEXT_LOST_WEBGL = 0x9242, |
441 | UNPACK_COLORSPACE_CONVERSION_WEBGL = 0x9243, |
442 | BROWSER_DEFAULT_WEBGL = 0x9244, |
443 | VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE = 0x88FE, |
444 | |
445 | // WebGL2 constants |
446 | READ_BUFFER = 0x0C02, |
447 | UNPACK_ROW_LENGTH = 0x0CF2, |
448 | UNPACK_SKIP_ROWS = 0x0CF3, |
449 | UNPACK_SKIP_PIXELS = 0x0CF4, |
450 | PACK_ROW_LENGTH = 0x0D02, |
451 | PACK_SKIP_ROWS = 0x0D03, |
452 | PACK_SKIP_PIXELS = 0x0D04, |
453 | COLOR = 0x1800, |
454 | DEPTH = 0x1801, |
455 | STENCIL = 0x1802, |
456 | RED = 0x1903, |
457 | RGB8 = 0x8051, |
458 | RGBA8 = 0x8058, |
459 | RGB10_A2 = 0x8059, |
460 | TEXTURE_BINDING_3D = 0x806A, |
461 | UNPACK_SKIP_IMAGES = 0x806D, |
462 | UNPACK_IMAGE_HEIGHT = 0x806E, |
463 | TEXTURE_3D = 0x806F, |
464 | TEXTURE_WRAP_R = 0x8072, |
465 | MAX_3D_TEXTURE_SIZE = 0x8073, |
466 | UNSIGNED_INT_2_10_10_10_REV = 0x8368, |
467 | MAX_ELEMENTS_VERTICES = 0x80E8, |
468 | MAX_ELEMENTS_INDICES = 0x80E9, |
469 | TEXTURE_MIN_LOD = 0x813A, |
470 | TEXTURE_MAX_LOD = 0x813B, |
471 | TEXTURE_BASE_LEVEL = 0x813C, |
472 | TEXTURE_MAX_LEVEL = 0x813D, |
473 | MIN = 0x8007, |
474 | MAX = 0x8008, |
475 | DEPTH_COMPONENT24 = 0x81A6, |
476 | MAX_TEXTURE_LOD_BIAS = 0x84FD, |
477 | TEXTURE_COMPARE_MODE = 0x884C, |
478 | TEXTURE_COMPARE_FUNC = 0x884D, |
479 | CURRENT_QUERY = 0x8865, |
480 | QUERY_RESULT = 0x8866, |
481 | QUERY_RESULT_AVAILABLE = 0x8867, |
482 | STREAM_READ = 0x88E1, |
483 | STREAM_COPY = 0x88E2, |
484 | STATIC_READ = 0x88E5, |
485 | STATIC_COPY = 0x88E6, |
486 | DYNAMIC_READ = 0x88E9, |
487 | DYNAMIC_COPY = 0x88EA, |
488 | MAX_DRAW_BUFFERS = 0x8824, |
489 | DRAW_BUFFER0 = 0x8825, |
490 | DRAW_BUFFER1 = 0x8826, |
491 | DRAW_BUFFER2 = 0x8827, |
492 | DRAW_BUFFER3 = 0x8828, |
493 | DRAW_BUFFER4 = 0x8829, |
494 | DRAW_BUFFER5 = 0x882A, |
495 | DRAW_BUFFER6 = 0x882B, |
496 | DRAW_BUFFER7 = 0x882C, |
497 | DRAW_BUFFER8 = 0x882D, |
498 | DRAW_BUFFER9 = 0x882E, |
499 | DRAW_BUFFER10 = 0x882F, |
500 | DRAW_BUFFER11 = 0x8830, |
501 | DRAW_BUFFER12 = 0x8831, |
502 | DRAW_BUFFER13 = 0x8832, |
503 | DRAW_BUFFER14 = 0x8833, |
504 | DRAW_BUFFER15 = 0x8834, |
505 | MAX_FRAGMENT_UNIFORM_COMPONENTS = 0x8B49, |
506 | MAX_VERTEX_UNIFORM_COMPONENTS = 0x8B4A, |
507 | SAMPLER_3D = 0x8B5F, |
508 | SAMPLER_2D_SHADOW = 0x8B62, |
509 | FRAGMENT_SHADER_DERIVATIVE_HINT = 0x8B8B, |
510 | PIXEL_PACK_BUFFER = 0x88EB, |
511 | PIXEL_UNPACK_BUFFER = 0x88EC, |
512 | PIXEL_PACK_BUFFER_BINDING = 0x88ED, |
513 | PIXEL_UNPACK_BUFFER_BINDING = 0x88EF, |
514 | FLOAT_MAT2x3 = 0x8B65, |
515 | FLOAT_MAT2x4 = 0x8B66, |
516 | FLOAT_MAT3x2 = 0x8B67, |
517 | FLOAT_MAT3x4 = 0x8B68, |
518 | FLOAT_MAT4x2 = 0x8B69, |
519 | FLOAT_MAT4x3 = 0x8B6A, |
520 | SRGB = 0x8C40, |
521 | SRGB8 = 0x8C41, |
522 | SRGB_ALPHA = 0x8C42, |
523 | SRGB8_ALPHA8 = 0x8C43, |
524 | COMPARE_REF_TO_TEXTURE = 0x884E, |
525 | RGBA32F = 0x8814, |
526 | RGB32F = 0x8815, |
527 | RGBA16F = 0x881A, |
528 | RGB16F = 0x881B, |
529 | VERTEX_ATTRIB_ARRAY_INTEGER = 0x88FD, |
530 | MAX_ARRAY_TEXTURE_LAYERS = 0x88FF, |
531 | MIN_PROGRAM_TEXEL_OFFSET = 0x8904, |
532 | MAX_PROGRAM_TEXEL_OFFSET = 0x8905, |
533 | MAX_VARYING_COMPONENTS = 0x8B4B, |
534 | TEXTURE_2D_ARRAY = 0x8C1A, |
535 | TEXTURE_BINDING_2D_ARRAY = 0x8C1D, |
536 | R11F_G11F_B10F = 0x8C3A, |
537 | UNSIGNED_INT_10F_11F_11F_REV = 0x8C3B, |
538 | RGB9_E5 = 0x8C3D, |
539 | UNSIGNED_INT_5_9_9_9_REV = 0x8C3E, |
540 | TRANSFORM_FEEDBACK_BUFFER_MODE = 0x8C7F, |
541 | MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS = 0x8C80, |
542 | TRANSFORM_FEEDBACK_VARYINGS = 0x8C83, |
543 | TRANSFORM_FEEDBACK_BUFFER_START = 0x8C84, |
544 | TRANSFORM_FEEDBACK_BUFFER_SIZE = 0x8C85, |
545 | TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN = 0x8C88, |
546 | RASTERIZER_DISCARD = 0x8C89, |
547 | MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS = 0x8C8A, |
548 | MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS = 0x8C8B, |
549 | INTERLEAVED_ATTRIBS = 0x8C8C, |
550 | SEPARATE_ATTRIBS = 0x8C8D, |
551 | TRANSFORM_FEEDBACK_BUFFER = 0x8C8E, |
552 | TRANSFORM_FEEDBACK_BUFFER_BINDING = 0x8C8F, |
553 | RGBA32UI = 0x8D70, |
554 | RGB32UI = 0x8D71, |
555 | RGBA16UI = 0x8D76, |
556 | RGB16UI = 0x8D77, |
557 | RGBA8UI = 0x8D7C, |
558 | RGB8UI = 0x8D7D, |
559 | RGBA32I = 0x8D82, |
560 | RGB32I = 0x8D83, |
561 | RGBA16I = 0x8D88, |
562 | RGB16I = 0x8D89, |
563 | RGBA8I = 0x8D8E, |
564 | RGB8I = 0x8D8F, |
565 | RED_INTEGER = 0x8D94, |
566 | RGB_INTEGER = 0x8D98, |
567 | RGBA_INTEGER = 0x8D99, |
568 | SAMPLER_2D_ARRAY = 0x8DC1, |
569 | SAMPLER_2D_ARRAY_SHADOW = 0x8DC4, |
570 | SAMPLER_CUBE_SHADOW = 0x8DC5, |
571 | UNSIGNED_INT_VEC2 = 0x8DC6, |
572 | UNSIGNED_INT_VEC3 = 0x8DC7, |
573 | UNSIGNED_INT_VEC4 = 0x8DC8, |
574 | INT_SAMPLER_2D = 0x8DCA, |
575 | INT_SAMPLER_3D = 0x8DCB, |
576 | INT_SAMPLER_CUBE = 0x8DCC, |
577 | INT_SAMPLER_2D_ARRAY = 0x8DCF, |
578 | UNSIGNED_INT_SAMPLER_2D = 0x8DD2, |
579 | UNSIGNED_INT_SAMPLER_3D = 0x8DD3, |
580 | UNSIGNED_INT_SAMPLER_CUBE = 0x8DD4, |
581 | UNSIGNED_INT_SAMPLER_2D_ARRAY = 0x8DD7, |
582 | DEPTH_COMPONENT32F = 0x8CAC, |
583 | DEPTH32F_STENCIL8 = 0x8CAD, |
584 | FLOAT_32_UNSIGNED_INT_24_8_REV = 0x8DAD, |
585 | FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING = 0x8210, |
586 | FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE = 0x8211, |
587 | FRAMEBUFFER_ATTACHMENT_RED_SIZE = 0x8212, |
588 | FRAMEBUFFER_ATTACHMENT_GREEN_SIZE = 0x8213, |
589 | FRAMEBUFFER_ATTACHMENT_BLUE_SIZE = 0x8214, |
590 | FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE = 0x8215, |
591 | FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE = 0x8216, |
592 | FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE = 0x8217, |
593 | FRAMEBUFFER_DEFAULT = 0x8218, |
594 | DEPTH_STENCIL_ATTACHMENT = 0x821A, |
595 | DEPTH_STENCIL = 0x84F9, |
596 | UNSIGNED_INT_24_8 = 0x84FA, |
597 | DEPTH24_STENCIL8 = 0x88F0, |
598 | UNSIGNED_NORMALIZED = 0x8C17, |
599 | DRAW_FRAMEBUFFER_BINDING = 0x8CA6, /* Same as FRAMEBUFFER_BINDING */ |
600 | READ_FRAMEBUFFER = 0x8CA8, |
601 | DRAW_FRAMEBUFFER = 0x8CA9, |
602 | READ_FRAMEBUFFER_BINDING = 0x8CAA, |
603 | RENDERBUFFER_SAMPLES = 0x8CAB, |
604 | FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER = 0x8CD4, |
605 | MAX_COLOR_ATTACHMENTS = 0x8CDF, |
606 | COLOR_ATTACHMENT1 = 0x8CE1, |
607 | COLOR_ATTACHMENT2 = 0x8CE2, |
608 | COLOR_ATTACHMENT3 = 0x8CE3, |
609 | COLOR_ATTACHMENT4 = 0x8CE4, |
610 | COLOR_ATTACHMENT5 = 0x8CE5, |
611 | COLOR_ATTACHMENT6 = 0x8CE6, |
612 | COLOR_ATTACHMENT7 = 0x8CE7, |
613 | COLOR_ATTACHMENT8 = 0x8CE8, |
614 | COLOR_ATTACHMENT9 = 0x8CE9, |
615 | COLOR_ATTACHMENT10 = 0x8CEA, |
616 | COLOR_ATTACHMENT11 = 0x8CEB, |
617 | COLOR_ATTACHMENT12 = 0x8CEC, |
618 | COLOR_ATTACHMENT13 = 0x8CED, |
619 | COLOR_ATTACHMENT14 = 0x8CEE, |
620 | COLOR_ATTACHMENT15 = 0x8CEF, |
621 | FRAMEBUFFER_INCOMPLETE_MULTISAMPLE = 0x8D56, |
622 | MAX_SAMPLES = 0x8D57, |
623 | HALF_FLOAT = 0x140B, |
624 | RG = 0x8227, |
625 | RG_INTEGER = 0x8228, |
626 | R8 = 0x8229, |
627 | RG8 = 0x822B, |
628 | R16F = 0x822D, |
629 | R32F = 0x822E, |
630 | RG16F = 0x822F, |
631 | RG32F = 0x8230, |
632 | R8I = 0x8231, |
633 | R8UI = 0x8232, |
634 | R16I = 0x8233, |
635 | R16UI = 0x8234, |
636 | R32I = 0x8235, |
637 | R32UI = 0x8236, |
638 | RG8I = 0x8237, |
639 | RG8UI = 0x8238, |
640 | RG16I = 0x8239, |
641 | RG16UI = 0x823A, |
642 | RG32I = 0x823B, |
643 | RG32UI = 0x823C, |
644 | VERTEX_ARRAY_BINDING = 0x85B5, |
645 | R8_SNORM = 0x8F94, |
646 | RG8_SNORM = 0x8F95, |
647 | RGB8_SNORM = 0x8F96, |
648 | RGBA8_SNORM = 0x8F97, |
649 | SIGNED_NORMALIZED = 0x8F9C, |
650 | COPY_READ_BUFFER = 0x8F36, |
651 | COPY_WRITE_BUFFER = 0x8F37, |
652 | COPY_READ_BUFFER_BINDING = 0x8F36, /* Same as COPY_READ_BUFFER */ |
653 | COPY_WRITE_BUFFER_BINDING = 0x8F37, /* Same as COPY_WRITE_BUFFER */ |
654 | UNIFORM_BUFFER = 0x8A11, |
655 | UNIFORM_BUFFER_BINDING = 0x8A28, |
656 | UNIFORM_BUFFER_START = 0x8A29, |
657 | UNIFORM_BUFFER_SIZE = 0x8A2A, |
658 | MAX_VERTEX_UNIFORM_BLOCKS = 0x8A2B, |
659 | MAX_FRAGMENT_UNIFORM_BLOCKS = 0x8A2D, |
660 | MAX_COMBINED_UNIFORM_BLOCKS = 0x8A2E, |
661 | MAX_UNIFORM_BUFFER_BINDINGS = 0x8A2F, |
662 | MAX_UNIFORM_BLOCK_SIZE = 0x8A30, |
663 | MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS = 0x8A31, |
664 | MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS = 0x8A33, |
665 | UNIFORM_BUFFER_OFFSET_ALIGNMENT = 0x8A34, |
666 | ACTIVE_UNIFORM_BLOCKS = 0x8A36, |
667 | UNIFORM_TYPE = 0x8A37, |
668 | UNIFORM_SIZE = 0x8A38, |
669 | UNIFORM_BLOCK_INDEX = 0x8A3A, |
670 | UNIFORM_OFFSET = 0x8A3B, |
671 | UNIFORM_ARRAY_STRIDE = 0x8A3C, |
672 | UNIFORM_MATRIX_STRIDE = 0x8A3D, |
673 | UNIFORM_IS_ROW_MAJOR = 0x8A3E, |
674 | UNIFORM_BLOCK_BINDING = 0x8A3F, |
675 | UNIFORM_BLOCK_DATA_SIZE = 0x8A40, |
676 | UNIFORM_BLOCK_ACTIVE_UNIFORMS = 0x8A42, |
677 | UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES = 0x8A43, |
678 | UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER = 0x8A44, |
679 | UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER = 0x8A46, |
680 | INVALID_INDEX = 0xFFFFFFFF, |
681 | MAX_VERTEX_OUTPUT_COMPONENTS = 0x9122, |
682 | MAX_FRAGMENT_INPUT_COMPONENTS = 0x9125, |
683 | MAX_SERVER_WAIT_TIMEOUT = 0x9111, |
684 | OBJECT_TYPE = 0x9112, |
685 | SYNC_CONDITION = 0x9113, |
686 | SYNC_STATUS = 0x9114, |
687 | SYNC_FLAGS = 0x9115, |
688 | SYNC_FENCE = 0x9116, |
689 | SYNC_GPU_COMMANDS_COMPLETE = 0x9117, |
690 | UNSIGNALED = 0x9118, |
691 | SIGNALED = 0x9119, |
692 | ALREADY_SIGNALED = 0x911A, |
693 | TIMEOUT_EXPIRED = 0x911B, |
694 | CONDITION_SATISFIED = 0x911C, |
695 | #if PLATFORM(WIN) |
696 | WAIT_FAILED_WIN = 0x911D, |
697 | #else |
698 | WAIT_FAILED = 0x911D, |
699 | #endif |
700 | SYNC_FLUSH_COMMANDS_BIT = 0x00000001, |
701 | VERTEX_ATTRIB_ARRAY_DIVISOR = 0x88FE, |
702 | ANY_SAMPLES_PASSED = 0x8C2F, |
703 | ANY_SAMPLES_PASSED_CONSERVATIVE = 0x8D6A, |
704 | SAMPLER_BINDING = 0x8919, |
705 | RGB10_A2UI = 0x906F, |
706 | TEXTURE_SWIZZLE_R = 0x8E42, |
707 | TEXTURE_SWIZZLE_G = 0x8E43, |
708 | TEXTURE_SWIZZLE_B = 0x8E44, |
709 | TEXTURE_SWIZZLE_A = 0x8E45, |
710 | GREEN = 0x1904, |
711 | BLUE = 0x1905, |
712 | INT_2_10_10_10_REV = 0x8D9F, |
713 | TRANSFORM_FEEDBACK = 0x8E22, |
714 | TRANSFORM_FEEDBACK_PAUSED = 0x8E23, |
715 | TRANSFORM_FEEDBACK_ACTIVE = 0x8E24, |
716 | TRANSFORM_FEEDBACK_BINDING = 0x8E25, |
717 | COMPRESSED_R11_EAC = 0x9270, |
718 | COMPRESSED_SIGNED_R11_EAC = 0x9271, |
719 | COMPRESSED_RG11_EAC = 0x9272, |
720 | COMPRESSED_SIGNED_RG11_EAC = 0x9273, |
721 | COMPRESSED_RGB8_ETC2 = 0x9274, |
722 | COMPRESSED_SRGB8_ETC2 = 0x9275, |
723 | COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276, |
724 | COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277, |
725 | COMPRESSED_RGBA8_ETC2_EAC = 0x9278, |
726 | COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279, |
727 | TEXTURE_IMMUTABLE_FORMAT = 0x912F, |
728 | MAX_ELEMENT_INDEX = 0x8D6B, |
729 | NUM_SAMPLE_COUNTS = 0x9380, |
730 | TEXTURE_IMMUTABLE_LEVELS = 0x82DF, |
731 | PRIMITIVE_RESTART_FIXED_INDEX = 0x8D69, |
732 | PRIMITIVE_RESTART = 0x8F9D, |
733 | |
734 | // OpenGL ES 3 constants |
735 | MAP_READ_BIT = 0x0001 |
736 | }; |
737 | |
738 | enum RenderStyle { |
739 | RenderOffscreen, |
740 | RenderDirectlyToHostWindow, |
741 | }; |
742 | |
743 | class ContextLostCallback { |
744 | public: |
745 | virtual void onContextLost() = 0; |
746 | virtual ~ContextLostCallback() = default; |
747 | }; |
748 | |
749 | class ErrorMessageCallback { |
750 | public: |
751 | virtual void onErrorMessage(const String& message, GC3Dint id) = 0; |
752 | virtual ~ErrorMessageCallback() = default; |
753 | }; |
754 | |
755 | void setContextLostCallback(std::unique_ptr<ContextLostCallback>); |
756 | void setErrorMessageCallback(std::unique_ptr<ErrorMessageCallback>); |
757 | |
758 | static RefPtr<GraphicsContext3D> create(GraphicsContext3DAttributes, HostWindow*, RenderStyle = RenderOffscreen); |
759 | ~GraphicsContext3D(); |
760 | |
761 | #if PLATFORM(COCOA) |
762 | static Ref<GraphicsContext3D> createShared(GraphicsContext3D& sharedContext); |
763 | #endif |
764 | |
765 | #if PLATFORM(COCOA) |
766 | PlatformGraphicsContext3D platformGraphicsContext3D() const { return m_contextObj; } |
767 | Platform3DObject platformTexture() const { return m_texture; } |
768 | CALayer* platformLayer() const { return reinterpret_cast<CALayer*>(m_webGLLayer.get()); } |
769 | #else |
770 | PlatformGraphicsContext3D platformGraphicsContext3D(); |
771 | Platform3DObject platformTexture() const; |
772 | PlatformLayer* platformLayer() const; |
773 | #endif |
774 | |
775 | bool makeContextCurrent(); |
776 | |
777 | void addClient(Client& client) { m_clients.add(&client); } |
778 | void removeClient(Client& client) { m_clients.remove(&client); } |
779 | |
780 | // With multisampling on, blit from multisampleFBO to regular FBO. |
781 | void prepareTexture(); |
782 | |
783 | // Equivalent to ::glTexImage2D(). Allows pixels==0 with no allocation. |
784 | void texImage2DDirect(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels); |
785 | |
786 | // Get an attribute location without checking the name -> mangledname mapping. |
787 | int getAttribLocationDirect(Platform3DObject program, const String& name); |
788 | |
789 | // Compile a shader without going through ANGLE. |
790 | void compileShaderDirect(Platform3DObject); |
791 | |
792 | // Helper to texImage2D with pixel==0 case: pixels are initialized to 0. |
793 | // Return true if no GL error is synthesized. |
794 | // By default, alignment is 4, the OpenGL default setting. |
795 | bool texImage2DResourceSafe(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, GC3Dint alignment = 4); |
796 | |
797 | bool isGLES2Compliant() const; |
798 | |
799 | //---------------------------------------------------------------------- |
800 | // Helpers for texture uploading and pixel readback. |
801 | // |
802 | |
803 | // Computes the components per pixel and bytes per component |
804 | // for the given format and type combination. Returns false if |
805 | // either was an invalid enum. |
806 | static bool computeFormatAndTypeParameters(GC3Denum format, |
807 | GC3Denum type, |
808 | unsigned int* componentsPerPixel, |
809 | unsigned int* bytesPerComponent); |
810 | |
811 | // Computes the image size in bytes. If paddingInBytes is not null, padding |
812 | // is also calculated in return. Returns NO_ERROR if succeed, otherwise |
813 | // return the suggested GL error indicating the cause of the failure: |
814 | // INVALID_VALUE if width/height is negative or overflow happens. |
815 | // INVALID_ENUM if format/type is illegal. |
816 | static GC3Denum computeImageSizeInBytes(GC3Denum format, |
817 | GC3Denum type, |
818 | GC3Dsizei width, |
819 | GC3Dsizei height, |
820 | GC3Dint alignment, |
821 | unsigned int* imageSizeInBytes, |
822 | unsigned int* paddingInBytes); |
823 | |
824 | static bool possibleFormatAndTypeForInternalFormat(GC3Denum internalFormat, GC3Denum& format, GC3Denum& type); |
825 | |
826 | // Extracts the contents of the given ImageData into the passed Vector, |
827 | // packing the pixel data according to the given format and type, |
828 | // and obeying the flipY and premultiplyAlpha flags. Returns true |
829 | // upon success. |
830 | static bool (ImageData*, |
831 | GC3Denum format, |
832 | GC3Denum type, |
833 | bool flipY, |
834 | bool premultiplyAlpha, |
835 | Vector<uint8_t>& data); |
836 | |
837 | // Helper function which extracts the user-supplied texture |
838 | // data, applying the flipY and premultiplyAlpha parameters. |
839 | // If the data is not tightly packed according to the passed |
840 | // unpackAlignment, the output data will be tightly packed. |
841 | // Returns true if successful, false if any error occurred. |
842 | static bool (unsigned int width, unsigned int height, |
843 | GC3Denum format, GC3Denum type, |
844 | unsigned int unpackAlignment, |
845 | bool flipY, bool premultiplyAlpha, |
846 | const void* pixels, |
847 | Vector<uint8_t>& data); |
848 | |
849 | |
850 | // Attempt to enumerate all possible native image formats to |
851 | // reduce the amount of temporary allocations during texture |
852 | // uploading. This enum must be public because it is accessed |
853 | // by non-member functions. |
854 | enum DataFormat { |
855 | DataFormatRGBA8 = 0, |
856 | DataFormatRGBA16Little, |
857 | DataFormatRGBA16Big, |
858 | DataFormatRGBA16F, |
859 | DataFormatRGBA32F, |
860 | DataFormatRGB8, |
861 | DataFormatRGB16Little, |
862 | DataFormatRGB16Big, |
863 | DataFormatRGB16F, |
864 | DataFormatRGB32F, |
865 | DataFormatBGR8, |
866 | DataFormatBGRA8, |
867 | DataFormatBGRA16Little, |
868 | DataFormatBGRA16Big, |
869 | DataFormatARGB8, |
870 | DataFormatARGB16Little, |
871 | DataFormatARGB16Big, |
872 | DataFormatABGR8, |
873 | DataFormatRGBA5551, |
874 | DataFormatRGBA4444, |
875 | DataFormatRGB565, |
876 | DataFormatR8, |
877 | DataFormatR16Little, |
878 | DataFormatR16Big, |
879 | DataFormatR16F, |
880 | DataFormatR32F, |
881 | DataFormatRA8, |
882 | DataFormatRA16Little, |
883 | DataFormatRA16Big, |
884 | DataFormatRA16F, |
885 | DataFormatRA32F, |
886 | DataFormatAR8, |
887 | DataFormatAR16Little, |
888 | DataFormatAR16Big, |
889 | DataFormatA8, |
890 | DataFormatA16Little, |
891 | DataFormatA16Big, |
892 | DataFormatA16F, |
893 | DataFormatA32F, |
894 | DataFormatNumFormats |
895 | }; |
896 | |
897 | ALWAYS_INLINE static bool hasAlpha(DataFormat format) |
898 | { |
899 | switch (format) { |
900 | case GraphicsContext3D::DataFormatA8: |
901 | case GraphicsContext3D::DataFormatA16F: |
902 | case GraphicsContext3D::DataFormatA32F: |
903 | case GraphicsContext3D::DataFormatRA8: |
904 | case GraphicsContext3D::DataFormatAR8: |
905 | case GraphicsContext3D::DataFormatRA16F: |
906 | case GraphicsContext3D::DataFormatRA32F: |
907 | case GraphicsContext3D::DataFormatRGBA8: |
908 | case GraphicsContext3D::DataFormatBGRA8: |
909 | case GraphicsContext3D::DataFormatARGB8: |
910 | case GraphicsContext3D::DataFormatABGR8: |
911 | case GraphicsContext3D::DataFormatRGBA16F: |
912 | case GraphicsContext3D::DataFormatRGBA32F: |
913 | case GraphicsContext3D::DataFormatRGBA4444: |
914 | case GraphicsContext3D::DataFormatRGBA5551: |
915 | return true; |
916 | default: |
917 | return false; |
918 | } |
919 | } |
920 | |
921 | ALWAYS_INLINE static bool hasColor(DataFormat format) |
922 | { |
923 | switch (format) { |
924 | case GraphicsContext3D::DataFormatRGBA8: |
925 | case GraphicsContext3D::DataFormatRGBA16F: |
926 | case GraphicsContext3D::DataFormatRGBA32F: |
927 | case GraphicsContext3D::DataFormatRGB8: |
928 | case GraphicsContext3D::DataFormatRGB16F: |
929 | case GraphicsContext3D::DataFormatRGB32F: |
930 | case GraphicsContext3D::DataFormatBGR8: |
931 | case GraphicsContext3D::DataFormatBGRA8: |
932 | case GraphicsContext3D::DataFormatARGB8: |
933 | case GraphicsContext3D::DataFormatABGR8: |
934 | case GraphicsContext3D::DataFormatRGBA5551: |
935 | case GraphicsContext3D::DataFormatRGBA4444: |
936 | case GraphicsContext3D::DataFormatRGB565: |
937 | case GraphicsContext3D::DataFormatR8: |
938 | case GraphicsContext3D::DataFormatR16F: |
939 | case GraphicsContext3D::DataFormatR32F: |
940 | case GraphicsContext3D::DataFormatRA8: |
941 | case GraphicsContext3D::DataFormatRA16F: |
942 | case GraphicsContext3D::DataFormatRA32F: |
943 | case GraphicsContext3D::DataFormatAR8: |
944 | return true; |
945 | default: |
946 | return false; |
947 | } |
948 | } |
949 | |
950 | // Check if the format is one of the formats from the ImageData or DOM elements. |
951 | // The formats from ImageData is always RGBA8. |
952 | // The formats from DOM elements vary with Graphics ports. It can only be RGBA8 or BGRA8 for non-CG port while a little more for CG port. |
953 | static ALWAYS_INLINE bool srcFormatComesFromDOMElementOrImageData(DataFormat SrcFormat) |
954 | { |
955 | #if USE(CG) |
956 | #if CPU(BIG_ENDIAN) |
957 | return SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8 |
958 | || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8 || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8; |
959 | #else |
960 | // That LITTLE_ENDIAN case has more possible formats than BIG_ENDIAN case is because some decoded image data is actually big endian |
961 | // even on little endian architectures. |
962 | return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatABGR8 || SrcFormat == DataFormatBGR8 |
963 | || SrcFormat == DataFormatRGBA8 || SrcFormat == DataFormatARGB8 || SrcFormat == DataFormatRGB8 |
964 | || SrcFormat == DataFormatR8 || SrcFormat == DataFormatA8 |
965 | || SrcFormat == DataFormatRA8 || SrcFormat == DataFormatAR8; |
966 | #endif |
967 | #else |
968 | return SrcFormat == DataFormatBGRA8 || SrcFormat == DataFormatRGBA8; |
969 | #endif |
970 | } |
971 | |
972 | //---------------------------------------------------------------------- |
973 | // Entry points for WebGL. |
974 | // |
975 | |
976 | void activeTexture(GC3Denum texture); |
977 | void attachShader(Platform3DObject program, Platform3DObject shader); |
978 | void bindAttribLocation(Platform3DObject, GC3Duint index, const String& name); |
979 | void bindBuffer(GC3Denum target, Platform3DObject); |
980 | void bindFramebuffer(GC3Denum target, Platform3DObject); |
981 | void bindRenderbuffer(GC3Denum target, Platform3DObject); |
982 | void bindTexture(GC3Denum target, Platform3DObject); |
983 | void blendColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha); |
984 | void blendEquation(GC3Denum mode); |
985 | void blendEquationSeparate(GC3Denum modeRGB, GC3Denum modeAlpha); |
986 | void blendFunc(GC3Denum sfactor, GC3Denum dfactor); |
987 | void blendFuncSeparate(GC3Denum srcRGB, GC3Denum dstRGB, GC3Denum srcAlpha, GC3Denum dstAlpha); |
988 | |
989 | void bufferData(GC3Denum target, GC3Dsizeiptr size, GC3Denum usage); |
990 | void bufferData(GC3Denum target, GC3Dsizeiptr size, const void* data, GC3Denum usage); |
991 | void bufferSubData(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr size, const void* data); |
992 | |
993 | void* mapBufferRange(GC3Denum target, GC3Dintptr offset, GC3Dsizeiptr length, GC3Dbitfield access); |
994 | GC3Dboolean unmapBuffer(GC3Denum target); |
995 | void copyBufferSubData(GC3Denum readTarget, GC3Denum writeTarget, GC3Dintptr readOffset, GC3Dintptr writeOffset, GC3Dsizeiptr); |
996 | |
997 | void getInternalformativ(GC3Denum target, GC3Denum internalformat, GC3Denum pname, GC3Dsizei bufSize, GC3Dint* params); |
998 | void renderbufferStorageMultisample(GC3Denum target, GC3Dsizei samples, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height); |
999 | |
1000 | void texStorage2D(GC3Denum target, GC3Dsizei levels, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height); |
1001 | void texStorage3D(GC3Denum target, GC3Dsizei levels, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dsizei depth); |
1002 | |
1003 | void getActiveUniforms(Platform3DObject program, const Vector<GC3Duint>& uniformIndices, GC3Denum pname, Vector<GC3Dint>& params); |
1004 | |
1005 | GC3Denum checkFramebufferStatus(GC3Denum target); |
1006 | void clear(GC3Dbitfield mask); |
1007 | void clearColor(GC3Dclampf red, GC3Dclampf green, GC3Dclampf blue, GC3Dclampf alpha); |
1008 | void clearDepth(GC3Dclampf depth); |
1009 | void clearStencil(GC3Dint s); |
1010 | void colorMask(GC3Dboolean red, GC3Dboolean green, GC3Dboolean blue, GC3Dboolean alpha); |
1011 | void compileShader(Platform3DObject); |
1012 | |
1013 | void compressedTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Dsizei imageSize, const void* data); |
1014 | void compressedTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Dsizei imageSize, const void* data); |
1015 | void copyTexImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Dint border); |
1016 | void copyTexSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); |
1017 | void cullFace(GC3Denum mode); |
1018 | void depthFunc(GC3Denum func); |
1019 | void depthMask(GC3Dboolean flag); |
1020 | void depthRange(GC3Dclampf zNear, GC3Dclampf zFar); |
1021 | void detachShader(Platform3DObject, Platform3DObject); |
1022 | void disable(GC3Denum cap); |
1023 | void disableVertexAttribArray(GC3Duint index); |
1024 | void drawArrays(GC3Denum mode, GC3Dint first, GC3Dsizei count); |
1025 | void drawElements(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset); |
1026 | |
1027 | void enable(GC3Denum cap); |
1028 | void enableVertexAttribArray(GC3Duint index); |
1029 | void finish(); |
1030 | void flush(); |
1031 | void framebufferRenderbuffer(GC3Denum target, GC3Denum attachment, GC3Denum renderbuffertarget, Platform3DObject); |
1032 | void framebufferTexture2D(GC3Denum target, GC3Denum attachment, GC3Denum textarget, Platform3DObject, GC3Dint level); |
1033 | void frontFace(GC3Denum mode); |
1034 | void generateMipmap(GC3Denum target); |
1035 | |
1036 | bool getActiveAttrib(Platform3DObject program, GC3Duint index, ActiveInfo&); |
1037 | bool getActiveAttribImpl(Platform3DObject program, GC3Duint index, ActiveInfo&); |
1038 | bool getActiveUniform(Platform3DObject program, GC3Duint index, ActiveInfo&); |
1039 | bool getActiveUniformImpl(Platform3DObject program, GC3Duint index, ActiveInfo&); |
1040 | void getAttachedShaders(Platform3DObject program, GC3Dsizei maxCount, GC3Dsizei* count, Platform3DObject* shaders); |
1041 | GC3Dint getAttribLocation(Platform3DObject, const String& name); |
1042 | void getBooleanv(GC3Denum pname, GC3Dboolean* value); |
1043 | void getBufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value); |
1044 | GraphicsContext3DAttributes getContextAttributes(); |
1045 | GC3Denum getError(); |
1046 | void getFloatv(GC3Denum pname, GC3Dfloat* value); |
1047 | void getFramebufferAttachmentParameteriv(GC3Denum target, GC3Denum attachment, GC3Denum pname, GC3Dint* value); |
1048 | void getIntegerv(GC3Denum pname, GC3Dint* value); |
1049 | void getInteger64v(GC3Denum pname, GC3Dint64* value); |
1050 | void getProgramiv(Platform3DObject program, GC3Denum pname, GC3Dint* value); |
1051 | void getNonBuiltInActiveSymbolCount(Platform3DObject program, GC3Denum pname, GC3Dint* value); |
1052 | String getProgramInfoLog(Platform3DObject); |
1053 | String getUnmangledInfoLog(Platform3DObject[2], GC3Dsizei, const String&); |
1054 | void getRenderbufferParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value); |
1055 | void getShaderiv(Platform3DObject, GC3Denum pname, GC3Dint* value); |
1056 | String getShaderInfoLog(Platform3DObject); |
1057 | void getShaderPrecisionFormat(GC3Denum shaderType, GC3Denum precisionType, GC3Dint* range, GC3Dint* precision); |
1058 | String getShaderSource(Platform3DObject); |
1059 | String getString(GC3Denum name); |
1060 | void getTexParameterfv(GC3Denum target, GC3Denum pname, GC3Dfloat* value); |
1061 | void getTexParameteriv(GC3Denum target, GC3Denum pname, GC3Dint* value); |
1062 | void getUniformfv(Platform3DObject program, GC3Dint location, GC3Dfloat* value); |
1063 | void getUniformiv(Platform3DObject program, GC3Dint location, GC3Dint* value); |
1064 | GC3Dint getUniformLocation(Platform3DObject, const String& name); |
1065 | void getVertexAttribfv(GC3Duint index, GC3Denum pname, GC3Dfloat* value); |
1066 | void getVertexAttribiv(GC3Duint index, GC3Denum pname, GC3Dint* value); |
1067 | GC3Dsizeiptr getVertexAttribOffset(GC3Duint index, GC3Denum pname); |
1068 | |
1069 | void hint(GC3Denum target, GC3Denum mode); |
1070 | GC3Dboolean isBuffer(Platform3DObject); |
1071 | GC3Dboolean isEnabled(GC3Denum cap); |
1072 | GC3Dboolean isFramebuffer(Platform3DObject); |
1073 | GC3Dboolean isProgram(Platform3DObject); |
1074 | GC3Dboolean isRenderbuffer(Platform3DObject); |
1075 | GC3Dboolean isShader(Platform3DObject); |
1076 | GC3Dboolean isTexture(Platform3DObject); |
1077 | void lineWidth(GC3Dfloat); |
1078 | void linkProgram(Platform3DObject); |
1079 | void pixelStorei(GC3Denum pname, GC3Dint param); |
1080 | void polygonOffset(GC3Dfloat factor, GC3Dfloat units); |
1081 | |
1082 | void readPixels(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, void* data); |
1083 | |
1084 | void releaseShaderCompiler(); |
1085 | |
1086 | void renderbufferStorage(GC3Denum target, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height); |
1087 | void sampleCoverage(GC3Dclampf value, GC3Dboolean invert); |
1088 | void scissor(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); |
1089 | void shaderSource(Platform3DObject, const String& string); |
1090 | void stencilFunc(GC3Denum func, GC3Dint ref, GC3Duint mask); |
1091 | void stencilFuncSeparate(GC3Denum face, GC3Denum func, GC3Dint ref, GC3Duint mask); |
1092 | void stencilMask(GC3Duint mask); |
1093 | void stencilMaskSeparate(GC3Denum face, GC3Duint mask); |
1094 | void stencilOp(GC3Denum fail, GC3Denum zfail, GC3Denum zpass); |
1095 | void stencilOpSeparate(GC3Denum face, GC3Denum fail, GC3Denum zfail, GC3Denum zpass); |
1096 | |
1097 | bool texImage2D(GC3Denum target, GC3Dint level, GC3Denum internalformat, GC3Dsizei width, GC3Dsizei height, GC3Dint border, GC3Denum format, GC3Denum type, const void* pixels); |
1098 | void texParameterf(GC3Denum target, GC3Denum pname, GC3Dfloat param); |
1099 | void texParameteri(GC3Denum target, GC3Denum pname, GC3Dint param); |
1100 | void texSubImage2D(GC3Denum target, GC3Dint level, GC3Dint xoffset, GC3Dint yoffset, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, const void* pixels); |
1101 | |
1102 | void uniform1f(GC3Dint location, GC3Dfloat x); |
1103 | void uniform1fv(GC3Dint location, GC3Dsizei, const GC3Dfloat* v); |
1104 | void uniform1i(GC3Dint location, GC3Dint x); |
1105 | void uniform1iv(GC3Dint location, GC3Dsizei, const GC3Dint* v); |
1106 | void uniform2f(GC3Dint location, GC3Dfloat x, GC3Dfloat y); |
1107 | void uniform2fv(GC3Dint location, GC3Dsizei, const GC3Dfloat* v); |
1108 | void uniform2i(GC3Dint location, GC3Dint x, GC3Dint y); |
1109 | void uniform2iv(GC3Dint location, GC3Dsizei, const GC3Dint* v); |
1110 | void uniform3f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z); |
1111 | void uniform3fv(GC3Dint location, GC3Dsizei, const GC3Dfloat* v); |
1112 | void uniform3i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z); |
1113 | void uniform3iv(GC3Dint location, GC3Dsizei, const GC3Dint* v); |
1114 | void uniform4f(GC3Dint location, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w); |
1115 | void uniform4fv(GC3Dint location, GC3Dsizei, const GC3Dfloat* v); |
1116 | void uniform4i(GC3Dint location, GC3Dint x, GC3Dint y, GC3Dint z, GC3Dint w); |
1117 | void uniform4iv(GC3Dint location, GC3Dsizei, const GC3Dint* v); |
1118 | void uniformMatrix2fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, const GC3Dfloat* value); |
1119 | void uniformMatrix3fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, const GC3Dfloat* value); |
1120 | void uniformMatrix4fv(GC3Dint location, GC3Dsizei, GC3Dboolean transpose, const GC3Dfloat* value); |
1121 | |
1122 | void useProgram(Platform3DObject); |
1123 | void validateProgram(Platform3DObject); |
1124 | bool checkVaryingsPacking(Platform3DObject vertexShader, Platform3DObject fragmentShader) const; |
1125 | bool precisionsMatch(Platform3DObject vertexShader, Platform3DObject fragmentShader) const; |
1126 | |
1127 | void vertexAttrib1f(GC3Duint index, GC3Dfloat x); |
1128 | void vertexAttrib1fv(GC3Duint index, const GC3Dfloat* values); |
1129 | void vertexAttrib2f(GC3Duint index, GC3Dfloat x, GC3Dfloat y); |
1130 | void vertexAttrib2fv(GC3Duint index, const GC3Dfloat* values); |
1131 | void vertexAttrib3f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z); |
1132 | void vertexAttrib3fv(GC3Duint index, const GC3Dfloat* values); |
1133 | void vertexAttrib4f(GC3Duint index, GC3Dfloat x, GC3Dfloat y, GC3Dfloat z, GC3Dfloat w); |
1134 | void vertexAttrib4fv(GC3Duint index, const GC3Dfloat* values); |
1135 | void vertexAttribPointer(GC3Duint index, GC3Dint size, GC3Denum type, GC3Dboolean normalized, |
1136 | GC3Dsizei stride, GC3Dintptr offset); |
1137 | |
1138 | void viewport(GC3Dint x, GC3Dint y, GC3Dsizei width, GC3Dsizei height); |
1139 | |
1140 | void reshape(int width, int height); |
1141 | |
1142 | void drawArraysInstanced(GC3Denum mode, GC3Dint first, GC3Dsizei count, GC3Dsizei primcount); |
1143 | void drawElementsInstanced(GC3Denum mode, GC3Dsizei count, GC3Denum type, GC3Dintptr offset, GC3Dsizei primcount); |
1144 | void vertexAttribDivisor(GC3Duint index, GC3Duint divisor); |
1145 | |
1146 | // VertexArrayOject calls |
1147 | Platform3DObject createVertexArray(); |
1148 | void deleteVertexArray(Platform3DObject); |
1149 | GC3Dboolean isVertexArray(Platform3DObject); |
1150 | void bindVertexArray(Platform3DObject); |
1151 | |
1152 | void paintToCanvas(const unsigned char* imagePixels, const IntSize& imageSize, const IntSize& canvasSize, GraphicsContext&); |
1153 | |
1154 | void markContextChanged(); |
1155 | void markLayerComposited(); |
1156 | bool layerComposited() const; |
1157 | void forceContextLost(); |
1158 | void recycleContext(); |
1159 | |
1160 | void dispatchContextChangedNotification(); |
1161 | void simulateContextChanged(); |
1162 | |
1163 | void paintRenderingResultsToCanvas(ImageBuffer*); |
1164 | RefPtr<ImageData> paintRenderingResultsToImageData(); |
1165 | bool paintCompositedResultsToCanvas(ImageBuffer*); |
1166 | |
1167 | #if USE(OPENGL) && ENABLE(WEBGL2) |
1168 | void primitiveRestartIndex(GC3Duint); |
1169 | #endif |
1170 | |
1171 | #if PLATFORM(COCOA) |
1172 | bool texImageIOSurface2D(GC3Denum target, GC3Denum internalFormat, GC3Dsizei width, GC3Dsizei height, GC3Denum format, GC3Denum type, IOSurfaceRef, GC3Duint plane); |
1173 | |
1174 | #if USE(OPENGL_ES) |
1175 | void presentRenderbuffer(); |
1176 | #endif |
1177 | |
1178 | #if USE(OPENGL) |
1179 | void allocateIOSurfaceBackingStore(IntSize); |
1180 | void updateFramebufferTextureBackingStoreFromLayer(); |
1181 | void updateCGLContext(); |
1182 | #endif |
1183 | #endif // PLATFORM(COCOA) |
1184 | |
1185 | void setContextVisibility(bool); |
1186 | |
1187 | GraphicsContext3DPowerPreference powerPreferenceUsedForCreation() const { return m_powerPreferenceUsedForCreation; } |
1188 | |
1189 | // Support for buffer creation and deletion |
1190 | Platform3DObject createBuffer(); |
1191 | Platform3DObject createFramebuffer(); |
1192 | Platform3DObject createProgram(); |
1193 | Platform3DObject createRenderbuffer(); |
1194 | Platform3DObject createShader(GC3Denum); |
1195 | Platform3DObject createTexture(); |
1196 | |
1197 | void deleteBuffer(Platform3DObject); |
1198 | void deleteFramebuffer(Platform3DObject); |
1199 | void deleteProgram(Platform3DObject); |
1200 | void deleteRenderbuffer(Platform3DObject); |
1201 | void deleteShader(Platform3DObject); |
1202 | void deleteTexture(Platform3DObject); |
1203 | |
1204 | // Synthesizes an OpenGL error which will be returned from a |
1205 | // later call to getError. This is used to emulate OpenGL ES |
1206 | // 2.0 behavior on the desktop and to enforce additional error |
1207 | // checking mandated by WebGL. |
1208 | // |
1209 | // Per the behavior of glGetError, this stores at most one |
1210 | // instance of any given error, and returns them from calls to |
1211 | // getError in the order they were added. |
1212 | void synthesizeGLError(GC3Denum error); |
1213 | |
1214 | // Read real OpenGL errors, and move them to the synthetic |
1215 | // error list. Return true if at least one error is moved. |
1216 | bool moveErrorsToSyntheticErrorList(); |
1217 | |
1218 | // Support for extensions. Returns a non-null object, though not |
1219 | // all methods it contains may necessarily be supported on the |
1220 | // current hardware. Must call Extensions3D::supports() to |
1221 | // determine this. |
1222 | Extensions3D& getExtensions(); |
1223 | |
1224 | IntSize getInternalFramebufferSize() const; |
1225 | |
1226 | static unsigned getClearBitsByAttachmentType(GC3Denum); |
1227 | static unsigned getClearBitsByFormat(GC3Denum); |
1228 | |
1229 | enum ChannelBits { |
1230 | ChannelRed = 1, |
1231 | ChannelGreen = 2, |
1232 | ChannelBlue = 4, |
1233 | ChannelAlpha = 8, |
1234 | ChannelDepth = 16, |
1235 | ChannelStencil = 32, |
1236 | ChannelRGB = ChannelRed | ChannelGreen | ChannelBlue, |
1237 | ChannelRGBA = ChannelRGB | ChannelAlpha, |
1238 | }; |
1239 | |
1240 | static unsigned getChannelBitsByFormat(GC3Denum); |
1241 | |
1242 | // Possible alpha operations that may need to occur during |
1243 | // pixel packing. FIXME: kAlphaDoUnmultiply is lossy and must |
1244 | // be removed. |
1245 | enum AlphaOp { |
1246 | AlphaDoNothing = 0, |
1247 | AlphaDoPremultiply = 1, |
1248 | AlphaDoUnmultiply = 2 |
1249 | }; |
1250 | |
1251 | enum ImageHtmlDomSource { |
1252 | HtmlDomImage = 0, |
1253 | HtmlDomCanvas = 1, |
1254 | HtmlDomVideo = 2, |
1255 | HtmlDomNone = 3 |
1256 | }; |
1257 | |
1258 | // Packs the contents of the given Image which is passed in |pixels| into the passed Vector |
1259 | // according to the given format and type, and obeying the flipY and AlphaOp flags. |
1260 | // Returns true upon success. |
1261 | static bool packImageData(Image*, const void* pixels, GC3Denum format, GC3Denum type, bool flipY, AlphaOp, DataFormat sourceFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, Vector<uint8_t>& data); |
1262 | |
1263 | class { |
1264 | public: |
1265 | (Image*, ImageHtmlDomSource, bool premultiplyAlpha, bool ignoreGammaAndColorProfile); |
1266 | |
1267 | // Each platform must provide an implementation of this method to deallocate or release resources |
1268 | // associated with the image if needed. |
1269 | (); |
1270 | |
1271 | bool () { return m_extractSucceeded; } |
1272 | const void* () { return m_imagePixelData; } |
1273 | unsigned () { return m_imageWidth; } |
1274 | unsigned () { return m_imageHeight; } |
1275 | DataFormat () { return m_imageSourceFormat; } |
1276 | AlphaOp () { return m_alphaOp; } |
1277 | unsigned () { return m_imageSourceUnpackAlignment; } |
1278 | ImageHtmlDomSource () { return m_imageHtmlDomSource; } |
1279 | private: |
1280 | // Each platform must provide an implementation of this method. |
1281 | // Extracts the image and keeps track of its status, such as width, height, Source Alignment, format and AlphaOp etc, |
1282 | // needs to lock the resources or relevant data if needed and returns true upon success |
1283 | bool (bool premultiplyAlpha, bool ignoreGammaAndColorProfile); |
1284 | |
1285 | #if USE(CAIRO) |
1286 | RefPtr<cairo_surface_t> ; |
1287 | #elif USE(CG) |
1288 | RetainPtr<CGImageRef> m_cgImage; |
1289 | RetainPtr<CGImageRef> m_decodedImage; |
1290 | RetainPtr<CFDataRef> m_pixelData; |
1291 | UniqueArray<uint8_t> m_formalizedRGBA8Data; |
1292 | #endif |
1293 | Image* ; |
1294 | ImageHtmlDomSource ; |
1295 | bool ; |
1296 | const void* ; |
1297 | unsigned ; |
1298 | unsigned ; |
1299 | DataFormat ; |
1300 | AlphaOp ; |
1301 | unsigned ; |
1302 | }; |
1303 | |
1304 | void setFailNextGPUStatusCheck() { m_failNextStatusCheck = true; } |
1305 | |
1306 | GC3Denum activeTextureUnit() const { return m_state.activeTextureUnit; } |
1307 | GC3Denum currentBoundTexture() const { return m_state.currentBoundTexture(); } |
1308 | GC3Denum currentBoundTarget() const { return m_state.currentBoundTarget(); } |
1309 | unsigned textureSeed(GC3Duint texture) { return m_state.textureSeedCount.count(texture); } |
1310 | |
1311 | #if PLATFORM(MAC) |
1312 | using PlatformDisplayID = uint32_t; |
1313 | void screenDidChange(PlatformDisplayID); |
1314 | #endif |
1315 | |
1316 | private: |
1317 | GraphicsContext3D(GraphicsContext3DAttributes, HostWindow*, RenderStyle = RenderOffscreen, GraphicsContext3D* sharedContext = nullptr); |
1318 | |
1319 | // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel |
1320 | // data into the specified OpenGL destination format and type. |
1321 | // A sourceUnpackAlignment of zero indicates that the source |
1322 | // data is tightly packed. Non-zero values may take a slow path. |
1323 | // Destination data will have no gaps between rows. |
1324 | static bool packPixels(const uint8_t* sourceData, DataFormat sourceDataFormat, unsigned width, unsigned height, unsigned sourceUnpackAlignment, unsigned destinationFormat, unsigned destinationType, AlphaOp, void* destinationData, bool flipY); |
1325 | |
1326 | // Take into account the user's requested context creation attributes, |
1327 | // in particular stencil and antialias, and determine which could or |
1328 | // could not be honored based on the capabilities of the OpenGL |
1329 | // implementation. |
1330 | void validateDepthStencil(const char* packedDepthStencilExtension); |
1331 | void validateAttributes(); |
1332 | |
1333 | // Did the most recent drawing operation leave the GPU in an acceptable state? |
1334 | void checkGPUStatus(); |
1335 | |
1336 | // Read rendering results into a pixel array with the same format as the |
1337 | // backbuffer. |
1338 | void readRenderingResults(unsigned char* pixels, int pixelsSize); |
1339 | void readPixelsAndConvertToBGRAIfNecessary(int x, int y, int width, int height, unsigned char* pixels); |
1340 | |
1341 | #if PLATFORM(IOS_FAMILY) |
1342 | void setRenderbufferStorageFromDrawable(GC3Dsizei width, GC3Dsizei height); |
1343 | #endif |
1344 | |
1345 | bool reshapeFBOs(const IntSize&); |
1346 | void resolveMultisamplingIfNecessary(const IntRect& = IntRect()); |
1347 | void attachDepthAndStencilBufferIfNeeded(GLuint internalDepthStencilFormat, int width, int height); |
1348 | |
1349 | #if PLATFORM(COCOA) |
1350 | bool allowOfflineRenderers() const; |
1351 | #endif |
1352 | |
1353 | int m_currentWidth { 0 }; |
1354 | int m_currentHeight { 0 }; |
1355 | |
1356 | #if PLATFORM(COCOA) |
1357 | RetainPtr<WebGLLayer> m_webGLLayer; |
1358 | PlatformGraphicsContext3D m_contextObj { nullptr }; |
1359 | #endif |
1360 | |
1361 | #if PLATFORM(WIN) && USE(CA) |
1362 | RefPtr<PlatformCALayer> m_webGLLayer; |
1363 | #endif |
1364 | |
1365 | typedef HashMap<String, sh::ShaderVariable> ShaderSymbolMap; |
1366 | |
1367 | struct ShaderSourceEntry { |
1368 | GC3Denum type; |
1369 | String source; |
1370 | String translatedSource; |
1371 | String log; |
1372 | bool isValid; |
1373 | ShaderSymbolMap attributeMap; |
1374 | ShaderSymbolMap uniformMap; |
1375 | ShaderSymbolMap varyingMap; |
1376 | ShaderSourceEntry() |
1377 | : type(VERTEX_SHADER) |
1378 | , isValid(false) |
1379 | { |
1380 | } |
1381 | |
1382 | ShaderSymbolMap& symbolMap(enum ANGLEShaderSymbolType symbolType) |
1383 | { |
1384 | ASSERT(symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE || symbolType == SHADER_SYMBOL_TYPE_UNIFORM || symbolType == SHADER_SYMBOL_TYPE_VARYING); |
1385 | if (symbolType == SHADER_SYMBOL_TYPE_ATTRIBUTE) |
1386 | return attributeMap; |
1387 | if (symbolType == SHADER_SYMBOL_TYPE_VARYING) |
1388 | return varyingMap; |
1389 | return uniformMap; |
1390 | } |
1391 | }; |
1392 | |
1393 | // FIXME: Shaders are never removed from this map, even if they and their program are deleted. |
1394 | // This is bad, and it also relies on the fact we never reuse Platform3DObject numbers. |
1395 | typedef HashMap<Platform3DObject, ShaderSourceEntry> ShaderSourceMap; |
1396 | ShaderSourceMap m_shaderSourceMap; |
1397 | |
1398 | typedef HashMap<Platform3DObject, std::pair<Platform3DObject, Platform3DObject>> LinkedShaderMap; |
1399 | LinkedShaderMap m_linkedShaderMap; |
1400 | |
1401 | struct ActiveShaderSymbolCounts { |
1402 | Vector<GC3Dint> filteredToActualAttributeIndexMap; |
1403 | Vector<GC3Dint> filteredToActualUniformIndexMap; |
1404 | |
1405 | ActiveShaderSymbolCounts() |
1406 | { |
1407 | } |
1408 | |
1409 | GC3Dint countForType(GC3Denum activeType) |
1410 | { |
1411 | ASSERT(activeType == ACTIVE_ATTRIBUTES || activeType == ACTIVE_UNIFORMS); |
1412 | if (activeType == ACTIVE_ATTRIBUTES) |
1413 | return filteredToActualAttributeIndexMap.size(); |
1414 | |
1415 | return filteredToActualUniformIndexMap.size(); |
1416 | } |
1417 | }; |
1418 | typedef HashMap<Platform3DObject, ActiveShaderSymbolCounts> ShaderProgramSymbolCountMap; |
1419 | ShaderProgramSymbolCountMap m_shaderProgramSymbolCountMap; |
1420 | |
1421 | typedef HashMap<String, String> HashedSymbolMap; |
1422 | HashedSymbolMap m_possiblyUnusedAttributeMap; |
1423 | |
1424 | String mappedSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name); |
1425 | String mappedSymbolName(Platform3DObject shaders[2], size_t count, const String& name); |
1426 | String originalSymbolName(Platform3DObject program, ANGLEShaderSymbolType, const String& name); |
1427 | Optional<String> mappedSymbolInShaderSourceMap(Platform3DObject shader, ANGLEShaderSymbolType, const String& name); |
1428 | Optional<String> originalSymbolInShaderSourceMap(Platform3DObject shader, ANGLEShaderSymbolType, const String& name); |
1429 | |
1430 | std::unique_ptr<ShaderNameHash> nameHashMapForShaders; |
1431 | |
1432 | #if !PLATFORM(COCOA) && USE(OPENGL_ES) |
1433 | friend class Extensions3DOpenGLES; |
1434 | std::unique_ptr<Extensions3DOpenGLES> m_extensions; |
1435 | #else |
1436 | friend class Extensions3DOpenGL; |
1437 | std::unique_ptr<Extensions3DOpenGL> m_extensions; |
1438 | #endif |
1439 | friend class Extensions3DOpenGLCommon; |
1440 | |
1441 | GraphicsContext3DAttributes m_attrs; |
1442 | GraphicsContext3DPowerPreference m_powerPreferenceUsedForCreation { GraphicsContext3DPowerPreference::Default }; |
1443 | RenderStyle m_renderStyle; |
1444 | Vector<Vector<float>> m_vertexArray; |
1445 | |
1446 | ANGLEWebKitBridge m_compiler; |
1447 | |
1448 | GC3Duint m_texture { 0 }; |
1449 | GC3Duint m_fbo { 0 }; |
1450 | #if USE(COORDINATED_GRAPHICS) |
1451 | GC3Duint m_compositorTexture { 0 }; |
1452 | GC3Duint m_intermediateTexture { 0 }; |
1453 | #endif |
1454 | |
1455 | GC3Duint m_depthBuffer { 0 }; |
1456 | GC3Duint m_stencilBuffer { 0 }; |
1457 | GC3Duint m_depthStencilBuffer { 0 }; |
1458 | |
1459 | bool m_layerComposited { false }; |
1460 | GC3Duint m_internalColorFormat { 0 }; |
1461 | |
1462 | struct GraphicsContext3DState { |
1463 | GC3Duint boundFBO { 0 }; |
1464 | GC3Denum activeTextureUnit { GraphicsContext3D::TEXTURE0 }; |
1465 | |
1466 | using BoundTextureMap = HashMap<GC3Denum, |
1467 | std::pair<GC3Duint, GC3Denum>, |
1468 | WTF::IntHash<GC3Denum>, |
1469 | WTF::UnsignedWithZeroKeyHashTraits<GC3Duint>, |
1470 | WTF::PairHashTraits<WTF::UnsignedWithZeroKeyHashTraits<GC3Duint>, WTF::UnsignedWithZeroKeyHashTraits<GC3Duint>> |
1471 | >; |
1472 | BoundTextureMap boundTextureMap; |
1473 | GC3Duint currentBoundTexture() const { return boundTexture(activeTextureUnit); } |
1474 | GC3Duint boundTexture(GC3Denum textureUnit) const |
1475 | { |
1476 | auto iterator = boundTextureMap.find(textureUnit); |
1477 | if (iterator != boundTextureMap.end()) |
1478 | return iterator->value.first; |
1479 | return 0; |
1480 | } |
1481 | |
1482 | GC3Duint currentBoundTarget() const { return boundTarget(activeTextureUnit); } |
1483 | GC3Denum boundTarget(GC3Denum textureUnit) const |
1484 | { |
1485 | auto iterator = boundTextureMap.find(textureUnit); |
1486 | if (iterator != boundTextureMap.end()) |
1487 | return iterator->value.second; |
1488 | return 0; |
1489 | } |
1490 | |
1491 | void setBoundTexture(GC3Denum textureUnit, GC3Duint texture, GC3Denum target) |
1492 | { |
1493 | boundTextureMap.set(textureUnit, std::make_pair(texture, target)); |
1494 | } |
1495 | |
1496 | using TextureSeedCount = HashCountedSet<GC3Duint, WTF::IntHash<GC3Duint>, WTF::UnsignedWithZeroKeyHashTraits<GC3Duint>>; |
1497 | TextureSeedCount textureSeedCount; |
1498 | }; |
1499 | |
1500 | GraphicsContext3DState m_state; |
1501 | |
1502 | // For multisampling |
1503 | GC3Duint m_multisampleFBO { 0 }; |
1504 | GC3Duint m_multisampleDepthStencilBuffer { 0 }; |
1505 | GC3Duint m_multisampleColorBuffer { 0 }; |
1506 | |
1507 | // Errors raised by synthesizeGLError(). |
1508 | ListHashSet<GC3Denum> m_syntheticErrors; |
1509 | |
1510 | #if USE(NICOSIA) && USE(TEXTURE_MAPPER) |
1511 | friend class Nicosia::GC3DLayer; |
1512 | std::unique_ptr<Nicosia::GC3DLayer> m_nicosiaLayer; |
1513 | #elif USE(TEXTURE_MAPPER) |
1514 | friend class TextureMapperGC3DPlatformLayer; |
1515 | std::unique_ptr<TextureMapperGC3DPlatformLayer> m_texmapLayer; |
1516 | #else |
1517 | friend class GraphicsContext3DPrivate; |
1518 | std::unique_ptr<GraphicsContext3DPrivate> m_private; |
1519 | #endif |
1520 | |
1521 | HashSet<Client*> m_clients; |
1522 | |
1523 | bool m_isForWebGL2 { false }; |
1524 | bool m_usingCoreProfile { false }; |
1525 | |
1526 | unsigned m_statusCheckCount { 0 }; |
1527 | bool m_failNextStatusCheck { false }; |
1528 | |
1529 | #if USE(CAIRO) |
1530 | Platform3DObject m_vao { 0 }; |
1531 | #endif |
1532 | |
1533 | #if PLATFORM(COCOA) && USE(OPENGL) |
1534 | bool m_hasSwitchedToHighPerformanceGPU { false }; |
1535 | #endif |
1536 | }; |
1537 | |
1538 | } // namespace WebCore |
1539 | |