• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright 2015 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 
9 #ifndef GrGLTypes_DEFINED
10 #define GrGLTypes_DEFINED
11 
12 #include "include/core/SkRefCnt.h"
13 #include "include/gpu/gl/GrGLConfig.h"
14 
15 /**
16  * Classifies GL contexts by which standard they implement (currently as OpenGL vs. OpenGL ES).
17  */
18 enum GrGLStandard {
19     kNone_GrGLStandard,
20     kGL_GrGLStandard,
21     kGLES_GrGLStandard,
22     kWebGL_GrGLStandard,
23 };
24 static const int kGrGLStandardCnt = 4;
25 
26 // The following allow certain interfaces to be turned off at compile time
27 // (for example, to lower code size).
28 #if SK_ASSUME_GL_ES
29     #define GR_IS_GR_GL(standard) false
30     #define GR_IS_GR_GL_ES(standard) true
31     #define GR_IS_GR_WEBGL(standard) false
32     #define SK_DISABLE_GL_INTERFACE 1
33     #define SK_DISABLE_WEBGL_INTERFACE 1
34 #elif SK_ASSUME_GL
35     #define GR_IS_GR_GL(standard) true
36     #define GR_IS_GR_GL_ES(standard) false
37     #define GR_IS_GR_WEBGL(standard) false
38     #define SK_DISABLE_GL_ES_INTERFACE 1
39     #define SK_DISABLE_WEBGL_INTERFACE 1
40 #elif SK_ASSUME_WEBGL
41     #define GR_IS_GR_GL(standard) false
42     #define GR_IS_GR_GL_ES(standard) false
43     #define GR_IS_GR_WEBGL(standard) true
44     #define SK_DISABLE_GL_ES_INTERFACE 1
45     #define SK_DISABLE_GL_INTERFACE 1
46 #else
47     #define GR_IS_GR_GL(standard) (kGL_GrGLStandard == standard)
48     #define GR_IS_GR_GL_ES(standard) (kGLES_GrGLStandard == standard)
49     #define GR_IS_GR_WEBGL(standard) (kWebGL_GrGLStandard == standard)
50 #endif
51 
52 ///////////////////////////////////////////////////////////////////////////////
53 
54 /**
55  * The supported GL formats represented as an enum. Actual support by GrContext depends on GL
56  * context version and extensions.
57  */
58 enum class GrGLFormat {
59     kUnknown,
60 
61     kRGBA8,
62     kR8,
63     kALPHA8,
64     kLUMINANCE8,
65     kLUMINANCE8_ALPHA8,
66     kBGRA8,
67     kRGB565,
68     kRGBA16F,
69     kR16F,
70     kRGB8,
71     kRG8,
72     kRGB10_A2,
73     kRGBA4,
74     kSRGB8_ALPHA8,
75     kCOMPRESSED_ETC1_RGB8,
76     kCOMPRESSED_RGB8_ETC2,
77     kCOMPRESSED_RGB8_BC1,
78     kCOMPRESSED_RGBA8_BC1,
79     kCOMPRESSED_ASTC_RGBA8_4x4,
80     kCOMPRESSED_ASTC_RGBA8_6x6,
81     kCOMPRESSED_ASTC_RGBA8_8x8,
82     kR16,
83     kRG16,
84     kRGBA16,
85     kRG16F,
86     kLUMINANCE16F,
87 
88     kLastColorFormat = kLUMINANCE16F,
89 
90     // Depth/Stencil formats
91     kSTENCIL_INDEX8,
92     kSTENCIL_INDEX16,
93     kDEPTH24_STENCIL8,
94 
95     kLast = kDEPTH24_STENCIL8
96 };
97 
98 ///////////////////////////////////////////////////////////////////////////////
99 /**
100  * Declares typedefs for all the GL functions used in GrGLInterface
101  */
102 
103 typedef unsigned int GrGLenum;
104 typedef unsigned char GrGLboolean;
105 typedef unsigned int GrGLbitfield;
106 typedef signed char GrGLbyte;
107 typedef char GrGLchar;
108 typedef short GrGLshort;
109 typedef int GrGLint;
110 typedef int GrGLsizei;
111 typedef int64_t GrGLint64;
112 typedef unsigned char GrGLubyte;
113 typedef unsigned short GrGLushort;
114 typedef unsigned int GrGLuint;
115 typedef uint64_t GrGLuint64;
116 typedef unsigned short int GrGLhalf;
117 typedef float GrGLfloat;
118 typedef float GrGLclampf;
119 typedef double GrGLdouble;
120 typedef double GrGLclampd;
121 typedef void GrGLvoid;
122 #ifdef _WIN64
123 typedef signed long long int GrGLintptr;
124 typedef signed long long int GrGLsizeiptr;
125 #else
126 typedef signed long int GrGLintptr;
127 typedef signed long int GrGLsizeiptr;
128 #endif
129 typedef void* GrGLeglImage;
130 typedef struct __GLsync* GrGLsync;
131 
132 struct GrGLDrawArraysIndirectCommand {
133     GrGLuint fCount;
134     GrGLuint fInstanceCount;
135     GrGLuint fFirst;
136     GrGLuint fBaseInstance;  // Requires EXT_base_instance on ES.
137 };
138 
139 // static_asserts must have messages in this file because its included in C++14 client code.
140 static_assert(16 == sizeof(GrGLDrawArraysIndirectCommand), "");
141 
142 struct GrGLDrawElementsIndirectCommand {
143     GrGLuint fCount;
144     GrGLuint fInstanceCount;
145     GrGLuint fFirstIndex;
146     GrGLuint fBaseVertex;
147     GrGLuint fBaseInstance;  // Requires EXT_base_instance on ES.
148 };
149 
150 static_assert(20 == sizeof(GrGLDrawElementsIndirectCommand), "");
151 
152 /**
153  * KHR_debug
154  */
155 typedef void (GR_GL_FUNCTION_TYPE* GRGLDEBUGPROC)(GrGLenum source,
156                                                   GrGLenum type,
157                                                   GrGLuint id,
158                                                   GrGLenum severity,
159                                                   GrGLsizei length,
160                                                   const GrGLchar* message,
161                                                   const void* userParam);
162 
163 /**
164  * EGL types.
165  */
166 typedef void* GrEGLImage;
167 typedef void* GrEGLDisplay;
168 typedef void* GrEGLContext;
169 typedef void* GrEGLClientBuffer;
170 typedef unsigned int GrEGLenum;
171 typedef int32_t GrEGLint;
172 typedef unsigned int GrEGLBoolean;
173 
174 ///////////////////////////////////////////////////////////////////////////////
175 /**
176  * Types for interacting with GL resources created externally to Skia. GrBackendObjects for GL
177  * textures are really const GrGLTexture*. The fFormat here should be a sized, internal format
178  * for the texture. We will try to use the sized format if the GL Context supports it, otherwise
179  * we will internally fall back to using the base internal formats.
180  */
181 struct GrGLTextureInfo {
182     GrGLenum fTarget;
183     GrGLuint fID;
184     GrGLenum fFormat = 0;
185 
186     bool operator==(const GrGLTextureInfo& that) const {
187         return fTarget == that.fTarget && fID == that.fID && fFormat == that.fFormat;
188     }
189 };
190 
191 struct GrGLFramebufferInfo {
192     GrGLuint fFBOID;
193     GrGLenum fFormat = 0;
194 
195     bool operator==(const GrGLFramebufferInfo& that) const {
196         return fFBOID == that.fFBOID && fFormat == that.fFormat;
197     }
198 };
199 
200 struct GrGLSurfaceInfo {
201     uint32_t fSampleCount = 1;
202     uint32_t fLevelCount = 0;
203     GrProtected fProtected = GrProtected::kNo;
204 
205     GrGLenum fTarget = 0;
206     GrGLenum fFormat = 0;
207 };
208 
209 #endif
210