Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
GrGLExtensions Class Reference

#include <GrGLExtensions.h>

Public Member Functions

 GrGLExtensions ()
 
 GrGLExtensions (const GrGLExtensions &)
 
GrGLExtensionsoperator= (const GrGLExtensions &)
 
void swap (GrGLExtensions *that)
 
bool init (GrGLStandard standard, GrGLFunction< GrGLGetStringFn > getString, GrGLFunction< GrGLGetStringiFn > getStringi, GrGLFunction< GrGLGetIntegervFn > getIntegerv, GrGLFunction< GrEGLQueryStringFn > queryString=nullptr, GrEGLDisplay eglDisplay=nullptr)
 
bool isInitialized () const
 
bool has (const char[]) const
 
bool remove (const char[])
 
void add (const char[])
 
void reset ()
 
void dumpJSON (SkJSONWriter *) const
 

Detailed Description

This helper queries the current GL context for its extensions, remembers them, and can be queried. It supports both glGetString- and glGetStringi-style extension string APIs and will use the latter if it is available. It also will query for EGL extensions if a eglQueryString implementation is provided.

Definition at line 26 of file GrGLExtensions.h.

Constructor & Destructor Documentation

◆ GrGLExtensions() [1/2]

GrGLExtensions::GrGLExtensions ( )
inline

Definition at line 28 of file GrGLExtensions.h.

28{}

◆ GrGLExtensions() [2/2]

GrGLExtensions::GrGLExtensions ( const GrGLExtensions that)

Definition at line 36 of file GrGLExtensions.cpp.

36 {
37 *this = that;
38}

Member Function Documentation

◆ add()

void GrGLExtensions::add ( const char  ext[])

Adds an extension to list

Definition at line 148 of file GrGLExtensions.cpp.

148 {
149 int idx = find_string(fStrings, ext);
150 if (idx < 0) {
151 // This is not the most effecient approach since we end up looking at all of the
152 // extensions after the add
153 fStrings.emplace_back(ext);
154 SkTInsertionSort(fStrings.begin(), fStrings.size(), extension_compare);
155 }
156}
static int find_string(const TArray< SkString > &strings, const char ext[])
void SkTInsertionSort(T *left, int count, const C &lessThan)
Definition: SkTSort.h:114
int size() const
Definition: SkTArray.h:421
T & emplace_back(Args &&... args)
Definition: SkTArray.h:248

◆ dumpJSON()

void GrGLExtensions::dumpJSON ( SkJSONWriter writer) const

Definition at line 169 of file GrGLExtensions.cpp.

169{ }

◆ has()

bool GrGLExtensions::has ( const char  ext[]) const

Queries whether an extension is present. This will fail if init() has not been called.

Definition at line 127 of file GrGLExtensions.cpp.

127 {
128 SkASSERT(fInitialized);
129 return find_string(fStrings, ext) >= 0;
130}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ init()

bool GrGLExtensions::init ( GrGLStandard  standard,
GrGLFunction< GrGLGetStringFn getString,
GrGLFunction< GrGLGetStringiFn getStringi,
GrGLFunction< GrGLGetIntegervFn getIntegerv,
GrGLFunction< GrEGLQueryStringFn queryString = nullptr,
GrEGLDisplay  eglDisplay = nullptr 
)

We sometimes need to use this class without having yet created a GrGLInterface. This version of init expects that getString is always non-NULL while getIntegerv and getStringi are non- NULL if on desktop GL with version 3.0 or higher. Otherwise it will fail.

Definition at line 68 of file GrGLExtensions.cpp.

