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