forked from roytam1/UXP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGLContext.h
3728 lines (3161 loc) · 112 KB
/
GLContext.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GLCONTEXT_H_
#define GLCONTEXT_H_
#include <bitset>
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <map>
#include <queue>
#include <stack>
#ifdef DEBUG
#include <string.h>
#endif
#ifdef GetClassName
#undef GetClassName
#endif
// Define MOZ_GL_DEBUG unconditionally to enable GL debugging in opt
// builds.
#ifdef DEBUG
#define MOZ_GL_DEBUG 1
#endif
#include "../../mfbt/RefPtr.h"
#include "../../mfbt/UniquePtr.h"
#include "GLDefs.h"
#include "GLLibraryLoader.h"
#include "nsISupportsImpl.h"
#include "plstr.h"
#include "GLContextTypes.h"
#include "SurfaceTypes.h"
#include "GLContextSymbols.h"
#include "base/platform_thread.h" // for PlatformThreadId
#include "mozilla/GenericRefCounted.h"
#include "mozilla/WeakPtr.h"
#include "gfx2DGlue.h"
#include "GeckoProfiler.h"
class nsIWidget;
namespace android {
class GraphicBuffer;
} // namespace android
namespace mozilla {
namespace gfx {
class DataSourceSurface;
class SourceSurface;
} // namespace gfx
namespace gl {
class GLBlitHelper;
class GLBlitTextureImageHelper;
class GLContext;
class GLLibraryEGL;
class GLReadTexImageHelper;
class GLScreenBuffer;
class SharedSurface;
class TextureGarbageBin;
struct SurfaceCaps;
} // namespace gl
namespace layers {
class ColorTextureLayerProgram;
} // namespace layers
} // namespace mozilla
namespace mozilla {
namespace gl {
enum class GLFeature {
bind_buffer_offset,
blend_minmax,
clear_buffers,
copy_buffer,
depth_texture,
draw_buffers,
draw_instanced,
draw_range_elements,
element_index_uint,
ES2_compatibility,
ES3_compatibility,
EXT_color_buffer_float,
frag_color_float,
frag_depth,
framebuffer_blit,
framebuffer_multisample,
framebuffer_object,
framebuffer_object_EXT_OES,
get_integer_indexed,
get_integer64_indexed,
get_query_object_i64v,
get_query_object_iv,
get_string_indexed,
gpu_shader4,
gpu_shader5,
instanced_arrays,
instanced_non_arrays,
internalformat_query,
invalidate_framebuffer,
map_buffer_range,
occlusion_query,
occlusion_query_boolean,
occlusion_query2,
packed_depth_stencil,
prim_restart,
prim_restart_fixed,
query_counter,
query_objects,
query_time_elapsed,
read_buffer,
renderbuffer_color_float,
renderbuffer_color_half_float,
robustness,
sRGB_framebuffer,
sRGB_texture,
sampler_objects,
seamless_cube_map_opt_in,
shader_texture_lod,
split_framebuffer,
standard_derivatives,
sync,
texture_3D,
texture_3D_compressed,
texture_3D_copy,
texture_float,
texture_float_linear,
texture_half_float,
texture_half_float_linear,
texture_non_power_of_two,
texture_rg,
texture_storage,
texture_swizzle,
transform_feedback2,
uniform_buffer_object,
uniform_matrix_nonsquare,
vertex_array_object,
EnumMax
};
enum class ContextProfile : uint8_t {
Unknown = 0,
OpenGL, // only for IsAtLeast's <profile> parameter
OpenGLCore,
OpenGLCompatibility,
OpenGLES
};
enum class GLVendor {
Intel,
NVIDIA,
ATI,
Qualcomm,
Imagination,
Nouveau,
Vivante,
VMware,
ARM,
Other
};
enum class GLRenderer {
Adreno200,
Adreno205,
AdrenoTM200,
AdrenoTM205,
AdrenoTM305,
AdrenoTM320,
AdrenoTM330,
AdrenoTM420,
Mali400MP,
Mali450MP,
SGX530,
SGX540,
SGX544MP,
Tegra,
AndroidEmulator,
GalliumLlvmpipe,
IntelHD3000,
MicrosoftBasicRenderDriver,
Other
};
class GLContext
: public GLLibraryLoader
, public GenericAtomicRefCounted
, public SupportsWeakPtr<GLContext>
{
public:
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(GLContext)
// -----------------------------------------------------------------------------
// basic enums
public:
// -----------------------------------------------------------------------------
// basic getters
public:
/**
* Returns true if the context is using ANGLE. This should only be overridden
* for an ANGLE implementation.
*/
virtual bool IsANGLE() const {
return false;
}
/**
* Returns true if the context is using WARP. This should only be overridden
* for an ANGLE implementation.
*/
virtual bool IsWARP() const {
return false;
}
virtual void GetWSIInfo(nsCString* const out) const = 0;
/**
* Return true if we are running on a OpenGL core profile context
*/
inline bool IsCoreProfile() const {
MOZ_ASSERT(mProfile != ContextProfile::Unknown, "unknown context profile");
return mProfile == ContextProfile::OpenGLCore;
}
/**
* Return true if we are running on a OpenGL compatibility profile context
* (legacy profile 2.1 on Max OS X)
*/
inline bool IsCompatibilityProfile() const {
MOZ_ASSERT(mProfile != ContextProfile::Unknown, "unknown context profile");
return mProfile == ContextProfile::OpenGLCompatibility;
}
/**
* Return true if the context is a true OpenGL ES context or an ANGLE context
*/
inline bool IsGLES() const {
MOZ_ASSERT(mProfile != ContextProfile::Unknown, "unknown context profile");
return mProfile == ContextProfile::OpenGLES;
}
static const char* GetProfileName(ContextProfile profile)
{
switch (profile)
{
case ContextProfile::OpenGL:
return "OpenGL";
case ContextProfile::OpenGLCore:
return "OpenGL Core";
case ContextProfile::OpenGLCompatibility:
return "OpenGL Compatibility";
case ContextProfile::OpenGLES:
return "OpenGL ES";
default:
break;
}
MOZ_ASSERT(profile != ContextProfile::Unknown, "unknown context profile");
return "OpenGL unknown profile";
}
/**
* Return true if we are running on a OpenGL core profile context
*/
const char* ProfileString() const {
return GetProfileName(mProfile);
}
/**
* Return true if the context is compatible with given parameters
*
* IsAtLeast(ContextProfile::OpenGL, N) is exactly same as
* IsAtLeast(ContextProfile::OpenGLCore, N) || IsAtLeast(ContextProfile::OpenGLCompatibility, N)
*/
inline bool IsAtLeast(ContextProfile profile, unsigned int version) const
{
MOZ_ASSERT(profile != ContextProfile::Unknown, "IsAtLeast: bad <profile> parameter");
MOZ_ASSERT(mProfile != ContextProfile::Unknown, "unknown context profile");
MOZ_ASSERT(mVersion != 0, "unknown context version");
if (version > mVersion) {
return false;
}
if (profile == ContextProfile::OpenGL) {
return mProfile == ContextProfile::OpenGLCore ||
mProfile == ContextProfile::OpenGLCompatibility;
}
return profile == mProfile;
}
/**
* Return the version of the context.
* Example :
* If this a OpenGL 2.1, that will return 210
*/
inline uint32_t Version() const {
return mVersion;
}
const char* VersionString() const {
return mVersionString.get();
}
inline uint32_t ShadingLanguageVersion() const {
return mShadingLanguageVersion;
}
GLVendor Vendor() const {
return mVendor;
}
GLRenderer Renderer() const {
return mRenderer;
}
bool IsContextLost() const {
return mContextLost;
}
/**
* If this context is double-buffered, returns TRUE.
*/
virtual bool IsDoubleBuffered() const {
return false;
}
virtual GLContextType GetContextType() const = 0;
virtual bool IsCurrent() = 0;
/**
* Get the default framebuffer for this context.
*/
virtual GLuint GetDefaultFramebuffer() {
return 0;
}
protected:
bool mIsOffscreen;
bool mContextLost;
bool mIsDestroyed = false;
/**
* mVersion store the OpenGL's version, multiplied by 100. For example, if
* the context is an OpenGL 2.1 context, mVersion value will be 210.
*/
uint32_t mVersion;
nsCString mVersionString;
ContextProfile mProfile;
uint32_t mShadingLanguageVersion;
GLVendor mVendor;
GLRenderer mRenderer;
void SetProfileVersion(ContextProfile profile, uint32_t version) {
MOZ_ASSERT(!mSymbols.fBindFramebuffer,
"SetProfileVersion can only be called before initialization!");
MOZ_ASSERT(profile != ContextProfile::Unknown &&
profile != ContextProfile::OpenGL,
"Invalid `profile` for SetProfileVersion");
MOZ_ASSERT(version >= 100, "Invalid `version` for SetProfileVersion");
mVersion = version;
mProfile = profile;
}
// -----------------------------------------------------------------------------
// Extensions management
/**
* This mechanism is designed to know if an extension is supported. In the long
* term, we would like to only use the extension group queries XXX_* to have
* full compatibility with context version and profiles (especialy the core that
* officialy don't bring any extensions).
*/
public:
/**
* Known GL extensions that can be queried by
* IsExtensionSupported. The results of this are cached, and as
* such it's safe to use this even in performance critical code.
* If you add to this array, remember to add to the string names
* in GLContext.cpp.
*/
enum GLExtensions {
Extension_None = 0,
AMD_compressed_ATC_texture,
ANGLE_depth_texture,
ANGLE_framebuffer_blit,
ANGLE_framebuffer_multisample,
ANGLE_instanced_arrays,
ANGLE_texture_compression_dxt3,
ANGLE_texture_compression_dxt5,
ANGLE_timer_query,
APPLE_client_storage,
APPLE_framebuffer_multisample,
APPLE_sync,
APPLE_texture_range,
APPLE_vertex_array_object,
ARB_ES2_compatibility,
ARB_ES3_compatibility,
ARB_color_buffer_float,
ARB_copy_buffer,
ARB_depth_texture,
ARB_draw_buffers,
ARB_draw_instanced,
ARB_framebuffer_object,
ARB_framebuffer_sRGB,
ARB_geometry_shader4,
ARB_gpu_shader5,
ARB_half_float_pixel,
ARB_instanced_arrays,
ARB_internalformat_query,
ARB_invalidate_subdata,
ARB_map_buffer_range,
ARB_occlusion_query2,
ARB_pixel_buffer_object,
ARB_robustness,
ARB_sampler_objects,
ARB_seamless_cube_map,
ARB_shader_texture_lod,
ARB_sync,
ARB_texture_compression,
ARB_texture_float,
ARB_texture_non_power_of_two,
ARB_texture_rectangle,
ARB_texture_rg,
ARB_texture_storage,
ARB_texture_swizzle,
ARB_timer_query,
ARB_transform_feedback2,
ARB_uniform_buffer_object,
ARB_vertex_array_object,
EXT_bgra,
EXT_blend_minmax,
EXT_color_buffer_float,
EXT_color_buffer_half_float,
EXT_copy_texture,
EXT_disjoint_timer_query,
EXT_draw_buffers,
EXT_draw_buffers2,
EXT_draw_instanced,
EXT_draw_range_elements,
EXT_frag_depth,
EXT_framebuffer_blit,
EXT_framebuffer_multisample,
EXT_framebuffer_object,
EXT_framebuffer_sRGB,
EXT_gpu_shader4,
EXT_gpu_shader5,
EXT_multisampled_render_to_texture,
EXT_occlusion_query_boolean,
EXT_packed_depth_stencil,
EXT_read_format_bgra,
EXT_robustness,
EXT_sRGB,
EXT_sRGB_write_control,
EXT_shader_texture_lod,
EXT_texture3D,
EXT_texture_compression_dxt1,
EXT_texture_compression_s3tc,
EXT_texture_filter_anisotropic,
EXT_texture_format_BGRA8888,
EXT_texture_sRGB,
EXT_texture_storage,
EXT_timer_query,
EXT_transform_feedback,
EXT_unpack_subimage,
IMG_read_format,
IMG_texture_compression_pvrtc,
IMG_texture_npot,
KHR_debug,
NV_draw_instanced,
NV_fence,
NV_framebuffer_blit,
NV_geometry_program4,
NV_gpu_shader5,
NV_half_float,
NV_instanced_arrays,
NV_primitive_restart,
NV_texture_barrier,
NV_transform_feedback,
NV_transform_feedback2,
OES_EGL_image,
OES_EGL_image_external,
OES_EGL_sync,
OES_compressed_ETC1_RGB8_texture,
OES_depth24,
OES_depth32,
OES_depth_texture,
OES_element_index_uint,
OES_framebuffer_object,
OES_packed_depth_stencil,
OES_rgb8_rgba8,
OES_standard_derivatives,
OES_stencil8,
OES_texture_3D,
OES_texture_float,
OES_texture_float_linear,
OES_texture_half_float,
OES_texture_half_float_linear,
OES_texture_npot,
OES_vertex_array_object,
Extensions_Max,
Extensions_End
};
bool IsExtensionSupported(GLExtensions aKnownExtension) const {
return mAvailableExtensions[aKnownExtension];
}
protected:
void MarkExtensionUnsupported(GLExtensions aKnownExtension) {
mAvailableExtensions[aKnownExtension] = 0;
}
void MarkExtensionSupported(GLExtensions aKnownExtension) {
mAvailableExtensions[aKnownExtension] = 1;
}
std::bitset<Extensions_Max> mAvailableExtensions;
// -----------------------------------------------------------------------------
// Feature queries
/*
* This mecahnism introduces a new way to check if a OpenGL feature is
* supported, regardless of whether it is supported by an extension or natively
* by the context version/profile
*/
public:
bool IsSupported(GLFeature feature) const {
return mAvailableFeatures[size_t(feature)];
}
static const char* GetFeatureName(GLFeature feature);
private:
std::bitset<size_t(GLFeature::EnumMax)> mAvailableFeatures;
/**
* Init features regarding OpenGL extension and context version and profile
*/
void InitFeatures();
/**
* Mark the feature and associated extensions as unsupported
*/
void MarkUnsupported(GLFeature feature);
/**
* Is this feature supported using the core (unsuffixed) symbols?
*/
bool IsFeatureProvidedByCoreSymbols(GLFeature feature);
// -----------------------------------------------------------------------------
// Robustness handling
private:
/**
* The derived class is expected to provide information on whether or not it
* supports robustness.
*/
virtual bool SupportsRobustness() const = 0;
public:
// -----------------------------------------------------------------------------
// Error handling
static const char* GLErrorToString(GLenum aError) {
switch (aError) {
case LOCAL_GL_INVALID_ENUM:
return "GL_INVALID_ENUM";
case LOCAL_GL_INVALID_VALUE:
return "GL_INVALID_VALUE";
case LOCAL_GL_INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case LOCAL_GL_STACK_OVERFLOW:
return "GL_STACK_OVERFLOW";
case LOCAL_GL_STACK_UNDERFLOW:
return "GL_STACK_UNDERFLOW";
case LOCAL_GL_OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
case LOCAL_GL_TABLE_TOO_LARGE:
return "GL_TABLE_TOO_LARGE";
case LOCAL_GL_INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION";
default:
return "";
}
}
private:
GLenum mTopError;
GLenum RawGetError() {
return mSymbols.fGetError();
}
GLenum RawGetErrorAndClear() {
GLenum err = RawGetError();
if (err)
while (RawGetError()) {}
return err;
}
public:
GLenum FlushErrors() {
GLenum err = RawGetErrorAndClear();
if (!mTopError)
mTopError = err;
return err;
}
// We smash all errors together, so you never have to loop on this. We
// guarantee that immediately after this call, there are no errors left.
GLenum fGetError() {
FlushErrors();
GLenum err = mTopError;
mTopError = LOCAL_GL_NO_ERROR;
return err;
}
////////////////////////////////////
// Use this safer option.
class LocalErrorScope;
private:
std::stack<const LocalErrorScope*> mLocalErrorScopeStack;
public:
class LocalErrorScope {
GLContext& mGL;
GLenum mOldTop;
bool mHasBeenChecked;
public:
explicit LocalErrorScope(GLContext& gl)
: mGL(gl)
, mHasBeenChecked(false)
{
mGL.mLocalErrorScopeStack.push(this);
mGL.FlushErrors();
mOldTop = mGL.mTopError;
mGL.mTopError = LOCAL_GL_NO_ERROR;
}
GLenum GetError() {
MOZ_ASSERT(!mHasBeenChecked);
mHasBeenChecked = true;
const GLenum ret = mGL.fGetError();
while (mGL.fGetError()) {}
return ret;
}
~LocalErrorScope() {
MOZ_ASSERT(mHasBeenChecked);
MOZ_ASSERT(mGL.fGetError() == LOCAL_GL_NO_ERROR);
MOZ_ASSERT(mGL.mLocalErrorScopeStack.top() == this);
mGL.mLocalErrorScopeStack.pop();
mGL.mTopError = mOldTop;
}
};
bool GetPotentialInteger(GLenum pname, GLint* param) {
LocalErrorScope localError(*this);
fGetIntegerv(pname, param);
GLenum err = localError.GetError();
MOZ_ASSERT_IF(err != LOCAL_GL_NO_ERROR, err == LOCAL_GL_INVALID_ENUM);
return err == LOCAL_GL_NO_ERROR;
}
private:
static void GLAPIENTRY StaticDebugCallback(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const GLvoid* userParam);
void DebugCallback(GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message);
// -----------------------------------------------------------------------------
// MOZ_GL_DEBUG implementation
private:
#undef BEFORE_GL_CALL
#undef AFTER_GL_CALL
#ifdef MOZ_GL_DEBUG
#ifndef MOZ_FUNCTION_NAME
# ifdef __GNUC__
# define MOZ_FUNCTION_NAME __PRETTY_FUNCTION__
# elif defined(_MSC_VER)
# define MOZ_FUNCTION_NAME __FUNCTION__
# else
# define MOZ_FUNCTION_NAME __func__ // defined in C99, supported in various C++ compilers. Just raw function name.
# endif
#endif
void BeforeGLCall(const char* funcName) {
MOZ_ASSERT(IsCurrent());
if (mDebugFlags) {
FlushErrors();
if (mDebugFlags & DebugFlagTrace) {
printf_stderr("[gl:%p] > %s\n", this, funcName);
}
GLContext* tlsContext = (GLContext*)PR_GetThreadPrivate(sCurrentGLContextTLS);
if (this != tlsContext) {
printf_stderr("Fatal: %s called on non-current context %p. The"
" current context for this thread is %p.\n",
funcName, this, tlsContext);
MOZ_CRASH("GFX: GLContext is not current.");
}
}
}
void AfterGLCall(const char* funcName) {
if (mDebugFlags) {
// calling fFinish() immediately after every GL call makes sure that if this GL command crashes,
// the stack trace will actually point to it. Otherwise, OpenGL being an asynchronous API, stack traces
// tend to be meaningless
mSymbols.fFinish();
GLenum err = FlushErrors();
if (mDebugFlags & DebugFlagTrace) {
printf_stderr("[gl:%p] < %s [%s (0x%04x)]\n", this, funcName,
GLErrorToString(err), err);
}
if (err != LOCAL_GL_NO_ERROR &&
!mLocalErrorScopeStack.size())
{
printf_stderr("[gl:%p] %s: Generated unexpected %s error."
" (0x%04x)\n", this, funcName,
GLErrorToString(err), err);
if (mDebugFlags & DebugFlagAbortOnError) {
MOZ_CRASH("Unexpected error with MOZ_GL_DEBUG_ABORT_ON_ERROR. (Run"
" with MOZ_GL_DEBUG_ABORT_ON_ERROR=0 to disable)");
}
}
}
}
GLContext* TrackingContext()
{
GLContext* tip = this;
while (tip->mSharedContext)
tip = tip->mSharedContext;
return tip;
}
static void AssertNotPassingStackBufferToTheGL(const void* ptr);
#define BEFORE_GL_CALL \
do { \
BeforeGLCall(MOZ_FUNCTION_NAME); \
} while (0)
#define AFTER_GL_CALL \
do { \
AfterGLCall(MOZ_FUNCTION_NAME); \
} while (0)
#define TRACKING_CONTEXT(a) \
do { \
TrackingContext()->a; \
} while (0)
#define ASSERT_NOT_PASSING_STACK_BUFFER_TO_GL(ptr) AssertNotPassingStackBufferToTheGL(ptr)
#else // ifdef MOZ_GL_DEBUG
#define BEFORE_GL_CALL do { } while (0)
#define AFTER_GL_CALL do { } while (0)
#define TRACKING_CONTEXT(a) do {} while (0)
#define ASSERT_NOT_PASSING_STACK_BUFFER_TO_GL(ptr) do {} while (0)
#endif // ifdef MOZ_GL_DEBUG
#define ASSERT_SYMBOL_PRESENT(func) \
do {\
MOZ_ASSERT(strstr(MOZ_FUNCTION_NAME, #func) != nullptr, "Mismatched symbol check.");\
if (MOZ_UNLIKELY(!mSymbols.func)) {\
printf_stderr("RUNTIME ASSERT: Uninitialized GL function: %s\n", #func);\
MOZ_CRASH("GFX: Uninitialized GL function");\
}\
} while (0)
// Do whatever setup is necessary to draw to our offscreen FBO, if it's
// bound.
void BeforeGLDrawCall() { }
// Do whatever tear-down is necessary after drawing to our offscreen FBO,
// if it's bound.
void AfterGLDrawCall();
// Do whatever setup is necessary to read from our offscreen FBO, if it's
// bound.
void BeforeGLReadCall();
// Do whatever tear-down is necessary after reading from our offscreen FBO,
// if it's bound.
void AfterGLReadCall() { }
// -----------------------------------------------------------------------------
// GL official entry points
public:
void fActiveTexture(GLenum texture) {
BEFORE_GL_CALL;
mSymbols.fActiveTexture(texture);
AFTER_GL_CALL;
}
void fAttachShader(GLuint program, GLuint shader) {
BEFORE_GL_CALL;
mSymbols.fAttachShader(program, shader);
AFTER_GL_CALL;
}
void fBeginQuery(GLenum target, GLuint id) {
BEFORE_GL_CALL;
ASSERT_SYMBOL_PRESENT(fBeginQuery);
mSymbols.fBeginQuery(target, id);
AFTER_GL_CALL;
}
void fBindAttribLocation(GLuint program, GLuint index, const GLchar* name) {
BEFORE_GL_CALL;
mSymbols.fBindAttribLocation(program, index, name);
AFTER_GL_CALL;
}
void fBindBuffer(GLenum target, GLuint buffer) {
BEFORE_GL_CALL;
mSymbols.fBindBuffer(target, buffer);
AFTER_GL_CALL;
}
void fBindFramebuffer(GLenum target, GLuint framebuffer);
void fInvalidateFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments) {
BeforeGLDrawCall();
BEFORE_GL_CALL;
ASSERT_SYMBOL_PRESENT(fInvalidateFramebuffer);
mSymbols.fInvalidateFramebuffer(target, numAttachments, attachments);
AFTER_GL_CALL;
AfterGLDrawCall();
}
void fInvalidateSubFramebuffer(GLenum target, GLsizei numAttachments, const GLenum* attachments, GLint x, GLint y, GLsizei width, GLsizei height) {
BeforeGLDrawCall();
BEFORE_GL_CALL;
ASSERT_SYMBOL_PRESENT(fInvalidateSubFramebuffer);
mSymbols.fInvalidateSubFramebuffer(target, numAttachments, attachments, x, y, width, height);
AFTER_GL_CALL;
AfterGLDrawCall();
}
void fBindTexture(GLenum target, GLuint texture) {
BEFORE_GL_CALL;
mSymbols.fBindTexture(target, texture);
AFTER_GL_CALL;
}
void fBlendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) {
BEFORE_GL_CALL;
mSymbols.fBlendColor(red, green, blue, alpha);
AFTER_GL_CALL;
}
void fBlendEquation(GLenum mode) {
BEFORE_GL_CALL;
mSymbols.fBlendEquation(mode);
AFTER_GL_CALL;
}
void fBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) {
BEFORE_GL_CALL;
mSymbols.fBlendEquationSeparate(modeRGB, modeAlpha);
AFTER_GL_CALL;
}
void fBlendFunc(GLenum sfactor, GLenum dfactor) {
BEFORE_GL_CALL;
mSymbols.fBlendFunc(sfactor, dfactor);
AFTER_GL_CALL;
}
void fBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha) {
BEFORE_GL_CALL;
mSymbols.fBlendFuncSeparate(sfactorRGB, dfactorRGB, sfactorAlpha, dfactorAlpha);
AFTER_GL_CALL;
}
private:
void raw_fBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage) {
ASSERT_NOT_PASSING_STACK_BUFFER_TO_GL(data);
BEFORE_GL_CALL;
mSymbols.fBufferData(target, size, data, usage);
AFTER_GL_CALL;
mHeavyGLCallsSinceLastFlush = true;
}
public:
void fBufferData(GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage) {
raw_fBufferData(target, size, data, usage);
// bug 744888
if (WorkAroundDriverBugs() &&
!data &&
Vendor() == GLVendor::NVIDIA)
{
UniquePtr<char[]> buf = MakeUnique<char[]>(1);
buf[0] = 0;
fBufferSubData(target, size-1, 1, buf.get());
}
}
void fBufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid* data) {
ASSERT_NOT_PASSING_STACK_BUFFER_TO_GL(data);
BEFORE_GL_CALL;
mSymbols.fBufferSubData(target, offset, size, data);
AFTER_GL_CALL;
mHeavyGLCallsSinceLastFlush = true;
}
private:
void raw_fClear(GLbitfield mask) {
BEFORE_GL_CALL;
mSymbols.fClear(mask);
AFTER_GL_CALL;
}
public:
void fClear(GLbitfield mask) {
BeforeGLDrawCall();
raw_fClear(mask);
AfterGLDrawCall();
}
void fClearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) {
BeforeGLDrawCall();
BEFORE_GL_CALL;
mSymbols.fClearBufferfi(buffer, drawbuffer, depth, stencil);
AFTER_GL_CALL;
AfterGLDrawCall();
}
void fClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat* value) {
BeforeGLDrawCall();
BEFORE_GL_CALL;
mSymbols.fClearBufferfv(buffer, drawbuffer, value);
AFTER_GL_CALL;
AfterGLDrawCall();
}
void fClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint* value) {
BeforeGLDrawCall();
BEFORE_GL_CALL;
mSymbols.fClearBufferiv(buffer, drawbuffer, value);
AFTER_GL_CALL;