73 {
74 fInitialized = false;
75 fStrings.clear();
76
77 if (!getString) {
78 return false;
79 }
80
81 const GrGLubyte* verString = getString(GR_GL_VERSION);
82 GrGLVersion version = GrGLGetVersionFromString((const char*) verString);
84 return false;
85 }
86
87 bool indexed = false;
88 if (GR_IS_GR_GL(standard) || GR_IS_GR_GL_ES(standard)) {
89 // glGetStringi and indexed extensions were added in version 3.0 of desktop GL and ES.
90 indexed = version >= GR_GL_VER(3, 0);
91 } else if (GR_IS_GR_WEBGL(standard)) {
92 // WebGL (1.0 or 2.0) doesn't natively support glGetStringi, but enscripten adds it in
93 // https://github.com/emscripten-core/emscripten/issues/3472
94 indexed = version >= GR_GL_VER(2, 0);
95 }
96
97 if (indexed) {
98 if (!getStringi || !getIntegerv) {
99 return false;
100 }
101 GrGLint extensionCnt = 0;
102 getIntegerv(GR_GL_NUM_EXTENSIONS, &extensionCnt);
103 fStrings.push_back_n(extensionCnt);
104 for (int i = 0; i < extensionCnt; ++i) {
105 const char* ext = (const char*) getStringi(GR_GL_EXTENSIONS, i);
106 fStrings[i] = ext;
107 }
108 } else {
109 const char* extensions = (const char*) getString(GR_GL_EXTENSIONS);
110 if (!extensions) {
111 return false;
112 }
114 }
115 if (queryString) {
116 const char* extensions = queryString(eglDisplay, GR_EGL_EXTENSIONS);
117
119 }
120 if (!fStrings.empty()) {
121 SkTQSort(fStrings.begin(), fStrings.end(), extension_compare);
122 }
123 fInitialized = true;
124 return true;
125}
#define GR_GL_NUM_EXTENSIONS
Definition: GrGLDefines.h:606
#define GR_EGL_EXTENSIONS
Definition: GrGLDefines.h:1117
#define GR_GL_EXTENSIONS
Definition: GrGLDefines.h:603
#define GR_GL_VERSION
Definition: GrGLDefines.h:602
static void eat_space_sep_strings(TArray< SkString > *out, const char in[])
#define GR_IS_GR_WEBGL(standard)
Definition: GrGLTypes.h:50
int GrGLint
Definition: GrGLTypes.h:108
unsigned char GrGLubyte
Definition: GrGLTypes.h:111
#define GR_IS_GR_GL(standard)
Definition: GrGLTypes.h:48
#define GR_IS_GR_GL_ES(standard)
Definition: GrGLTypes.h:49
GrGLVersion GrGLGetVersionFromString(const char *versionString)
Definition: GrGLUtil.cpp:68
#define GR_GL_INVALID_VER
Definition: GrGLUtil.h:37
#define GR_GL_VER(major, minor)
Definition: GrGLUtil.h:26
uint32_t GrGLVersion
Definition: GrGLUtil.h:22
void SkTQSort(T *begin, T *end, const C &lessThan)
Definition: SkTSort.h:194
T * push_back_n(int n)
Definition: SkTArray.h:267
bool empty() const
Definition: SkTArray.h:199

◆ isInitialized()

bool GrGLExtensions::isInitialized ( ) const
inline

Definition at line 52 of file GrGLExtensions.h.

52{ return fInitialized; }

◆ operator=()

GrGLExtensions & GrGLExtensions::operator= ( const GrGLExtensions that)

Definition at line 40 of file GrGLExtensions.cpp.

40 {
41 if (this != &that) {
42 fStrings = that.fStrings;
43 fInitialized = that.fInitialized;
44 }
45 return *this;
46}

◆ remove()

bool GrGLExtensions::remove ( const char  ext[])

Removes an extension if present. Returns true if the extension was present before the call.

Definition at line 132 of file GrGLExtensions.cpp.

132 {
133 SkASSERT(fInitialized);
134 int idx = find_string(fStrings, ext);
135 if (idx < 0) {
136 return false;
137 }
138
139 // This is not terribly effecient but we really only expect this function to be called at
140 // most a handful of times when our test programs start.
141 fStrings.removeShuffle(idx);
142 if (idx != fStrings.size()) {
143 SkTInsertionSort(fStrings.begin() + idx, fStrings.size() - idx, extension_compare);
144 }
145 return true;
146}
void removeShuffle(int n)
Definition: SkTArray.h:188

◆ reset()

void GrGLExtensions::reset ( )
inline

Definition at line 69 of file GrGLExtensions.h.

69{ fStrings.clear(); }

◆ swap()

void GrGLExtensions::swap ( GrGLExtensions that)
inline

Definition at line 34 of file GrGLExtensions.h.

34 {
35 using std::swap;
36 swap(fStrings, that->fStrings);
37 swap(fInitialized, that->fInitialized);
38 }
void swap(sk_sp< T > &a, sk_sp< T > &b)
Definition: SkRefCnt.h:341
void swap(GrGLExtensions *that)

The documentation for this class was generated from the following files: