reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkPixmap.h" |
| 9 | #include "include/core/SkStrokeRec.h" |
| 10 | #include "include/core/SkTypes.h" |
| 11 | #include "include/gpu/GrBackendSemaphore.h" |
| 12 | #include "include/gpu/GrBackendSurface.h" |
| 13 | #include "include/gpu/GrTypes.h" |
| 14 | #include "include/private/SkHalf.h" |
| 15 | #include "include/private/SkTemplates.h" |
| 16 | #include "include/private/SkTo.h" |
| 17 | #include "src/core/SkAutoMalloc.h" |
| 18 | #include "src/core/SkConvertPixels.h" |
| 19 | #include "src/core/SkMakeUnique.h" |
| 20 | #include "src/core/SkMipMap.h" |
| 21 | #include "src/core/SkTraceEvent.h" |
Brian Osman | 8518f2e | 2019-05-01 14:13:41 -0400 | [diff] [blame] | 22 | #include "src/gpu/GrContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/GrCpuBuffer.h" |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 24 | #include "src/gpu/GrDataUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/GrFixedClip.h" |
| 26 | #include "src/gpu/GrGpuResourcePriv.h" |
| 27 | #include "src/gpu/GrMesh.h" |
| 28 | #include "src/gpu/GrPipeline.h" |
| 29 | #include "src/gpu/GrRenderTargetPriv.h" |
| 30 | #include "src/gpu/GrShaderCaps.h" |
| 31 | #include "src/gpu/GrSurfaceProxyPriv.h" |
| 32 | #include "src/gpu/GrTexturePriv.h" |
| 33 | #include "src/gpu/gl/GrGLBuffer.h" |
| 34 | #include "src/gpu/gl/GrGLGpu.h" |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 35 | #include "src/gpu/gl/GrGLOpsRenderPass.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 36 | #include "src/gpu/gl/GrGLSemaphore.h" |
| 37 | #include "src/gpu/gl/GrGLStencilAttachment.h" |
| 38 | #include "src/gpu/gl/GrGLTextureRenderTarget.h" |
| 39 | #include "src/gpu/gl/builders/GrGLShaderStringBuilder.h" |
| 40 | #include "src/sksl/SkSLCompiler.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 41 | |
Hal Canary | c640d0d | 2018-06-13 09:59:02 -0400 | [diff] [blame] | 42 | #include <cmath> |
| 43 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 44 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 45 | #define GL_CALL_RET(RET, X) GR_GL_CALL_RET(this->glInterface(), RET, X) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 46 | |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 47 | #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
| 48 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
| 49 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
| 50 | #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 51 | #else |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 52 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) |
| 53 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) |
| 54 | #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR |
| 55 | #endif |
| 56 | |
Jim Van Verth | 32ac83e | 2016-11-28 15:23:57 -0500 | [diff] [blame] | 57 | //#define USE_NSIGHT |
| 58 | |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 59 | /////////////////////////////////////////////////////////////////////////////// |
| 60 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 61 | static const GrGLenum gXfermodeEquation2Blend[] = { |
| 62 | // Basic OpenGL blend equations. |
| 63 | GR_GL_FUNC_ADD, |
| 64 | GR_GL_FUNC_SUBTRACT, |
| 65 | GR_GL_FUNC_REVERSE_SUBTRACT, |
| 66 | |
| 67 | // GL_KHR_blend_equation_advanced. |
| 68 | GR_GL_SCREEN, |
| 69 | GR_GL_OVERLAY, |
| 70 | GR_GL_DARKEN, |
| 71 | GR_GL_LIGHTEN, |
| 72 | GR_GL_COLORDODGE, |
| 73 | GR_GL_COLORBURN, |
| 74 | GR_GL_HARDLIGHT, |
| 75 | GR_GL_SOFTLIGHT, |
| 76 | GR_GL_DIFFERENCE, |
| 77 | GR_GL_EXCLUSION, |
| 78 | GR_GL_MULTIPLY, |
| 79 | GR_GL_HSL_HUE, |
| 80 | GR_GL_HSL_SATURATION, |
| 81 | GR_GL_HSL_COLOR, |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 82 | GR_GL_HSL_LUMINOSITY, |
| 83 | |
| 84 | // Illegal... needs to map to something. |
| 85 | GR_GL_FUNC_ADD, |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 86 | }; |
| 87 | GR_STATIC_ASSERT(0 == kAdd_GrBlendEquation); |
| 88 | GR_STATIC_ASSERT(1 == kSubtract_GrBlendEquation); |
| 89 | GR_STATIC_ASSERT(2 == kReverseSubtract_GrBlendEquation); |
| 90 | GR_STATIC_ASSERT(3 == kScreen_GrBlendEquation); |
| 91 | GR_STATIC_ASSERT(4 == kOverlay_GrBlendEquation); |
| 92 | GR_STATIC_ASSERT(5 == kDarken_GrBlendEquation); |
| 93 | GR_STATIC_ASSERT(6 == kLighten_GrBlendEquation); |
| 94 | GR_STATIC_ASSERT(7 == kColorDodge_GrBlendEquation); |
| 95 | GR_STATIC_ASSERT(8 == kColorBurn_GrBlendEquation); |
| 96 | GR_STATIC_ASSERT(9 == kHardLight_GrBlendEquation); |
| 97 | GR_STATIC_ASSERT(10 == kSoftLight_GrBlendEquation); |
| 98 | GR_STATIC_ASSERT(11 == kDifference_GrBlendEquation); |
| 99 | GR_STATIC_ASSERT(12 == kExclusion_GrBlendEquation); |
| 100 | GR_STATIC_ASSERT(13 == kMultiply_GrBlendEquation); |
| 101 | GR_STATIC_ASSERT(14 == kHSLHue_GrBlendEquation); |
| 102 | GR_STATIC_ASSERT(15 == kHSLSaturation_GrBlendEquation); |
| 103 | GR_STATIC_ASSERT(16 == kHSLColor_GrBlendEquation); |
| 104 | GR_STATIC_ASSERT(17 == kHSLLuminosity_GrBlendEquation); |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 105 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gXfermodeEquation2Blend) == kGrBlendEquationCnt); |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 106 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 107 | static const GrGLenum gXfermodeCoeff2Blend[] = { |
| 108 | GR_GL_ZERO, |
| 109 | GR_GL_ONE, |
| 110 | GR_GL_SRC_COLOR, |
| 111 | GR_GL_ONE_MINUS_SRC_COLOR, |
| 112 | GR_GL_DST_COLOR, |
| 113 | GR_GL_ONE_MINUS_DST_COLOR, |
| 114 | GR_GL_SRC_ALPHA, |
| 115 | GR_GL_ONE_MINUS_SRC_ALPHA, |
| 116 | GR_GL_DST_ALPHA, |
| 117 | GR_GL_ONE_MINUS_DST_ALPHA, |
| 118 | GR_GL_CONSTANT_COLOR, |
| 119 | GR_GL_ONE_MINUS_CONSTANT_COLOR, |
| 120 | GR_GL_CONSTANT_ALPHA, |
| 121 | GR_GL_ONE_MINUS_CONSTANT_ALPHA, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 122 | |
| 123 | // extended blend coeffs |
| 124 | GR_GL_SRC1_COLOR, |
| 125 | GR_GL_ONE_MINUS_SRC1_COLOR, |
| 126 | GR_GL_SRC1_ALPHA, |
| 127 | GR_GL_ONE_MINUS_SRC1_ALPHA, |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 128 | |
| 129 | // Illegal... needs to map to something. |
| 130 | GR_GL_ZERO, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 133 | bool GrGLGpu::BlendCoeffReferencesConstant(GrBlendCoeff coeff) { |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 134 | static const bool gCoeffReferencesBlendConst[] = { |
| 135 | false, |
| 136 | false, |
| 137 | false, |
| 138 | false, |
| 139 | false, |
| 140 | false, |
| 141 | false, |
| 142 | false, |
| 143 | false, |
| 144 | false, |
| 145 | true, |
| 146 | true, |
| 147 | true, |
| 148 | true, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 149 | |
| 150 | // extended blend coeffs |
| 151 | false, |
| 152 | false, |
| 153 | false, |
| 154 | false, |
Mike Klein | 3674336 | 2018-11-06 08:23:30 -0500 | [diff] [blame] | 155 | |
| 156 | // Illegal. |
| 157 | false, |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 158 | }; |
| 159 | return gCoeffReferencesBlendConst[coeff]; |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 160 | GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendConst)); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 161 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 162 | GR_STATIC_ASSERT(0 == kZero_GrBlendCoeff); |
| 163 | GR_STATIC_ASSERT(1 == kOne_GrBlendCoeff); |
| 164 | GR_STATIC_ASSERT(2 == kSC_GrBlendCoeff); |
| 165 | GR_STATIC_ASSERT(3 == kISC_GrBlendCoeff); |
| 166 | GR_STATIC_ASSERT(4 == kDC_GrBlendCoeff); |
| 167 | GR_STATIC_ASSERT(5 == kIDC_GrBlendCoeff); |
| 168 | GR_STATIC_ASSERT(6 == kSA_GrBlendCoeff); |
| 169 | GR_STATIC_ASSERT(7 == kISA_GrBlendCoeff); |
| 170 | GR_STATIC_ASSERT(8 == kDA_GrBlendCoeff); |
| 171 | GR_STATIC_ASSERT(9 == kIDA_GrBlendCoeff); |
| 172 | GR_STATIC_ASSERT(10 == kConstC_GrBlendCoeff); |
| 173 | GR_STATIC_ASSERT(11 == kIConstC_GrBlendCoeff); |
| 174 | GR_STATIC_ASSERT(12 == kConstA_GrBlendCoeff); |
| 175 | GR_STATIC_ASSERT(13 == kIConstA_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 176 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 177 | GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff); |
| 178 | GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); |
| 179 | GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); |
| 180 | GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 181 | |
| 182 | // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 183 | GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 186 | ////////////////////////////////////////////////////////////////////////////// |
| 187 | |
| 188 | static int gl_target_to_binding_index(GrGLenum target) { |
| 189 | switch (target) { |
| 190 | case GR_GL_TEXTURE_2D: |
| 191 | return 0; |
| 192 | case GR_GL_TEXTURE_RECTANGLE: |
| 193 | return 1; |
| 194 | case GR_GL_TEXTURE_EXTERNAL: |
| 195 | return 2; |
| 196 | } |
| 197 | SK_ABORT("Unexpected GL texture target."); |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | GrGpuResource::UniqueID GrGLGpu::TextureUnitBindings::boundID(GrGLenum target) const { |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 201 | return fTargetBindings[gl_target_to_binding_index(target)].fBoundResourceID; |
| 202 | } |
| 203 | |
| 204 | bool GrGLGpu::TextureUnitBindings::hasBeenModified(GrGLenum target) const { |
| 205 | return fTargetBindings[gl_target_to_binding_index(target)].fHasBeenModified; |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void GrGLGpu::TextureUnitBindings::setBoundID(GrGLenum target, GrGpuResource::UniqueID resourceID) { |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 209 | int targetIndex = gl_target_to_binding_index(target); |
| 210 | fTargetBindings[targetIndex].fBoundResourceID = resourceID; |
| 211 | fTargetBindings[targetIndex].fHasBeenModified = true; |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 212 | } |
| 213 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 214 | void GrGLGpu::TextureUnitBindings::invalidateForScratchUse(GrGLenum target) { |
| 215 | this->setBoundID(target, GrGpuResource::UniqueID()); |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 216 | } |
| 217 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 218 | void GrGLGpu::TextureUnitBindings::invalidateAllTargets(bool markUnmodified) { |
| 219 | for (auto& targetBinding : fTargetBindings) { |
| 220 | targetBinding.fBoundResourceID.makeInvalid(); |
| 221 | if (markUnmodified) { |
| 222 | targetBinding.fHasBeenModified = false; |
| 223 | } |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 224 | } |
| 225 | } |
| 226 | |
| 227 | ////////////////////////////////////////////////////////////////////////////// |
| 228 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 229 | static GrGLenum filter_to_gl_mag_filter(GrSamplerState::Filter filter) { |
| 230 | switch (filter) { |
| 231 | case GrSamplerState::Filter::kNearest: return GR_GL_NEAREST; |
| 232 | case GrSamplerState::Filter::kBilerp: return GR_GL_LINEAR; |
| 233 | case GrSamplerState::Filter::kMipMap: return GR_GL_LINEAR; |
| 234 | } |
| 235 | SK_ABORT("Unknown filter"); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static GrGLenum filter_to_gl_min_filter(GrSamplerState::Filter filter) { |
| 239 | switch (filter) { |
| 240 | case GrSamplerState::Filter::kNearest: return GR_GL_NEAREST; |
| 241 | case GrSamplerState::Filter::kBilerp: return GR_GL_LINEAR; |
| 242 | case GrSamplerState::Filter::kMipMap: return GR_GL_LINEAR_MIPMAP_LINEAR; |
| 243 | } |
| 244 | SK_ABORT("Unknown filter"); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 247 | static inline GrGLenum wrap_mode_to_gl_wrap(GrSamplerState::WrapMode wrapMode, |
| 248 | const GrCaps& caps) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 249 | switch (wrapMode) { |
| 250 | case GrSamplerState::WrapMode::kClamp: return GR_GL_CLAMP_TO_EDGE; |
| 251 | case GrSamplerState::WrapMode::kRepeat: return GR_GL_REPEAT; |
| 252 | case GrSamplerState::WrapMode::kMirrorRepeat: return GR_GL_MIRRORED_REPEAT; |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 253 | case GrSamplerState::WrapMode::kClampToBorder: |
| 254 | // May not be supported but should have been caught earlier |
| 255 | SkASSERT(caps.clampToBorderSupport()); |
| 256 | return GR_GL_CLAMP_TO_BORDER; |
Brian Salomon | 2335644 | 2018-11-30 15:33:19 -0500 | [diff] [blame] | 257 | } |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 258 | SK_ABORT("Unknown wrap mode"); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /////////////////////////////////////////////////////////////////////////////// |
| 262 | |
| 263 | class GrGLGpu::SamplerObjectCache { |
| 264 | public: |
| 265 | SamplerObjectCache(GrGLGpu* gpu) : fGpu(gpu) { |
| 266 | fNumTextureUnits = fGpu->glCaps().shaderCaps()->maxFragmentSamplers(); |
| 267 | fHWBoundSamplers.reset(new GrGLuint[fNumTextureUnits]); |
| 268 | std::fill_n(fHWBoundSamplers.get(), fNumTextureUnits, 0); |
| 269 | std::fill_n(fSamplers, kNumSamplers, 0); |
| 270 | } |
| 271 | |
| 272 | ~SamplerObjectCache() { |
| 273 | if (!fNumTextureUnits) { |
| 274 | // We've already been abandoned. |
| 275 | return; |
| 276 | } |
Chris Dalton | 703fe68 | 2019-05-15 12:58:12 -0600 | [diff] [blame] | 277 | for (GrGLuint sampler : fSamplers) { |
| 278 | // The spec states that "zero" values should be silently ignored, however they still |
| 279 | // trigger GL errors on some NVIDIA platforms. |
| 280 | if (sampler) { |
| 281 | GR_GL_CALL(fGpu->glInterface(), DeleteSamplers(1, &sampler)); |
| 282 | } |
| 283 | } |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | void bindSampler(int unitIdx, const GrSamplerState& state) { |
| 287 | int index = StateToIndex(state); |
| 288 | if (!fSamplers[index]) { |
| 289 | GrGLuint s; |
| 290 | GR_GL_CALL(fGpu->glInterface(), GenSamplers(1, &s)); |
| 291 | if (!s) { |
| 292 | return; |
| 293 | } |
| 294 | fSamplers[index] = s; |
| 295 | auto minFilter = filter_to_gl_min_filter(state.filter()); |
| 296 | auto magFilter = filter_to_gl_mag_filter(state.filter()); |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 297 | auto wrapX = wrap_mode_to_gl_wrap(state.wrapModeX(), fGpu->glCaps()); |
| 298 | auto wrapY = wrap_mode_to_gl_wrap(state.wrapModeY(), fGpu->glCaps()); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 299 | GR_GL_CALL(fGpu->glInterface(), |
| 300 | SamplerParameteri(s, GR_GL_TEXTURE_MIN_FILTER, minFilter)); |
| 301 | GR_GL_CALL(fGpu->glInterface(), |
| 302 | SamplerParameteri(s, GR_GL_TEXTURE_MAG_FILTER, magFilter)); |
| 303 | GR_GL_CALL(fGpu->glInterface(), SamplerParameteri(s, GR_GL_TEXTURE_WRAP_S, wrapX)); |
| 304 | GR_GL_CALL(fGpu->glInterface(), SamplerParameteri(s, GR_GL_TEXTURE_WRAP_T, wrapY)); |
| 305 | } |
| 306 | if (fHWBoundSamplers[unitIdx] != fSamplers[index]) { |
| 307 | GR_GL_CALL(fGpu->glInterface(), BindSampler(unitIdx, fSamplers[index])); |
| 308 | fHWBoundSamplers[unitIdx] = fSamplers[index]; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | void invalidateBindings() { |
| 313 | // When we have sampler support we always use samplers. So setting these to zero will cause |
| 314 | // a rebind on next usage. |
| 315 | std::fill_n(fHWBoundSamplers.get(), fNumTextureUnits, 0); |
| 316 | } |
| 317 | |
| 318 | void abandon() { |
| 319 | fHWBoundSamplers.reset(); |
| 320 | fNumTextureUnits = 0; |
| 321 | } |
| 322 | |
| 323 | void release() { |
| 324 | if (!fNumTextureUnits) { |
| 325 | // We've already been abandoned. |
| 326 | return; |
| 327 | } |
| 328 | GR_GL_CALL(fGpu->glInterface(), DeleteSamplers(kNumSamplers, fSamplers)); |
| 329 | std::fill_n(fSamplers, kNumSamplers, 0); |
| 330 | // Deleting a bound sampler implicitly binds sampler 0. |
| 331 | std::fill_n(fHWBoundSamplers.get(), fNumTextureUnits, 0); |
| 332 | } |
| 333 | |
| 334 | private: |
| 335 | static int StateToIndex(const GrSamplerState& state) { |
| 336 | int filter = static_cast<int>(state.filter()); |
| 337 | SkASSERT(filter >= 0 && filter < 3); |
| 338 | int wrapX = static_cast<int>(state.wrapModeX()); |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 339 | SkASSERT(wrapX >= 0 && wrapX < 4); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 340 | int wrapY = static_cast<int>(state.wrapModeY()); |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 341 | SkASSERT(wrapY >= 0 && wrapY < 4); |
| 342 | int idx = 16 * filter + 4 * wrapX + wrapY; |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 343 | SkASSERT(idx < kNumSamplers); |
| 344 | return idx; |
| 345 | } |
| 346 | |
| 347 | GrGLGpu* fGpu; |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 348 | static constexpr int kNumSamplers = 48; |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 349 | std::unique_ptr<GrGLuint[]> fHWBoundSamplers; |
| 350 | GrGLuint fSamplers[kNumSamplers]; |
| 351 | int fNumTextureUnits; |
| 352 | }; |
| 353 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 354 | /////////////////////////////////////////////////////////////////////////////// |
| 355 | |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 356 | sk_sp<GrGpu> GrGLGpu::Make(sk_sp<const GrGLInterface> interface, const GrContextOptions& options, |
| 357 | GrContext* context) { |
| 358 | if (!interface) { |
Brian Salomon | 3d6801e | 2017-12-11 10:06:31 -0500 | [diff] [blame] | 359 | interface = GrGLMakeNativeInterface(); |
| 360 | // For clients that have written their own GrGLCreateNativeInterface and haven't yet updated |
| 361 | // to GrGLMakeNativeInterface. |
| 362 | if (!interface) { |
| 363 | interface = sk_ref_sp(GrGLCreateNativeInterface()); |
| 364 | } |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 365 | if (!interface) { |
| 366 | return nullptr; |
| 367 | } |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 368 | } |
Jim Van Verth | 7633477 | 2017-05-05 16:46:05 -0400 | [diff] [blame] | 369 | #ifdef USE_NSIGHT |
| 370 | const_cast<GrContextOptions&>(options).fSuppressPathRendering = true; |
| 371 | #endif |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 372 | auto glContext = GrGLContext::Make(std::move(interface), options); |
| 373 | if (!glContext) { |
| 374 | return nullptr; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 375 | } |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 376 | return sk_sp<GrGpu>(new GrGLGpu(std::move(glContext), context)); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 379 | GrGLGpu::GrGLGpu(std::unique_ptr<GrGLContext> ctx, GrContext* context) |
| 380 | : GrGpu(context) |
| 381 | , fGLContext(std::move(ctx)) |
| 382 | , fProgramCache(new ProgramCache(this)) |
| 383 | , fHWProgramID(0) |
| 384 | , fTempSrcFBOID(0) |
| 385 | , fTempDstFBOID(0) |
Brian Osman | a63593a | 2018-12-06 15:54:53 -0500 | [diff] [blame] | 386 | , fStencilClearFBOID(0) { |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 387 | SkASSERT(fGLContext); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 388 | GrGLClearErr(this->glInterface()); |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 389 | fCaps = sk_ref_sp(fGLContext->caps()); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 390 | |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 391 | fHWTextureUnitBindings.reset(this->numTextureUnits()); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 392 | |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 393 | this->hwBufferState(GrGpuBufferType::kVertex)->fGLTarget = GR_GL_ARRAY_BUFFER; |
| 394 | this->hwBufferState(GrGpuBufferType::kIndex)->fGLTarget = GR_GL_ELEMENT_ARRAY_BUFFER; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 395 | if (GrGLCaps::kChromium_TransferBufferType == this->glCaps().transferBufferType()) { |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 396 | this->hwBufferState(GrGpuBufferType::kXferCpuToGpu)->fGLTarget = |
| 397 | GR_GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM; |
| 398 | this->hwBufferState(GrGpuBufferType::kXferGpuToCpu)->fGLTarget = |
| 399 | GR_GL_PIXEL_PACK_TRANSFER_BUFFER_CHROMIUM; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 400 | } else { |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 401 | this->hwBufferState(GrGpuBufferType::kXferCpuToGpu)->fGLTarget = GR_GL_PIXEL_UNPACK_BUFFER; |
| 402 | this->hwBufferState(GrGpuBufferType::kXferGpuToCpu)->fGLTarget = GR_GL_PIXEL_PACK_BUFFER; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 403 | } |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 404 | for (int i = 0; i < kGrGpuBufferTypeCount; ++i) { |
Rob Phillips | bc534f6 | 2017-09-05 19:56:19 -0400 | [diff] [blame] | 405 | fHWBufferState[i].invalidate(); |
| 406 | } |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 407 | GR_STATIC_ASSERT(4 == SK_ARRAY_COUNT(fHWBufferState)); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 408 | |
| 409 | if (this->glCaps().shaderCaps()->pathRenderingSupport()) { |
| 410 | fPathRendering.reset(new GrGLPathRendering(this)); |
| 411 | } |
| 412 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 413 | if (this->glCaps().samplerObjectSupport()) { |
| 414 | fSamplerObjectCache.reset(new SamplerObjectCache(this)); |
| 415 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 416 | } |
| 417 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 418 | GrGLGpu::~GrGLGpu() { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 419 | // Ensure any GrGpuResource objects get deleted first, since they may require a working GrGLGpu |
| 420 | // to release the resources held by the objects themselves. |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 421 | fPathRendering.reset(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 422 | fCopyProgramArrayBuffer.reset(); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 423 | fMipmapProgramArrayBuffer.reset(); |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 424 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 425 | fHWProgram.reset(); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 426 | if (fHWProgramID) { |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 427 | // detach the current program so there is no confusion on OpenGL's part |
| 428 | // that we want it to be deleted |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 429 | GL_CALL(UseProgram(0)); |
| 430 | } |
| 431 | |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 432 | if (fTempSrcFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 433 | this->deleteFramebuffer(fTempSrcFBOID); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 434 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 435 | if (fTempDstFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 436 | this->deleteFramebuffer(fTempDstFBOID); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 437 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 438 | if (fStencilClearFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 439 | this->deleteFramebuffer(fStencilClearFBOID); |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 440 | } |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 441 | |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 442 | for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
| 443 | if (0 != fCopyPrograms[i].fProgram) { |
| 444 | GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram)); |
| 445 | } |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 446 | } |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 447 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 448 | for (size_t i = 0; i < SK_ARRAY_COUNT(fMipmapPrograms); ++i) { |
| 449 | if (0 != fMipmapPrograms[i].fProgram) { |
| 450 | GL_CALL(DeleteProgram(fMipmapPrograms[i].fProgram)); |
| 451 | } |
| 452 | } |
| 453 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 454 | delete fProgramCache; |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 455 | fSamplerObjectCache.reset(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 456 | } |
| 457 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 458 | void GrGLGpu::disconnect(DisconnectType type) { |
| 459 | INHERITED::disconnect(type); |
| 460 | if (DisconnectType::kCleanup == type) { |
| 461 | if (fHWProgramID) { |
| 462 | GL_CALL(UseProgram(0)); |
| 463 | } |
| 464 | if (fTempSrcFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 465 | this->deleteFramebuffer(fTempSrcFBOID); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 466 | } |
| 467 | if (fTempDstFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 468 | this->deleteFramebuffer(fTempDstFBOID); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 469 | } |
| 470 | if (fStencilClearFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 471 | this->deleteFramebuffer(fStencilClearFBOID); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 472 | } |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 473 | for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
| 474 | if (fCopyPrograms[i].fProgram) { |
| 475 | GL_CALL(DeleteProgram(fCopyPrograms[i].fProgram)); |
| 476 | } |
| 477 | } |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 478 | for (size_t i = 0; i < SK_ARRAY_COUNT(fMipmapPrograms); ++i) { |
| 479 | if (fMipmapPrograms[i].fProgram) { |
| 480 | GL_CALL(DeleteProgram(fMipmapPrograms[i].fProgram)); |
| 481 | } |
| 482 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 483 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 484 | if (fSamplerObjectCache) { |
| 485 | fSamplerObjectCache->release(); |
| 486 | } |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 487 | } else { |
| 488 | if (fProgramCache) { |
| 489 | fProgramCache->abandon(); |
| 490 | } |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 491 | if (fSamplerObjectCache) { |
| 492 | fSamplerObjectCache->abandon(); |
| 493 | } |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 496 | fHWProgram.reset(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 497 | delete fProgramCache; |
| 498 | fProgramCache = nullptr; |
| 499 | |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 500 | fHWProgramID = 0; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 501 | fTempSrcFBOID = 0; |
| 502 | fTempDstFBOID = 0; |
| 503 | fStencilClearFBOID = 0; |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 504 | fCopyProgramArrayBuffer.reset(); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 505 | for (size_t i = 0; i < SK_ARRAY_COUNT(fCopyPrograms); ++i) { |
| 506 | fCopyPrograms[i].fProgram = 0; |
| 507 | } |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 508 | fMipmapProgramArrayBuffer.reset(); |
| 509 | for (size_t i = 0; i < SK_ARRAY_COUNT(fMipmapPrograms); ++i) { |
| 510 | fMipmapPrograms[i].fProgram = 0; |
| 511 | } |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 512 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 513 | if (this->glCaps().shaderCaps()->pathRenderingSupport()) { |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 514 | this->glPathRendering()->disconnect(type); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 515 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 516 | } |
| 517 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 518 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 519 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 520 | void GrGLGpu::onResetContext(uint32_t resetBits) { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 521 | if (resetBits & kMisc_GrGLBackendState) { |
Brian Salomon | f086167 | 2017-05-08 11:10:10 -0400 | [diff] [blame] | 522 | // we don't use the zb at all |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 523 | GL_CALL(Disable(GR_GL_DEPTH_TEST)); |
| 524 | GL_CALL(DepthMask(GR_GL_FALSE)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 525 | |
Brian Salomon | f086167 | 2017-05-08 11:10:10 -0400 | [diff] [blame] | 526 | // We don't use face culling. |
| 527 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 528 | // We do use separate stencil. Our algorithms don't care which face is front vs. back so |
| 529 | // just set this to the default for self-consistency. |
| 530 | GL_CALL(FrontFace(GR_GL_CCW)); |
Brian Salomon | f086167 | 2017-05-08 11:10:10 -0400 | [diff] [blame] | 531 | |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 532 | this->hwBufferState(GrGpuBufferType::kXferCpuToGpu)->invalidate(); |
| 533 | this->hwBufferState(GrGpuBufferType::kXferGpuToCpu)->invalidate(); |
cdalton | c161310 | 2016-03-16 07:48:20 -0700 | [diff] [blame] | 534 | |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 535 | if (GR_IS_GR_GL(this->glStandard())) { |
Jim Van Verth | 32ac83e | 2016-11-28 15:23:57 -0500 | [diff] [blame] | 536 | #ifndef USE_NSIGHT |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 537 | // Desktop-only state that we never change |
| 538 | if (!this->glCaps().isCoreProfile()) { |
| 539 | GL_CALL(Disable(GR_GL_POINT_SMOOTH)); |
| 540 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 541 | GL_CALL(Disable(GR_GL_POLYGON_SMOOTH)); |
| 542 | GL_CALL(Disable(GR_GL_POLYGON_STIPPLE)); |
| 543 | GL_CALL(Disable(GR_GL_COLOR_LOGIC_OP)); |
| 544 | GL_CALL(Disable(GR_GL_INDEX_LOGIC_OP)); |
| 545 | } |
| 546 | // The windows NVIDIA driver has GL_ARB_imaging in the extension string when using a |
| 547 | // core profile. This seems like a bug since the core spec removes any mention of |
| 548 | // GL_ARB_imaging. |
| 549 | if (this->glCaps().imagingSupport() && !this->glCaps().isCoreProfile()) { |
| 550 | GL_CALL(Disable(GR_GL_COLOR_TABLE)); |
| 551 | } |
| 552 | GL_CALL(Disable(GR_GL_POLYGON_OFFSET_FILL)); |
Jim Van Verth | 609e7cc | 2017-03-30 14:28:08 -0400 | [diff] [blame] | 553 | |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 554 | if (this->caps()->wireframeMode()) { |
| 555 | GL_CALL(PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_LINE)); |
| 556 | } else { |
| 557 | GL_CALL(PolygonMode(GR_GL_FRONT_AND_BACK, GR_GL_FILL)); |
| 558 | } |
Jim Van Verth | 32ac83e | 2016-11-28 15:23:57 -0500 | [diff] [blame] | 559 | #endif |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 560 | // Since ES doesn't support glPointSize at all we always use the VS to |
| 561 | // set the point size |
| 562 | GL_CALL(Enable(GR_GL_VERTEX_PROGRAM_POINT_SIZE)); |
| 563 | |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 564 | } |
joshualitt | 5816233 | 2014-08-01 06:44:53 -0700 | [diff] [blame] | 565 | |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 566 | if (GR_IS_GR_GL_ES(this->glStandard()) && |
Brian Salomon | 8bc352c | 2019-01-28 09:05:22 -0500 | [diff] [blame] | 567 | this->glCaps().fbFetchRequiresEnablePerSample()) { |
joshualitt | 5816233 | 2014-08-01 06:44:53 -0700 | [diff] [blame] | 568 | // The arm extension requires specifically enabling MSAA fetching per sample. |
| 569 | // On some devices this may have a perf hit. Also multiple render targets are disabled |
Brian Salomon | 8bc352c | 2019-01-28 09:05:22 -0500 | [diff] [blame] | 570 | GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE)); |
joshualitt | 5816233 | 2014-08-01 06:44:53 -0700 | [diff] [blame] | 571 | } |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 572 | fHWWriteToColor = kUnknown_TriState; |
| 573 | // we only ever use lines in hairline mode |
| 574 | GL_CALL(LineWidth(1)); |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 575 | GL_CALL(Disable(GR_GL_DITHER)); |
Brian Salomon | 805cc7a | 2019-01-28 09:52:34 -0500 | [diff] [blame] | 576 | |
| 577 | fHWClearColor[0] = fHWClearColor[1] = fHWClearColor[2] = fHWClearColor[3] = SK_FloatNaN; |
bsalomon@google.com | cad107b | 2013-06-28 14:32:08 +0000 | [diff] [blame] | 578 | } |
edisonn@google.com | ba66999 | 2013-06-28 16:03:21 +0000 | [diff] [blame] | 579 | |
egdaniel | b414f25 | 2014-07-29 13:15:47 -0700 | [diff] [blame] | 580 | if (resetBits & kMSAAEnable_GrGLBackendState) { |
| 581 | fMSAAEnabled = kUnknown_TriState; |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 582 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 583 | if (this->caps()->mixedSamplesSupport()) { |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 584 | // The skia blend modes all use premultiplied alpha and therefore expect RGBA coverage |
| 585 | // modulation. This state has no effect when not rendering to a mixed sampled target. |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 586 | GL_CALL(CoverageModulation(GR_GL_RGBA)); |
| 587 | } |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 588 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 589 | |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 590 | fHWActiveTextureUnitIdx = -1; // invalid |
Brian Salomon | af971de | 2017-06-08 16:11:33 -0400 | [diff] [blame] | 591 | fLastPrimitiveType = static_cast<GrPrimitiveType>(-1); |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 592 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 593 | if (resetBits & kTextureBinding_GrGLBackendState) { |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 594 | for (int s = 0; s < this->numTextureUnits(); ++s) { |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 595 | fHWTextureUnitBindings[s].invalidateAllTargets(false); |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 596 | } |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 597 | if (fSamplerObjectCache) { |
| 598 | fSamplerObjectCache->invalidateBindings(); |
| 599 | } |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 600 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 601 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 602 | if (resetBits & kBlend_GrGLBackendState) { |
| 603 | fHWBlendState.invalidate(); |
| 604 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 605 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 606 | if (resetBits & kView_GrGLBackendState) { |
| 607 | fHWScissorSettings.invalidate(); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 608 | fHWWindowRectsState.invalidate(); |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 609 | fHWViewport.invalidate(); |
| 610 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 611 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 612 | if (resetBits & kStencil_GrGLBackendState) { |
| 613 | fHWStencilSettings.invalidate(); |
| 614 | fHWStencilTestEnabled = kUnknown_TriState; |
| 615 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 616 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 617 | // Vertex |
| 618 | if (resetBits & kVertex_GrGLBackendState) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 619 | fHWVertexArrayState.invalidate(); |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 620 | this->hwBufferState(GrGpuBufferType::kVertex)->invalidate(); |
| 621 | this->hwBufferState(GrGpuBufferType::kIndex)->invalidate(); |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 622 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 623 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 624 | if (resetBits & kRenderTarget_GrGLBackendState) { |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 625 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
bsalomon | 16921ec | 2015-07-30 15:34:56 -0700 | [diff] [blame] | 626 | fHWSRGBFramebuffer = kUnknown_TriState; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 627 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 628 | |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 629 | if (resetBits & kPathRendering_GrGLBackendState) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 630 | if (this->caps()->shaderCaps()->pathRenderingSupport()) { |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 631 | this->glPathRendering()->resetContext(); |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 632 | } |
bsalomon@google.com | 05a718c | 2012-06-29 14:01:53 +0000 | [diff] [blame] | 633 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 634 | |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 635 | // we assume these values |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 636 | if (resetBits & kPixelStore_GrGLBackendState) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 637 | if (this->caps()->writePixelsRowBytesSupport()) { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 638 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 639 | } |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 640 | if (this->glCaps().readPixelsRowBytesSupport()) { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 641 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 642 | } |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 643 | if (this->glCaps().packFlipYSupport()) { |
| 644 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, GR_GL_FALSE)); |
| 645 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 646 | } |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 647 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 648 | if (resetBits & kProgram_GrGLBackendState) { |
| 649 | fHWProgramID = 0; |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 650 | fHWProgram.reset(); |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 651 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 652 | ++fResetTimestampForTextureParameters; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 655 | static bool check_backend_texture(const GrBackendTexture& backendTex, const GrColorType colorType, |
| 656 | const GrGLCaps& caps, GrGLTexture::Desc* desc, |
| 657 | bool skipRectTexSupportCheck = false) { |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 658 | GrGLTextureInfo info; |
Robert Phillips | 1cd1ed8 | 2019-07-23 13:21:01 -0400 | [diff] [blame] | 659 | if (!backendTex.getGLTextureInfo(&info) || !info.fID || !info.fFormat) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 660 | return false; |
bsalomon | 091f60c | 2015-11-10 11:54:56 -0800 | [diff] [blame] | 661 | } |
robertphillips@google.com | b72e5d3 | 2012-10-30 15:18:10 +0000 | [diff] [blame] | 662 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 663 | desc->fSize = {backendTex.width(), backendTex.height()}; |
| 664 | desc->fTarget = info.fTarget; |
| 665 | desc->fID = info.fID; |
| 666 | desc->fFormat = GrGLFormatFromGLEnum(info.fFormat); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 667 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 668 | if (desc->fFormat == GrGLFormat::kUnknown) { |
| 669 | return false; |
| 670 | } |
| 671 | if (GR_GL_TEXTURE_EXTERNAL == desc->fTarget) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 672 | if (!caps.shaderCaps()->externalTextureSupport()) { |
| 673 | return false; |
| 674 | } |
Brian Salomon | f04fb44 | 2019-08-08 16:06:29 -0400 | [diff] [blame] | 675 | } else if (GR_GL_TEXTURE_RECTANGLE == desc->fTarget) { |
| 676 | if (!caps.rectangleTextureSupport() && !skipRectTexSupportCheck) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 677 | return false; |
| 678 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 679 | } else if (GR_GL_TEXTURE_2D != desc->fTarget) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 680 | return false; |
| 681 | } |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 682 | if (backendTex.isProtected()) { |
| 683 | // Not supported in GL backend at this time. |
| 684 | return false; |
| 685 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 686 | |
| 687 | desc->fConfig = caps.getConfigFromBackendFormat(backendTex.getBackendFormat(), colorType); |
| 688 | SkASSERT(desc->fConfig != kUnknown_GrPixelConfig); |
| 689 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 690 | return true; |
| 691 | } |
| 692 | |
| 693 | sk_sp<GrTexture> GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 694 | GrColorType colorType, GrWrapOwnership ownership, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 695 | GrWrapCacheable cacheable, GrIOType ioType) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 696 | GrGLTexture::Desc desc; |
| 697 | if (!check_backend_texture(backendTex, colorType, this->glCaps(), &desc)) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 698 | return nullptr; |
| 699 | } |
Robert Phillips | 1cd1ed8 | 2019-07-23 13:21:01 -0400 | [diff] [blame] | 700 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 701 | if (kBorrow_GrWrapOwnership == ownership) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 702 | desc.fOwnership = GrBackendObjectOwnership::kBorrowed; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 703 | } else { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 704 | desc.fOwnership = GrBackendObjectOwnership::kOwned; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 705 | } |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 706 | |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 707 | GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kValid |
| 708 | : GrMipMapsStatus::kNotAllocated; |
| 709 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 710 | auto texture = GrGLTexture::MakeWrapped(this, mipMapsStatus, desc, |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 711 | backendTex.getGLTextureParams(), cacheable, ioType); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 712 | // We don't know what parameters are already set on wrapped textures. |
| 713 | texture->textureParamsModified(); |
Brian Salomon | 9c73e3d | 2019-08-15 10:55:49 -0400 | [diff] [blame] | 714 | return texture; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | sk_sp<GrTexture> GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 718 | int sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 719 | GrColorType colorType, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 720 | GrWrapOwnership ownership, |
| 721 | GrWrapCacheable cacheable) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 722 | const GrGLCaps& caps = this->glCaps(); |
| 723 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 724 | GrGLTexture::Desc desc; |
| 725 | if (!check_backend_texture(backendTex, colorType, this->glCaps(), &desc)) { |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 726 | return nullptr; |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 727 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 728 | SkASSERT(caps.isFormatRenderable(desc.fFormat, sampleCnt)); |
| 729 | SkASSERT(caps.isFormatTexturable(desc.fFormat)); |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 730 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 731 | // We don't support rendering to a EXTERNAL texture. |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 732 | if (GR_GL_TEXTURE_EXTERNAL == desc.fTarget) { |
bsalomon | a98419b | 2015-11-23 07:09:50 -0800 | [diff] [blame] | 733 | return nullptr; |
| 734 | } |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 735 | |
Brian Osman | 766fcbb | 2017-03-13 09:33:09 -0400 | [diff] [blame] | 736 | if (kBorrow_GrWrapOwnership == ownership) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 737 | desc.fOwnership = GrBackendObjectOwnership::kBorrowed; |
Brian Osman | 766fcbb | 2017-03-13 09:33:09 -0400 | [diff] [blame] | 738 | } else { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 739 | desc.fOwnership = GrBackendObjectOwnership::kOwned; |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 740 | } |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 741 | |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 742 | |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 743 | sampleCnt = caps.getRenderTargetSampleCount(sampleCnt, desc.fFormat); |
| 744 | SkASSERT(sampleCnt); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 745 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 746 | GrGLRenderTarget::IDs rtIDs; |
| 747 | if (!this->createRenderTargetObjects(desc, sampleCnt, &rtIDs)) { |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 748 | return nullptr; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 749 | } |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 750 | |
| 751 | GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kDirty |
| 752 | : GrMipMapsStatus::kNotAllocated; |
| 753 | |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 754 | sk_sp<GrGLTextureRenderTarget> texRT(GrGLTextureRenderTarget::MakeWrapped( |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 755 | this, sampleCnt, desc, backendTex.getGLTextureParams(), rtIDs, cacheable, |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 756 | mipMapsStatus)); |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 757 | texRT->baseLevelWasBoundToFBO(); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 758 | // We don't know what parameters are already set on wrapped textures. |
| 759 | texRT->textureParamsModified(); |
Brian Salomon | 9c73e3d | 2019-08-15 10:55:49 -0400 | [diff] [blame] | 760 | return texRT; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 763 | sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT, |
| 764 | GrColorType grColorType) { |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 765 | GrGLFramebufferInfo info; |
| 766 | if (!backendRT.getGLFramebufferInfo(&info)) { |
Greg Daniel | bcf612b | 2017-05-01 13:50:58 +0000 | [diff] [blame] | 767 | return nullptr; |
| 768 | } |
| 769 | |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 770 | if (backendRT.isProtected()) { |
| 771 | // Not supported in GL at this time. |
| 772 | return nullptr; |
| 773 | } |
| 774 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 775 | const auto format = backendRT.getBackendFormat().asGLFormat(); |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 776 | if (!this->glCaps().isFormatRenderable(format, backendRT.sampleCnt())) { |
| 777 | return nullptr; |
| 778 | } |
| 779 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 780 | GrGLRenderTarget::IDs rtIDs; |
| 781 | rtIDs.fRTFBOID = info.fFBOID; |
| 782 | rtIDs.fMSColorRenderbufferID = 0; |
| 783 | rtIDs.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
| 784 | rtIDs.fRTFBOOwnership = GrBackendObjectOwnership::kBorrowed; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 785 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 786 | GrPixelConfig config = this->caps()->getConfigFromBackendFormat(backendRT.getBackendFormat(), |
| 787 | grColorType); |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 788 | SkASSERT(kUnknown_GrPixelConfig != config); |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 789 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 790 | const auto size = SkISize::Make(backendRT.width(), backendRT.height()); |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 791 | int sampleCount = this->glCaps().getRenderTargetSampleCount(backendRT.sampleCnt(), format); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 792 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 793 | return GrGLRenderTarget::MakeWrapped(this, size, format, config, sampleCount, rtIDs, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 794 | backendRT.stencilBits()); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 795 | } |
| 796 | |
Greg Daniel | 7ef28f3 | 2017-04-20 16:41:55 +0000 | [diff] [blame] | 797 | sk_sp<GrRenderTarget> GrGLGpu::onWrapBackendTextureAsRenderTarget(const GrBackendTexture& tex, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 798 | int sampleCnt, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 799 | GrColorType colorType) { |
| 800 | GrGLTexture::Desc desc; |
| 801 | // We do not check whether texture rectangle is supported by Skia - if the caller provided us |
| 802 | // with a texture rectangle,we assume the necessary support exists. |
| 803 | if (!check_backend_texture(tex, colorType, this->glCaps(), &desc, true)) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 804 | return nullptr; |
| 805 | } |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 806 | |
| 807 | if (!this->glCaps().isFormatRenderable(desc.fFormat, sampleCnt)) { |
| 808 | return nullptr; |
| 809 | } |
| 810 | |
| 811 | const int sampleCount = this->glCaps().getRenderTargetSampleCount(sampleCnt, desc.fFormat); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 812 | GrGLRenderTarget::IDs rtIDs; |
| 813 | if (!this->createRenderTargetObjects(desc, sampleCount, &rtIDs)) { |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 814 | return nullptr; |
| 815 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 816 | return GrGLRenderTarget::MakeWrapped(this, desc.fSize, desc.fFormat, desc.fConfig, sampleCount, |
| 817 | rtIDs, 0); |
ericrk | f7b8b8a | 2016-02-24 14:49:51 -0800 | [diff] [blame] | 818 | } |
| 819 | |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 820 | static bool check_write_and_transfer_input(GrGLTexture* glTex) { |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 821 | if (!glTex) { |
| 822 | return false; |
| 823 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 824 | |
bsalomon | e5286e0 | 2016-01-14 09:24:09 -0800 | [diff] [blame] | 825 | // Write or transfer of pixels is not implemented for TEXTURE_EXTERNAL textures |
| 826 | if (GR_GL_TEXTURE_EXTERNAL == glTex->target()) { |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 827 | return false; |
| 828 | } |
| 829 | |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 830 | return true; |
| 831 | } |
| 832 | |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 833 | bool GrGLGpu::onWritePixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 834 | GrColorType surfaceColorType, GrColorType srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 835 | const GrMipLevel texels[], int mipLevelCount, |
| 836 | bool prepForTexSampling) { |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 837 | auto glTex = static_cast<GrGLTexture*>(surface->asTexture()); |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 838 | |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 839 | if (!check_write_and_transfer_input(glTex)) { |
jvanverth | 17aa047 | 2016-01-05 10:41:27 -0800 | [diff] [blame] | 840 | return false; |
| 841 | } |
| 842 | |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 843 | this->bindTextureToScratchUnit(glTex->target(), glTex->textureID()); |
bsalomon@google.com | 9d6cfd8 | 2011-11-05 13:25:21 +0000 | [diff] [blame] | 844 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 845 | SkASSERT(!GrGLFormatIsCompressed(glTex->format())); |
Brian Salomon | 85769bf | 2019-08-01 15:52:34 -0400 | [diff] [blame] | 846 | return this->uploadTexData(glTex->format(), surfaceColorType, glTex->width(), glTex->height(), |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 847 | glTex->target(), left, top, width, height, srcColorType, texels, |
| 848 | mipLevelCount); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 849 | } |
| 850 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 851 | bool GrGLGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 852 | GrColorType textureColorType, GrColorType bufferColorType, |
| 853 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) { |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 854 | GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 855 | |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 856 | // Can't transfer compressed data |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 857 | SkASSERT(!GrGLFormatIsCompressed(glTex->format())); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 858 | |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 859 | if (!check_write_and_transfer_input(glTex)) { |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 860 | return false; |
| 861 | } |
| 862 | |
Hal Canary | c36f7e7 | 2018-06-18 15:50:09 -0400 | [diff] [blame] | 863 | static_assert(sizeof(int) == sizeof(int32_t), ""); |
| 864 | if (width <= 0 || height <= 0) { |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 865 | return false; |
| 866 | } |
| 867 | |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 868 | this->bindTextureToScratchUnit(glTex->target(), glTex->textureID()); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 869 | |
| 870 | SkASSERT(!transferBuffer->isMapped()); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 871 | SkASSERT(!transferBuffer->isCpuBuffer()); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 872 | const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer); |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 873 | this->bindBuffer(GrGpuBufferType::kXferCpuToGpu, glBuffer); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 874 | |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 875 | SkDEBUGCODE( |
| 876 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 877 | SkIRect bounds = SkIRect::MakeWH(texture->width(), texture->height()); |
| 878 | SkASSERT(bounds.contains(subRect)); |
| 879 | ) |
| 880 | |
Brian Salomon | b28cb68 | 2019-07-26 12:48:47 -0400 | [diff] [blame] | 881 | size_t bpp = GrColorTypeBytesPerPixel(bufferColorType); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 882 | const size_t trimRowBytes = width * bpp; |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 883 | const void* pixels = (void*)offset; |
Bruce Dawson | 71479b7 | 2017-07-05 14:30:20 -0700 | [diff] [blame] | 884 | if (width < 0 || height < 0) { |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 885 | return false; |
| 886 | } |
| 887 | |
| 888 | bool restoreGLRowLength = false; |
| 889 | if (trimRowBytes != rowBytes) { |
| 890 | // we should have checked for this support already |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 891 | SkASSERT(this->glCaps().writePixelsRowBytesSupport()); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 892 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowBytes / bpp)); |
| 893 | restoreGLRowLength = true; |
| 894 | } |
| 895 | |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 896 | GrGLFormat textureFormat = glTex->format(); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 897 | // External format and type come from the upload data. |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 898 | GrGLenum externalFormat = 0; |
| 899 | GrGLenum externalType = 0; |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 900 | this->glCaps().getTexSubImageExternalFormatAndType( |
| 901 | textureFormat, textureColorType, bufferColorType, &externalFormat, &externalType); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 902 | if (!externalFormat || !externalType) { |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 903 | return false; |
| 904 | } |
| 905 | |
Brian Salomon | 8cbf662 | 2019-07-30 11:03:14 -0400 | [diff] [blame] | 906 | GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 907 | GL_CALL(TexSubImage2D(glTex->target(), |
| 908 | 0, |
| 909 | left, top, |
| 910 | width, |
| 911 | height, |
| 912 | externalFormat, externalType, |
| 913 | pixels)); |
| 914 | |
| 915 | if (restoreGLRowLength) { |
| 916 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 917 | } |
| 918 | |
| 919 | return true; |
| 920 | } |
| 921 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 922 | bool GrGLGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 923 | GrColorType surfaceColorType, GrColorType dstColorType, |
| 924 | GrGpuBuffer* transferBuffer, size_t offset) { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 925 | auto* glBuffer = static_cast<GrGLBuffer*>(transferBuffer); |
| 926 | this->bindBuffer(GrGpuBufferType::kXferGpuToCpu, glBuffer); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 927 | auto offsetAsPtr = reinterpret_cast<void*>(offset); |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 928 | return this->readOrTransferPixelsFrom(surface, left, top, width, height, surfaceColorType, |
| 929 | dstColorType, offsetAsPtr, width); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 930 | } |
| 931 | |
Brian Osman | 9b56024 | 2017-09-05 15:34:52 -0400 | [diff] [blame] | 932 | void GrGLGpu::unbindCpuToGpuXferBuffer() { |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 933 | auto* xferBufferState = this->hwBufferState(GrGpuBufferType::kXferCpuToGpu); |
| 934 | if (!xferBufferState->fBoundBufferUniqueID.isInvalid()) { |
| 935 | GL_CALL(BindBuffer(xferBufferState->fGLTarget, 0)); |
| 936 | xferBufferState->invalidate(); |
Brian Osman | 9b56024 | 2017-09-05 15:34:52 -0400 | [diff] [blame] | 937 | } |
Brian Osman | 9b56024 | 2017-09-05 15:34:52 -0400 | [diff] [blame] | 938 | } |
| 939 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 940 | bool GrGLGpu::uploadTexData(GrGLFormat textureFormat, GrColorType textureColorType, int texWidth, |
| 941 | int texHeight, GrGLenum target, int left, int top, int width, |
| 942 | int height, GrColorType srcColorType, const GrMipLevel texels[], |
| 943 | int mipLevelCount, GrMipMapsStatus* mipMapsStatus) { |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 944 | // If we're uploading compressed data then we should be using uploadCompressedTexData |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 945 | SkASSERT(!GrGLFormatIsCompressed(textureFormat)); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 946 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 947 | SkASSERT(this->glCaps().isFormatTexturable(textureFormat)); |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 948 | SkDEBUGCODE( |
| 949 | SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); |
| 950 | SkIRect bounds = SkIRect::MakeWH(texWidth, texHeight); |
| 951 | SkASSERT(bounds.contains(subRect)); |
| 952 | ) |
Robert Phillips | 590533f | 2017-07-11 14:22:35 -0400 | [diff] [blame] | 953 | SkASSERT(1 == mipLevelCount || |
Greg Daniel | 660cc99 | 2017-06-26 14:55:05 -0400 | [diff] [blame] | 954 | (0 == left && 0 == top && width == texWidth && height == texHeight)); |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 955 | |
Brian Osman | 9b56024 | 2017-09-05 15:34:52 -0400 | [diff] [blame] | 956 | this->unbindCpuToGpuXferBuffer(); |
Jim Van Verth | 2e5eaf0 | 2017-06-21 15:55:46 -0400 | [diff] [blame] | 957 | |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 958 | const GrGLInterface* interface = this->glInterface(); |
| 959 | const GrGLCaps& caps = this->glCaps(); |
| 960 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 961 | size_t bpp = GrColorTypeBytesPerPixel(srcColorType); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 962 | |
| 963 | if (width == 0 || height == 0) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 964 | return false; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 965 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 966 | |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 967 | // External format and type come from the upload data. |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 968 | GrGLenum externalFormat; |
| 969 | GrGLenum externalType; |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 970 | this->glCaps().getTexSubImageExternalFormatAndType( |
| 971 | textureFormat, textureColorType, srcColorType, &externalFormat, &externalType); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 972 | if (!externalFormat || !externalType) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 973 | return false; |
| 974 | } |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 975 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 976 | /* |
bsalomon | 5b30c6f | 2015-12-17 14:17:34 -0800 | [diff] [blame] | 977 | * Check whether to allocate a temporary buffer for flipping y or |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 978 | * because our srcData has extra bytes past each row. If so, we need |
| 979 | * to trim those off here, since GL ES may not let us specify |
| 980 | * GL_UNPACK_ROW_LENGTH. |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 981 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 982 | bool restoreGLRowLength = false; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 983 | |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 984 | if (mipMapsStatus) { |
Chris Dalton | 95d8ceb | 2019-07-30 11:17:59 -0600 | [diff] [blame] | 985 | *mipMapsStatus = (mipLevelCount > 1) ? |
| 986 | GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 987 | } |
bsalomon | e699d0c | 2016-03-09 06:25:15 -0800 | [diff] [blame] | 988 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 989 | GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 990 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 991 | for (int currentMipLevel = 0; currentMipLevel < mipLevelCount; currentMipLevel++) { |
| 992 | if (!texels[currentMipLevel].fPixels) { |
| 993 | if (mipMapsStatus) { |
| 994 | *mipMapsStatus = GrMipMapsStatus::kDirty; |
Greg Daniel | 55afd6d | 2017-09-29 09:32:44 -0400 | [diff] [blame] | 995 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 996 | continue; |
Brian Salomon | 8e63cab | 2019-09-10 19:02:29 +0000 | [diff] [blame] | 997 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 998 | int twoToTheMipLevel = 1 << currentMipLevel; |
| 999 | const int currentWidth = SkTMax(1, width / twoToTheMipLevel); |
| 1000 | const int currentHeight = SkTMax(1, height / twoToTheMipLevel); |
| 1001 | const size_t trimRowBytes = currentWidth * bpp; |
| 1002 | const size_t rowBytes = texels[currentMipLevel].fRowBytes; |
| 1003 | |
| 1004 | if (caps.writePixelsRowBytesSupport() && (rowBytes != trimRowBytes || restoreGLRowLength)) { |
| 1005 | GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); |
| 1006 | GR_GL_CALL(interface, PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); |
| 1007 | restoreGLRowLength = true; |
| 1008 | } |
| 1009 | |
| 1010 | GL_CALL(TexSubImage2D(target, currentMipLevel, left, top, currentWidth, currentHeight, |
| 1011 | externalFormat, externalType, texels[currentMipLevel].fPixels)); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1012 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1013 | if (restoreGLRowLength) { |
| 1014 | SkASSERT(caps.writePixelsRowBytesSupport()); |
| 1015 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 1016 | } |
| 1017 | return true; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1020 | bool GrGLGpu::uploadCompressedTexData(GrGLFormat format, |
| 1021 | SkImage::CompressionType compressionType, |
| 1022 | const SkISize& size, |
| 1023 | GrGLenum target, |
| 1024 | const void* data) { |
| 1025 | SkASSERT(format != GrGLFormat::kUnknown); |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 1026 | const GrGLCaps& caps = this->glCaps(); |
| 1027 | |
| 1028 | // We only need the internal format for compressed 2D textures. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1029 | GrGLenum internalFormat = caps.getTexImageOrStorageInternalFormat(format); |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1030 | if (!internalFormat) { |
| 1031 | return 0; |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 1032 | } |
| 1033 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1034 | bool useTexStorage = caps.formatSupportsTexStorage(format); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1035 | |
| 1036 | static constexpr int kMipLevelCount = 1; |
| 1037 | |
| 1038 | // Make sure that the width and height that we pass to OpenGL |
| 1039 | // is a multiple of the block size. |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1040 | size_t dataSize = GrCompressedDataSize(compressionType, size.width(), size.height()); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1041 | |
| 1042 | if (useTexStorage) { |
| 1043 | // We never resize or change formats of textures. |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1044 | GL_ALLOC_CALL( |
| 1045 | this->glInterface(), |
| 1046 | TexStorage2D(target, kMipLevelCount, internalFormat, size.width(), size.height())); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1047 | GrGLenum error = CHECK_ALLOC_ERROR(this->glInterface()); |
| 1048 | if (error != GR_GL_NO_ERROR) { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1049 | return false; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1050 | } |
| 1051 | GL_CALL(CompressedTexSubImage2D(target, |
| 1052 | 0, // level |
| 1053 | 0, // left |
| 1054 | 0, // top |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1055 | size.width(), |
| 1056 | size.height(), |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1057 | internalFormat, |
| 1058 | SkToInt(dataSize), |
| 1059 | data)); |
| 1060 | } else { |
| 1061 | GL_ALLOC_CALL(this->glInterface(), CompressedTexImage2D(target, |
| 1062 | 0, // level |
| 1063 | internalFormat, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1064 | size.width(), |
| 1065 | size.height(), |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1066 | 0, // border |
| 1067 | SkToInt(dataSize), |
| 1068 | data)); |
| 1069 | |
| 1070 | GrGLenum error = CHECK_ALLOC_ERROR(this->glInterface()); |
| 1071 | if (error != GR_GL_NO_ERROR) { |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1072 | return false; |
Greg Kaiser | 73bfb89 | 2019-02-11 09:03:41 -0800 | [diff] [blame] | 1073 | } |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 1074 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1075 | return true; |
Jim Van Verth | 1676cb9 | 2019-01-15 13:24:45 -0500 | [diff] [blame] | 1076 | } |
| 1077 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 1078 | static bool renderbuffer_storage_msaa(const GrGLContext& ctx, |
commit-bot@chromium.org | 040fd8f | 2013-09-06 20:00:41 +0000 | [diff] [blame] | 1079 | int sampleCount, |
| 1080 | GrGLenum format, |
| 1081 | int width, int height) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 1082 | CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 1083 | SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 1084 | switch (ctx.caps()->msFBOType()) { |
Brian Salomon | 00731b4 | 2016-10-14 11:30:51 -0400 | [diff] [blame] | 1085 | case GrGLCaps::kStandard_MSFBOType: |
commit-bot@chromium.org | 040fd8f | 2013-09-06 20:00:41 +0000 | [diff] [blame] | 1086 | GL_ALLOC_CALL(ctx.interface(), |
| 1087 | RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, |
| 1088 | sampleCount, |
| 1089 | format, |
| 1090 | width, height)); |
| 1091 | break; |
| 1092 | case GrGLCaps::kES_Apple_MSFBOType: |
| 1093 | GL_ALLOC_CALL(ctx.interface(), |
| 1094 | RenderbufferStorageMultisampleES2APPLE(GR_GL_RENDERBUFFER, |
| 1095 | sampleCount, |
| 1096 | format, |
| 1097 | width, height)); |
| 1098 | break; |
| 1099 | case GrGLCaps::kES_EXT_MsToTexture_MSFBOType: |
| 1100 | case GrGLCaps::kES_IMG_MsToTexture_MSFBOType: |
| 1101 | GL_ALLOC_CALL(ctx.interface(), |
| 1102 | RenderbufferStorageMultisampleES2EXT(GR_GL_RENDERBUFFER, |
| 1103 | sampleCount, |
| 1104 | format, |
| 1105 | width, height)); |
| 1106 | break; |
| 1107 | case GrGLCaps::kNone_MSFBOType: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 1108 | SK_ABORT("Shouldn't be here if we don't support multisampled renderbuffers."); |
commit-bot@chromium.org | 040fd8f | 2013-09-06 20:00:41 +0000 | [diff] [blame] | 1109 | break; |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1110 | } |
Brian Salomon | 9251d4e | 2015-03-17 16:03:19 -0400 | [diff] [blame] | 1111 | return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1112 | } |
| 1113 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1114 | bool GrGLGpu::createRenderTargetObjects(const GrGLTexture::Desc& desc, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1115 | int sampleCount, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1116 | GrGLRenderTarget::IDs* rtIDs) { |
| 1117 | rtIDs->fMSColorRenderbufferID = 0; |
| 1118 | rtIDs->fRTFBOID = 0; |
| 1119 | rtIDs->fRTFBOOwnership = GrBackendObjectOwnership::kOwned; |
| 1120 | rtIDs->fTexFBOID = 0; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1121 | |
bsalomon | a11e5fc | 2015-12-18 07:59:41 -0800 | [diff] [blame] | 1122 | GrGLenum colorRenderbufferFormat = 0; // suppress warning |
bsalomon@google.com | ab15d61 | 2011-08-09 12:57:56 +0000 | [diff] [blame] | 1123 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1124 | if (desc.fFormat == GrGLFormat::kUnknown) { |
Greg Daniel | 9bb268b | 2019-07-17 10:40:13 -0400 | [diff] [blame] | 1125 | goto FAILED; |
| 1126 | } |
| 1127 | |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1128 | if (sampleCount > 1 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1129 | goto FAILED; |
| 1130 | } |
| 1131 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1132 | GL_CALL(GenFramebuffers(1, &rtIDs->fTexFBOID)); |
| 1133 | if (!rtIDs->fTexFBOID) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1134 | goto FAILED; |
| 1135 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1136 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1137 | // If we are using multisampling we will create two FBOS. We render to one and then resolve to |
| 1138 | // the texture bound to the other. The exception is the IMG multisample extension. With this |
| 1139 | // extension the texture is multisampled when rendered to and then auto-resolves it when it is |
| 1140 | // rendered from. |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1141 | if (sampleCount > 1 && this->glCaps().usesMSAARenderBuffers()) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1142 | GL_CALL(GenFramebuffers(1, &rtIDs->fRTFBOID)); |
| 1143 | GL_CALL(GenRenderbuffers(1, &rtIDs->fMSColorRenderbufferID)); |
| 1144 | if (!rtIDs->fRTFBOID || !rtIDs->fMSColorRenderbufferID) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1145 | goto FAILED; |
| 1146 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1147 | colorRenderbufferFormat = this->glCaps().getRenderbufferInternalFormat(desc.fFormat); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1148 | } else { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1149 | rtIDs->fRTFBOID = rtIDs->fTexFBOID; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1152 | // below here we may bind the FBO |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 1153 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1154 | if (rtIDs->fRTFBOID != rtIDs->fTexFBOID) { |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1155 | SkASSERT(sampleCount > 1); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1156 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, rtIDs->fMSColorRenderbufferID)); |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1157 | if (!renderbuffer_storage_msaa(*fGLContext, sampleCount, colorRenderbufferFormat, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1158 | desc.fSize.width(), desc.fSize.height())) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1159 | goto FAILED; |
| 1160 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1161 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, rtIDs->fRTFBOID); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1162 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 1163 | GR_GL_COLOR_ATTACHMENT0, |
| 1164 | GR_GL_RENDERBUFFER, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1165 | rtIDs->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1166 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1167 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, rtIDs->fTexFBOID); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1168 | |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1169 | if (this->glCaps().usesImplicitMSAAResolve() && sampleCount > 1) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1170 | GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
| 1171 | GR_GL_COLOR_ATTACHMENT0, |
| 1172 | desc.fTarget, |
| 1173 | desc.fID, |
| 1174 | 0, |
| 1175 | sampleCount)); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1176 | } else { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1177 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1178 | GR_GL_COLOR_ATTACHMENT0, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1179 | desc.fTarget, |
| 1180 | desc.fID, |
| 1181 | 0)); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1182 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1183 | |
| 1184 | return true; |
| 1185 | |
| 1186 | FAILED: |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1187 | if (rtIDs->fMSColorRenderbufferID) { |
| 1188 | GL_CALL(DeleteRenderbuffers(1, &rtIDs->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1189 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1190 | if (rtIDs->fRTFBOID != rtIDs->fTexFBOID) { |
| 1191 | this->deleteFramebuffer(rtIDs->fRTFBOID); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1192 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1193 | if (rtIDs->fTexFBOID) { |
| 1194 | this->deleteFramebuffer(rtIDs->fTexFBOID); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1195 | } |
| 1196 | return false; |
| 1197 | } |
| 1198 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 1199 | // good to set a break-point here to know when createTexture fails |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 1200 | static sk_sp<GrTexture> return_null_texture() { |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1201 | // SkDEBUGFAIL("null texture"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1202 | return nullptr; |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1205 | static GrGLTextureParameters::SamplerOverriddenState set_initial_texture_params( |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1206 | const GrGLInterface* interface, GrGLenum target) { |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 1207 | // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1208 | // drivers have a bug where an FBO won't be complete if it includes a |
| 1209 | // texture that is not mipmap complete (considering the filter in use). |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1210 | GrGLTextureParameters::SamplerOverriddenState state; |
| 1211 | state.fMinFilter = GR_GL_NEAREST; |
| 1212 | state.fMagFilter = GR_GL_NEAREST; |
| 1213 | state.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1214 | state.fWrapT = GR_GL_CLAMP_TO_EDGE; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1215 | GR_GL_CALL(interface, TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, state.fMagFilter)); |
| 1216 | GR_GL_CALL(interface, TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, state.fMinFilter)); |
| 1217 | GR_GL_CALL(interface, TexParameteri(target, GR_GL_TEXTURE_WRAP_S, state.fWrapS)); |
| 1218 | GR_GL_CALL(interface, TexParameteri(target, GR_GL_TEXTURE_WRAP_T, state.fWrapT)); |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1219 | return state; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 1220 | } |
| 1221 | |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 1222 | sk_sp<GrTexture> GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 1223 | const GrBackendFormat& format, |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 1224 | GrRenderable renderable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1225 | int renderTargetSampleCnt, |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 1226 | SkBudgeted budgeted, |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 1227 | GrProtected isProtected, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1228 | int mipLevelCount, |
| 1229 | uint32_t levelClearMask) { |
Brian Salomon | e8a766b | 2019-07-19 14:24:36 -0400 | [diff] [blame] | 1230 | // We don't support protected textures in GL. |
| 1231 | if (isProtected == GrProtected::kYes) { |
| 1232 | return nullptr; |
| 1233 | } |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 1234 | SkASSERT(GrGLCaps::kNone_MSFBOType != this->glCaps().msFBOType() || renderTargetSampleCnt == 1); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1235 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1236 | SkASSERT(mipLevelCount > 0); |
| 1237 | GrMipMapsStatus mipMapsStatus = |
| 1238 | mipLevelCount > 1 ? GrMipMapsStatus::kDirty : GrMipMapsStatus::kNotAllocated; |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1239 | GrGLTextureParameters::SamplerOverriddenState initialState; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1240 | GrGLTexture::Desc texDesc; |
| 1241 | texDesc.fSize = {desc.fWidth, desc.fHeight}; |
| 1242 | texDesc.fTarget = GR_GL_TEXTURE_2D; |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 1243 | texDesc.fFormat = format.asGLFormat(); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1244 | texDesc.fConfig = desc.fConfig; |
| 1245 | texDesc.fOwnership = GrBackendObjectOwnership::kOwned; |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 1246 | SkASSERT(texDesc.fFormat != GrGLFormat::kUnknown); |
| 1247 | SkASSERT(!GrGLFormatIsCompressed(texDesc.fFormat)); |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1248 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1249 | texDesc.fID = this->createTexture2D({desc.fWidth, desc.fHeight}, texDesc.fFormat, renderable, |
| 1250 | &initialState, mipLevelCount); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1251 | |
| 1252 | if (!texDesc.fID) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 1253 | return return_null_texture(); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1254 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1255 | |
Robert Phillips | 67d52cf | 2017-06-05 13:38:13 -0400 | [diff] [blame] | 1256 | sk_sp<GrGLTexture> tex; |
Brian Salomon | f2c2ba9 | 2019-07-17 09:59:59 -0400 | [diff] [blame] | 1257 | if (renderable == GrRenderable::kYes) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 1258 | // unbind the texture from the texture unit before binding it to the frame buffer |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1259 | GL_CALL(BindTexture(texDesc.fTarget, 0)); |
| 1260 | GrGLRenderTarget::IDs rtIDDesc; |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 1261 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1262 | if (!this->createRenderTargetObjects(texDesc, renderTargetSampleCnt, &rtIDDesc)) { |
| 1263 | GL_CALL(DeleteTextures(1, &texDesc.fID)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1264 | return return_null_texture(); |
| 1265 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1266 | tex = sk_make_sp<GrGLTextureRenderTarget>( |
| 1267 | this, budgeted, renderTargetSampleCnt, texDesc, rtIDDesc, mipMapsStatus); |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 1268 | tex->baseLevelWasBoundToFBO(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1269 | } else { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1270 | tex = sk_make_sp<GrGLTexture>(this, budgeted, texDesc, mipMapsStatus); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1271 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 1272 | // The non-sampler params are still at their default values. |
| 1273 | tex->parameters()->set(&initialState, GrGLTextureParameters::NonsamplerState(), |
| 1274 | fResetTimestampForTextureParameters); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1275 | if (levelClearMask) { |
| 1276 | GrGLenum externalFormat, externalType; |
| 1277 | size_t bpp; |
| 1278 | this->glCaps().getTexSubImageZeroFormatTypeAndBpp(texDesc.fFormat, &externalFormat, |
| 1279 | &externalType, &bpp); |
| 1280 | if (this->glCaps().clearTextureSupport()) { |
| 1281 | for (int i = 0; i < mipLevelCount; ++i) { |
| 1282 | if (levelClearMask & (1U << i)) { |
| 1283 | GL_CALL(ClearTexImage(tex->textureID(), i, externalFormat, externalType, |
| 1284 | nullptr)); |
| 1285 | } |
| 1286 | } |
| 1287 | } else if (this->glCaps().canFormatBeFBOColorAttachment(format.asGLFormat()) && |
| 1288 | !this->glCaps().performColorClearsAsDraws()) { |
| 1289 | this->disableScissor(); |
| 1290 | this->disableWindowRectangles(); |
| 1291 | this->flushColorWrite(true); |
| 1292 | this->flushClearColor(0, 0, 0, 0); |
| 1293 | for (int i = 0; i < mipLevelCount; ++i) { |
| 1294 | if (levelClearMask & (1U << i)) { |
| 1295 | this->bindSurfaceFBOForPixelOps(tex.get(), i, GR_GL_FRAMEBUFFER, |
| 1296 | kDst_TempFBOTarget); |
| 1297 | GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
| 1298 | this->unbindSurfaceFBOForPixelOps(tex.get(), i, GR_GL_FRAMEBUFFER); |
| 1299 | } |
| 1300 | } |
| 1301 | } else { |
| 1302 | std::unique_ptr<char[]> zeros; |
| 1303 | GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, 1)); |
| 1304 | for (int i = 0; i < mipLevelCount; ++i) { |
| 1305 | if (levelClearMask & (1U << i)) { |
| 1306 | int levelWidth = SkTMax(1, texDesc.fSize.width() >> i); |
| 1307 | int levelHeight = SkTMax(1, texDesc.fSize.height() >> i); |
| 1308 | // Levels only get smaller as we proceed. Once we create a zeros use it for all |
| 1309 | // smaller levels that need clearing. |
| 1310 | if (!zeros) { |
| 1311 | size_t size = levelWidth * levelHeight * bpp; |
| 1312 | zeros.reset(new char[size]()); |
| 1313 | } |
| 1314 | this->bindTextureToScratchUnit(GR_GL_TEXTURE_2D, tex->textureID()); |
| 1315 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, i, 0, 0, levelWidth, levelHeight, |
| 1316 | externalFormat, externalType, zeros.get())); |
| 1317 | } |
Brian Salomon | a3e2996 | 2019-07-16 11:52:08 -0400 | [diff] [blame] | 1318 | } |
Brian Salomon | d17b4a6 | 2017-05-23 16:53:47 -0400 | [diff] [blame] | 1319 | } |
| 1320 | } |
Brian Salomon | 9c73e3d | 2019-08-15 10:55:49 -0400 | [diff] [blame] | 1321 | return tex; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1324 | sk_sp<GrTexture> GrGLGpu::onCreateCompressedTexture(int width, int height, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1325 | const GrBackendFormat& format, |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1326 | SkImage::CompressionType compression, |
| 1327 | SkBudgeted budgeted, const void* data) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1328 | GrGLTextureParameters::SamplerOverriddenState initialState; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1329 | GrGLTexture::Desc desc; |
| 1330 | desc.fSize = {width, height}; |
| 1331 | desc.fTarget = GR_GL_TEXTURE_2D; |
| 1332 | desc.fConfig = GrCompressionTypePixelConfig(compression); |
| 1333 | desc.fOwnership = GrBackendObjectOwnership::kOwned; |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1334 | desc.fFormat = format.asGLFormat(); |
| 1335 | desc.fID = this->createCompressedTexture2D(desc.fSize, desc.fFormat, compression, &initialState, |
| 1336 | data); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1337 | if (!desc.fID) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1338 | return nullptr; |
| 1339 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1340 | auto tex = sk_make_sp<GrGLTexture>(this, budgeted, desc, GrMipMapsStatus::kNotAllocated); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1341 | // The non-sampler params are still at their default values. |
| 1342 | tex->parameters()->set(&initialState, GrGLTextureParameters::NonsamplerState(), |
| 1343 | fResetTimestampForTextureParameters); |
Brian Salomon | 9c73e3d | 2019-08-15 10:55:49 -0400 | [diff] [blame] | 1344 | return tex; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1345 | } |
| 1346 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1347 | namespace { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1348 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1349 | const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1350 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1351 | void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1352 | GrGLStencilAttachment::Format* format) { |
sugoi@google.com | 6ba0b0f | 2013-05-03 13:52:32 +0000 | [diff] [blame] | 1353 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1354 | // we shouldn't ever know one size and not the other |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1355 | SkASSERT((kUnknownBitCount == format->fStencilBits) == |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1356 | (kUnknownBitCount == format->fTotalBits)); |
| 1357 | if (kUnknownBitCount == format->fStencilBits) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1358 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1359 | GR_GL_RENDERBUFFER_STENCIL_SIZE, |
| 1360 | (GrGLint*)&format->fStencilBits); |
| 1361 | if (format->fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1362 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1363 | GR_GL_RENDERBUFFER_DEPTH_SIZE, |
| 1364 | (GrGLint*)&format->fTotalBits); |
| 1365 | format->fTotalBits += format->fStencilBits; |
| 1366 | } else { |
| 1367 | format->fTotalBits = format->fStencilBits; |
| 1368 | } |
| 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 1373 | int GrGLGpu::getCompatibleStencilIndex(GrGLFormat format) { |
bsalomon | 100b8f8 | 2015-10-28 08:37:44 -0700 | [diff] [blame] | 1374 | static const int kSize = 16; |
Brian Salomon | f6da146 | 2019-07-11 14:21:59 -0400 | [diff] [blame] | 1375 | SkASSERT(this->glCaps().canFormatBeFBOColorAttachment(format)); |
| 1376 | |
| 1377 | if (!this->glCaps().hasStencilFormatBeenDeterminedForFormat(format)) { |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1378 | // Default to unsupported, set this if we find a stencil format that works. |
| 1379 | int firstWorkingStencilFormatIndex = -1; |
Brian Osman | 91f9a2c | 2017-09-05 15:02:46 -0400 | [diff] [blame] | 1380 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1381 | GrGLuint colorID = |
| 1382 | this->createTexture2D({kSize, kSize}, format, GrRenderable::kYes, nullptr, 1); |
| 1383 | if (!colorID) { |
Brian Salomon | f6da146 | 2019-07-11 14:21:59 -0400 | [diff] [blame] | 1384 | return -1; |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1385 | } |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1386 | // unbind the texture from the texture unit before binding it to the frame buffer |
| 1387 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); |
| 1388 | |
| 1389 | // Create Framebuffer |
kkinnunen | 546eb5c | 2015-12-11 00:05:33 -0800 | [diff] [blame] | 1390 | GrGLuint fb = 0; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1391 | GL_CALL(GenFramebuffers(1, &fb)); |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 1392 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, fb); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 1393 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1394 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
| 1395 | GR_GL_COLOR_ATTACHMENT0, |
| 1396 | GR_GL_TEXTURE_2D, |
| 1397 | colorID, |
| 1398 | 0)); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1399 | GrGLuint sbRBID = 0; |
| 1400 | GL_CALL(GenRenderbuffers(1, &sbRBID)); |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1401 | |
| 1402 | // look over formats till I find a compatible one |
| 1403 | int stencilFmtCnt = this->glCaps().stencilFormats().count(); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1404 | if (sbRBID) { |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1405 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbRBID)); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1406 | for (int i = 0; i < stencilFmtCnt && sbRBID; ++i) { |
| 1407 | const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[i]; |
| 1408 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1409 | GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFER, |
| 1410 | sFmt.fInternalFormat, |
| 1411 | kSize, kSize)); |
| 1412 | if (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(this->glInterface())) { |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1413 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1414 | GR_GL_STENCIL_ATTACHMENT, |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1415 | GR_GL_RENDERBUFFER, sbRBID)); |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1416 | if (sFmt.fPacked) { |
| 1417 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1418 | GR_GL_DEPTH_ATTACHMENT, |
| 1419 | GR_GL_RENDERBUFFER, sbRBID)); |
| 1420 | } else { |
| 1421 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1422 | GR_GL_DEPTH_ATTACHMENT, |
| 1423 | GR_GL_RENDERBUFFER, 0)); |
| 1424 | } |
| 1425 | GrGLenum status; |
| 1426 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1427 | if (status == GR_GL_FRAMEBUFFER_COMPLETE) { |
| 1428 | firstWorkingStencilFormatIndex = i; |
| 1429 | break; |
| 1430 | } |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1431 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1432 | GR_GL_STENCIL_ATTACHMENT, |
| 1433 | GR_GL_RENDERBUFFER, 0)); |
| 1434 | if (sFmt.fPacked) { |
| 1435 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1436 | GR_GL_DEPTH_ATTACHMENT, |
| 1437 | GR_GL_RENDERBUFFER, 0)); |
| 1438 | } |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1439 | } |
| 1440 | } |
bsalomon | 3044737 | 2015-12-21 09:03:05 -0800 | [diff] [blame] | 1441 | GL_CALL(DeleteRenderbuffers(1, &sbRBID)); |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1442 | } |
| 1443 | GL_CALL(DeleteTextures(1, &colorID)); |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 1444 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, 0); |
| 1445 | this->deleteFramebuffer(fb); |
Brian Salomon | f6da146 | 2019-07-11 14:21:59 -0400 | [diff] [blame] | 1446 | fGLContext->caps()->setStencilFormatIndexForFormat(format, firstWorkingStencilFormatIndex); |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1447 | } |
Brian Salomon | f6da146 | 2019-07-11 14:21:59 -0400 | [diff] [blame] | 1448 | return this->glCaps().getStencilFormatIndexForFormat(format); |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1451 | GrGLuint GrGLGpu::createCompressedTexture2D( |
| 1452 | const SkISize& size, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1453 | GrGLFormat format, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1454 | SkImage::CompressionType compression, |
| 1455 | GrGLTextureParameters::SamplerOverriddenState* initialState, |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1456 | const void* data) { |
| 1457 | if (format == GrGLFormat::kUnknown) { |
| 1458 | return 0; |
| 1459 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1460 | GrGLuint id = 0; |
| 1461 | GL_CALL(GenTextures(1, &id)); |
| 1462 | if (!id) { |
| 1463 | return 0; |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 1464 | } |
| 1465 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1466 | this->bindTextureToScratchUnit(GR_GL_TEXTURE_2D, id); |
Robert Phillips | 8043f32 | 2019-05-31 08:11:36 -0400 | [diff] [blame] | 1467 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1468 | *initialState = set_initial_texture_params(this->glInterface(), GR_GL_TEXTURE_2D); |
| 1469 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 1470 | if (!this->uploadCompressedTexData(format, compression, size, GR_GL_TEXTURE_2D, data)) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1471 | GL_CALL(DeleteTextures(1, &id)); |
| 1472 | return 0; |
| 1473 | } |
| 1474 | return id; |
| 1475 | } |
| 1476 | |
| 1477 | GrGLuint GrGLGpu::createTexture2D(const SkISize& size, |
| 1478 | GrGLFormat format, |
| 1479 | GrRenderable renderable, |
| 1480 | GrGLTextureParameters::SamplerOverriddenState* initialState, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1481 | int mipLevelCount) { |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 1482 | SkASSERT(format != GrGLFormat::kUnknown); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1483 | SkASSERT(!GrGLFormatIsCompressed(format)); |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 1484 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1485 | GrGLuint id = 0; |
| 1486 | GL_CALL(GenTextures(1, &id)); |
| 1487 | |
| 1488 | if (!id) { |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | this->bindTextureToScratchUnit(GR_GL_TEXTURE_2D, id); |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 1493 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 1494 | if (GrRenderable::kYes == renderable && this->glCaps().textureUsageSupport()) { |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 1495 | // provides a hint about how this texture will be used |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 1496 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_USAGE, GR_GL_FRAMEBUFFER_ATTACHMENT)); |
erikchen | 9a1ed5d | 2016-02-10 16:32:34 -0800 | [diff] [blame] | 1497 | } |
| 1498 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1499 | if (initialState) { |
| 1500 | *initialState = set_initial_texture_params(this->glInterface(), GR_GL_TEXTURE_2D); |
| 1501 | } else { |
| 1502 | set_initial_texture_params(this->glInterface(), GR_GL_TEXTURE_2D); |
Brian Salomon | a739824 | 2019-09-10 09:17:38 -0400 | [diff] [blame] | 1503 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1504 | |
| 1505 | GrGLenum internalFormat = this->glCaps().getTexImageOrStorageInternalFormat(format); |
| 1506 | |
| 1507 | bool success = false; |
| 1508 | if (internalFormat) { |
| 1509 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1510 | if (this->glCaps().formatSupportsTexStorage(format)) { |
| 1511 | GL_ALLOC_CALL(this->glInterface(), |
| 1512 | TexStorage2D(GR_GL_TEXTURE_2D, SkTMax(mipLevelCount, 1), internalFormat, |
| 1513 | size.width(), size.height())); |
| 1514 | success = (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(this->glInterface())); |
| 1515 | } else { |
| 1516 | GrGLenum externalFormat, externalType; |
| 1517 | this->glCaps().getTexImageExternalFormatAndType(format, &externalFormat, &externalType); |
| 1518 | GrGLenum error = GR_GL_NO_ERROR; |
| 1519 | if (externalFormat && externalType) { |
| 1520 | for (int level = 0; level < mipLevelCount && error == GR_GL_NO_ERROR; level++) { |
| 1521 | const int twoToTheMipLevel = 1 << level; |
| 1522 | const int currentWidth = SkTMax(1, size.width() / twoToTheMipLevel); |
| 1523 | const int currentHeight = SkTMax(1, size.height() / twoToTheMipLevel); |
| 1524 | GL_ALLOC_CALL( |
| 1525 | this->glInterface(), |
| 1526 | TexImage2D(GR_GL_TEXTURE_2D, level, internalFormat, currentWidth, |
| 1527 | currentHeight, 0, externalFormat, externalType, nullptr)); |
| 1528 | error = CHECK_ALLOC_ERROR(this->glInterface()); |
| 1529 | } |
| 1530 | success = (GR_GL_NO_ERROR == error); |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | if (success) { |
| 1535 | return id; |
| 1536 | } |
| 1537 | GL_CALL(DeleteTextures(1, &id)); |
| 1538 | return 0; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 1539 | } |
| 1540 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 1541 | GrStencilAttachment* GrGLGpu::createStencilAttachmentForRenderTarget( |
| 1542 | const GrRenderTarget* rt, int width, int height, int numStencilSamples) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1543 | SkASSERT(width >= rt->width()); |
| 1544 | SkASSERT(height >= rt->height()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1545 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1546 | GrGLStencilAttachment::IDDesc sbDesc; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1547 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1548 | int sIdx = this->getCompatibleStencilIndex(rt->backendFormat().asGLFormat()); |
bsalomon | 62a627b | 2015-12-17 09:50:47 -0800 | [diff] [blame] | 1549 | if (sIdx < 0) { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 1550 | return nullptr; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1551 | } |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1552 | |
| 1553 | if (!sbDesc.fRenderbufferID) { |
| 1554 | GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID)); |
| 1555 | } |
| 1556 | if (!sbDesc.fRenderbufferID) { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 1557 | return nullptr; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1558 | } |
| 1559 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)); |
| 1560 | const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sIdx]; |
| 1561 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1562 | // we do this "if" so that we don't call the multisample |
| 1563 | // version on a GL that doesn't have an MSAA extension. |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 1564 | if (numStencilSamples > 1) { |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1565 | SkAssertResult(renderbuffer_storage_msaa(*fGLContext, |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 1566 | numStencilSamples, |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1567 | sFmt.fInternalFormat, |
| 1568 | width, height)); |
| 1569 | } else { |
| 1570 | GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFER, |
| 1571 | sFmt.fInternalFormat, |
| 1572 | width, height)); |
Brian Salomon | 0ec981b | 2017-05-15 13:48:50 -0400 | [diff] [blame] | 1573 | SkASSERT(GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(this->glInterface())); |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 1574 | } |
| 1575 | fStats.incStencilAttachmentCreates(); |
| 1576 | // After sized formats we attempt an unsized format and take |
| 1577 | // whatever sizes GL gives us. In that case we query for the size. |
| 1578 | GrGLStencilAttachment::Format format = sFmt; |
| 1579 | get_stencil_rb_sizes(this->glInterface(), &format); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 1580 | GrGLStencilAttachment* stencil = new GrGLStencilAttachment(this, |
| 1581 | sbDesc, |
| 1582 | width, |
| 1583 | height, |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 1584 | numStencilSamples, |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 1585 | format); |
| 1586 | return stencil; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1589 | //////////////////////////////////////////////////////////////////////////////// |
| 1590 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 1591 | sk_sp<GrGpuBuffer> GrGLGpu::onCreateBuffer(size_t size, GrGpuBufferType intendedType, |
| 1592 | GrAccessPattern accessPattern, const void* data) { |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 1593 | return GrGLBuffer::Make(this, size, intendedType, accessPattern, data); |
jvanverth | 73063dc | 2015-12-03 09:15:47 -0800 | [diff] [blame] | 1594 | } |
| 1595 | |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 1596 | void GrGLGpu::flushScissor(const GrScissorState& scissorState, int rtWidth, int rtHeight, |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1597 | GrSurfaceOrigin rtOrigin) { |
| 1598 | if (scissorState.enabled()) { |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 1599 | auto scissor = GrNativeRect::MakeRelativeTo(rtOrigin, rtHeight, scissorState.rect()); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1600 | // if the scissor fully contains the viewport then we fall through and |
| 1601 | // disable the scissor test. |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 1602 | if (!scissor.contains(rtWidth, rtHeight)) { |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1603 | if (fHWScissorSettings.fRect != scissor) { |
Chris Dalton | 76500e5 | 2019-09-05 02:13:05 -0600 | [diff] [blame] | 1604 | GL_CALL(Scissor(scissor.fX, scissor.fY, scissor.fWidth, scissor.fHeight)); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1605 | fHWScissorSettings.fRect = scissor; |
| 1606 | } |
| 1607 | if (kYes_TriState != fHWScissorSettings.fEnabled) { |
| 1608 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
| 1609 | fHWScissorSettings.fEnabled = kYes_TriState; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1610 | } |
| 1611 | return; |
| 1612 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1613 | } |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1614 | |
| 1615 | // See fall through note above |
| 1616 | this->disableScissor(); |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 1619 | void GrGLGpu::flushWindowRectangles(const GrWindowRectsState& windowState, |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 1620 | const GrGLRenderTarget* rt, GrSurfaceOrigin origin) { |
Jim Van Verth | 32ac83e | 2016-11-28 15:23:57 -0500 | [diff] [blame] | 1621 | #ifndef USE_NSIGHT |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 1622 | typedef GrWindowRectsState::Mode Mode; |
| 1623 | SkASSERT(!windowState.enabled() || rt->renderFBOID()); // Window rects can't be used on-screen. |
| 1624 | SkASSERT(windowState.numWindows() <= this->caps()->maxWindowRectangles()); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1625 | |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 1626 | if (!this->caps()->maxWindowRectangles() || |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 1627 | fHWWindowRectsState.knownEqualTo(origin, rt->width(), rt->height(), windowState)) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1628 | return; |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 1631 | // This is purely a workaround for a spurious warning generated by gcc. Otherwise the above |
| 1632 | // assert would be sufficient. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=5912 |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 1633 | int numWindows = SkTMin(windowState.numWindows(), int(GrWindowRectangles::kMaxWindows)); |
| 1634 | SkASSERT(windowState.numWindows() == numWindows); |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 1635 | |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 1636 | GrNativeRect glwindows[GrWindowRectangles::kMaxWindows]; |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 1637 | const SkIRect* skwindows = windowState.windows().data(); |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 1638 | for (int i = 0; i < numWindows; ++i) { |
Chris Dalton | 76500e5 | 2019-09-05 02:13:05 -0600 | [diff] [blame] | 1639 | glwindows[i].setRelativeTo(origin, rt->height(), skwindows[i]); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 1642 | GrGLenum glmode = (Mode::kExclusive == windowState.mode()) ? GR_GL_EXCLUSIVE : GR_GL_INCLUSIVE; |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 1643 | GL_CALL(WindowRectangles(glmode, numWindows, glwindows->asInts())); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1644 | |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 1645 | fHWWindowRectsState.set(origin, rt->width(), rt->height(), windowState); |
Jim Van Verth | 32ac83e | 2016-11-28 15:23:57 -0500 | [diff] [blame] | 1646 | #endif |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | void GrGLGpu::disableWindowRectangles() { |
Jim Van Verth | 32ac83e | 2016-11-28 15:23:57 -0500 | [diff] [blame] | 1650 | #ifndef USE_NSIGHT |
Jim Van Verth | 6a40abc | 2017-11-02 16:56:09 +0000 | [diff] [blame] | 1651 | if (!this->caps()->maxWindowRectangles() || fHWWindowRectsState.knownDisabled()) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1652 | return; |
| 1653 | } |
| 1654 | GL_CALL(WindowRectangles(GR_GL_EXCLUSIVE, 0, nullptr)); |
csmartdalton | bf4a8f9 | 2016-09-06 10:01:06 -0700 | [diff] [blame] | 1655 | fHWWindowRectsState.setDisabled(); |
Jim Van Verth | 32ac83e | 2016-11-28 15:23:57 -0500 | [diff] [blame] | 1656 | #endif |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 1659 | bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, |
| 1660 | GrSurfaceOrigin origin, |
| 1661 | const GrPrimitiveProcessor& primProc, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 1662 | const GrPipeline& pipeline, |
| 1663 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 1664 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
| 1665 | int dynamicStateArraysLength, |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 1666 | bool willDrawPoints) { |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 1667 | const GrTextureProxy* const* primProcProxies = nullptr; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 1668 | const GrTextureProxy* const* primProcProxiesToBind = nullptr; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 1669 | if (dynamicStateArrays && dynamicStateArrays->fPrimitiveProcessorTextures) { |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 1670 | primProcProxies = dynamicStateArrays->fPrimitiveProcessorTextures; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 1671 | } else if (fixedDynamicState && fixedDynamicState->fPrimitiveProcessorTextures) { |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 1672 | primProcProxies = fixedDynamicState->fPrimitiveProcessorTextures; |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 1673 | primProcProxiesToBind = fixedDynamicState->fPrimitiveProcessorTextures; |
Brian Salomon | 7eae3e0 | 2018-08-07 14:02:38 +0000 | [diff] [blame] | 1674 | } |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 1675 | |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 1676 | SkASSERT(SkToBool(primProcProxies) == SkToBool(primProc.numTextureSamplers())); |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 1677 | |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 1678 | sk_sp<GrGLProgram> program(fProgramCache->refProgram( |
| 1679 | this, renderTarget, origin, primProc, primProcProxies, pipeline, willDrawPoints)); |
Greg Daniel | 9a51a86 | 2018-11-30 10:18:14 -0500 | [diff] [blame] | 1680 | if (!program) { |
| 1681 | GrCapsDebugf(this->caps(), "Failed to create program!\n"); |
| 1682 | return false; |
| 1683 | } |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 1684 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 1685 | this->flushProgram(std::move(program)); |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1686 | |
Dongseong Hwang | 4e1f022 | 2018-11-01 09:10:51 -0700 | [diff] [blame] | 1687 | // Swizzle the blend to match what the shader will output. |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 1688 | this->flushBlendAndColorWrite( |
| 1689 | pipeline.getXferProcessor().getBlendInfo(), pipeline.outputSwizzle()); |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1690 | |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 1691 | fHWProgram->updateUniformsAndTextureBindings(renderTarget, origin, |
| 1692 | primProc, pipeline, primProcProxiesToBind); |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1693 | |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 1694 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); |
csmartdalton | c633abb | 2016-11-01 08:55:55 -0700 | [diff] [blame] | 1695 | GrStencilSettings stencil; |
| 1696 | if (pipeline.isStencilEnabled()) { |
| 1697 | // TODO: attach stencil and create settings during render target flush. |
| 1698 | SkASSERT(glRT->renderTargetPriv().getStencilAttachment()); |
| 1699 | stencil.reset(*pipeline.getUserStencil(), pipeline.hasStencilClip(), |
| 1700 | glRT->renderTargetPriv().numStencilBits()); |
| 1701 | } |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 1702 | this->flushStencil(stencil, origin); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1703 | if (pipeline.isScissorEnabled()) { |
| 1704 | static constexpr SkIRect kBogusScissor{0, 0, 1, 1}; |
| 1705 | GrScissorState state(fixedDynamicState ? fixedDynamicState->fScissorRect : kBogusScissor); |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 1706 | this->flushScissor(state, glRT->width(), glRT->height(), origin); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1707 | } else { |
| 1708 | this->disableScissor(); |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 1709 | } |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 1710 | this->flushWindowRectangles(pipeline.getWindowRectsState(), glRT, origin); |
Chris Dalton | 4c56b03 | 2019-03-04 12:28:42 -0700 | [diff] [blame] | 1711 | this->flushHWAAState(glRT, pipeline.isHWAntialiasState()); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1712 | |
| 1713 | // This must come after textures are flushed because a texture may need |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1714 | // to be msaa-resolved (which will modify bound FBO state). |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 1715 | this->flushRenderTarget(glRT); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1716 | |
| 1717 | return true; |
| 1718 | } |
| 1719 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 1720 | void GrGLGpu::flushProgram(sk_sp<GrGLProgram> program) { |
| 1721 | if (!program) { |
| 1722 | fHWProgram.reset(); |
| 1723 | fHWProgramID = 0; |
| 1724 | return; |
| 1725 | } |
| 1726 | SkASSERT((program == fHWProgram) == (fHWProgramID == program->programID())); |
| 1727 | if (program == fHWProgram) { |
| 1728 | return; |
| 1729 | } |
| 1730 | auto id = program->programID(); |
| 1731 | SkASSERT(id); |
| 1732 | GL_CALL(UseProgram(id)); |
| 1733 | fHWProgram = std::move(program); |
| 1734 | fHWProgramID = id; |
| 1735 | } |
| 1736 | |
| 1737 | void GrGLGpu::flushProgram(GrGLuint id) { |
| 1738 | SkASSERT(id); |
| 1739 | if (fHWProgramID == id) { |
| 1740 | SkASSERT(!fHWProgram); |
| 1741 | return; |
| 1742 | } |
| 1743 | fHWProgram.reset(); |
| 1744 | GL_CALL(UseProgram(id)); |
| 1745 | fHWProgramID = id; |
| 1746 | } |
| 1747 | |
| 1748 | void GrGLGpu::setupGeometry(const GrBuffer* indexBuffer, |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 1749 | const GrBuffer* vertexBuffer, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 1750 | int baseVertex, |
| 1751 | const GrBuffer* instanceBuffer, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 1752 | int baseInstance, |
| 1753 | GrPrimitiveRestart enablePrimitiveRestart) { |
| 1754 | SkASSERT((enablePrimitiveRestart == GrPrimitiveRestart::kNo) || indexBuffer); |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 1755 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 1756 | GrGLAttribArrayState* attribState; |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 1757 | if (indexBuffer) { |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 1758 | SkASSERT(indexBuffer->isCpuBuffer() || |
| 1759 | !static_cast<const GrGpuBuffer*>(indexBuffer)->isMapped()); |
Chris Dalton | ff92650 | 2017-05-03 14:36:54 -0400 | [diff] [blame] | 1760 | attribState = fHWVertexArrayState.bindInternalVertexArray(this, indexBuffer); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 1761 | } else { |
| 1762 | attribState = fHWVertexArrayState.bindInternalVertexArray(this); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1763 | } |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1764 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1765 | int numAttribs = fHWProgram->numVertexAttributes() + fHWProgram->numInstanceAttributes(); |
| 1766 | attribState->enableVertexArrays(this, numAttribs, enablePrimitiveRestart); |
Chris Dalton | 8e45b4f | 2017-05-05 14:00:56 -0400 | [diff] [blame] | 1767 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 1768 | if (int vertexStride = fHWProgram->vertexStride()) { |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 1769 | SkASSERT(vertexBuffer); |
| 1770 | SkASSERT(vertexBuffer->isCpuBuffer() || |
| 1771 | !static_cast<const GrGpuBuffer*>(vertexBuffer)->isMapped()); |
| 1772 | size_t bufferOffset = baseVertex * static_cast<size_t>(vertexStride); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1773 | for (int i = 0; i < fHWProgram->numVertexAttributes(); ++i) { |
| 1774 | const auto& attrib = fHWProgram->vertexAttribute(i); |
| 1775 | static constexpr int kDivisor = 0; |
Brian Osman | 4a3f5c8 | 2018-09-18 16:16:38 -0400 | [diff] [blame] | 1776 | attribState->set(this, attrib.fLocation, vertexBuffer, attrib.fCPUType, attrib.fGPUType, |
| 1777 | vertexStride, bufferOffset + attrib.fOffset, kDivisor); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1778 | } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 1779 | } |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 1780 | if (int instanceStride = fHWProgram->instanceStride()) { |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 1781 | SkASSERT(instanceBuffer); |
| 1782 | SkASSERT(instanceBuffer->isCpuBuffer() || |
| 1783 | !static_cast<const GrGpuBuffer*>(instanceBuffer)->isMapped()); |
| 1784 | size_t bufferOffset = baseInstance * static_cast<size_t>(instanceStride); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1785 | int attribIdx = fHWProgram->numVertexAttributes(); |
| 1786 | for (int i = 0; i < fHWProgram->numInstanceAttributes(); ++i, ++attribIdx) { |
| 1787 | const auto& attrib = fHWProgram->instanceAttribute(i); |
| 1788 | static constexpr int kDivisor = 1; |
Brian Osman | 4a3f5c8 | 2018-09-18 16:16:38 -0400 | [diff] [blame] | 1789 | attribState->set(this, attrib.fLocation, instanceBuffer, attrib.fCPUType, |
| 1790 | attrib.fGPUType, instanceStride, bufferOffset + attrib.fOffset, |
| 1791 | kDivisor); |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 1792 | } |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 1796 | GrGLenum GrGLGpu::bindBuffer(GrGpuBufferType type, const GrBuffer* buffer) { |
joshualitt | 93316b9 | 2015-10-23 09:08:08 -0700 | [diff] [blame] | 1797 | this->handleDirtyContext(); |
cdalton | deacc97 | 2016-04-06 14:26:33 -0700 | [diff] [blame] | 1798 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 1799 | // Index buffer state is tied to the vertex array. |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 1800 | if (GrGpuBufferType::kIndex == type) { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 1801 | this->bindVertexArray(0); |
cdalton | deacc97 | 2016-04-06 14:26:33 -0700 | [diff] [blame] | 1802 | } |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 1803 | |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 1804 | auto* bufferState = this->hwBufferState(type); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 1805 | if (buffer->isCpuBuffer()) { |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 1806 | if (!bufferState->fBufferZeroKnownBound) { |
| 1807 | GL_CALL(BindBuffer(bufferState->fGLTarget, 0)); |
| 1808 | bufferState->fBufferZeroKnownBound = true; |
| 1809 | bufferState->fBoundBufferUniqueID.makeInvalid(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 1810 | } |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 1811 | } else if (static_cast<const GrGpuBuffer*>(buffer)->uniqueID() != |
| 1812 | bufferState->fBoundBufferUniqueID) { |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 1813 | const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(buffer); |
| 1814 | GL_CALL(BindBuffer(bufferState->fGLTarget, glBuffer->bufferID())); |
| 1815 | bufferState->fBufferZeroKnownBound = false; |
| 1816 | bufferState->fBoundBufferUniqueID = glBuffer->uniqueID(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 1819 | return bufferState->fGLTarget; |
joshualitt | 93316b9 | 2015-10-23 09:08:08 -0700 | [diff] [blame] | 1820 | } |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1821 | void GrGLGpu::disableScissor() { |
| 1822 | if (kNo_TriState != fHWScissorSettings.fEnabled) { |
| 1823 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
| 1824 | fHWScissorSettings.fEnabled = kNo_TriState; |
| 1825 | return; |
| 1826 | } |
| 1827 | } |
| 1828 | |
Brian Osman | 9a9baae | 2018-11-05 15:06:26 -0500 | [diff] [blame] | 1829 | void GrGLGpu::clear(const GrFixedClip& clip, const SkPMColor4f& color, |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 1830 | GrRenderTarget* target, GrSurfaceOrigin origin) { |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1831 | // parent class should never let us get here with no RT |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1832 | SkASSERT(target); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 1833 | SkASSERT(!this->caps()->performColorClearsAsDraws()); |
| 1834 | SkASSERT(!clip.scissorEnabled() || !this->caps()->performPartialClearsAsDraws()); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1835 | |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 1836 | this->handleDirtyContext(); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1837 | |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 1838 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
| 1839 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1840 | if (clip.scissorEnabled()) { |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 1841 | this->flushRenderTarget(glRT, origin, clip.scissorRect()); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 1842 | } else { |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 1843 | this->flushRenderTarget(glRT); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 1844 | } |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 1845 | this->flushScissor(clip.scissorState(), glRT->width(), glRT->height(), origin); |
Brian Salomon | 43f8bf0 | 2017-10-18 08:33:29 -0400 | [diff] [blame] | 1846 | this->flushWindowRectangles(clip.windowRectsState(), glRT, origin); |
Brian Salomon | 805cc7a | 2019-01-28 09:52:34 -0500 | [diff] [blame] | 1847 | this->flushColorWrite(true); |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 1848 | |
| 1849 | GrGLfloat r = color.fR, g = color.fG, b = color.fB, a = color.fA; |
| 1850 | if (this->glCaps().clearToBoundaryValuesIsBroken() && |
| 1851 | (1 == r || 0 == r) && (1 == g || 0 == g) && (1 == b || 0 == b) && (1 == a || 0 == a)) { |
| 1852 | static const GrGLfloat safeAlpha1 = nextafter(1.f, 2.f); |
| 1853 | static const GrGLfloat safeAlpha0 = nextafter(0.f, -1.f); |
| 1854 | a = (1 == a) ? safeAlpha1 : safeAlpha0; |
| 1855 | } |
| 1856 | this->flushClearColor(r, g, b, a); |
| 1857 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1858 | GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 1861 | void GrGLGpu::clearStencil(GrRenderTarget* target, int clearValue) { |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 1862 | SkASSERT(!this->caps()->performStencilClearsAsDraws()); |
| 1863 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 1864 | if (!target) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1865 | return; |
| 1866 | } |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 1867 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 1868 | GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment(); |
| 1869 | // this should only be called internally when we know we have a |
| 1870 | // stencil buffer. |
| 1871 | SkASSERT(sb); |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 1872 | |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1873 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 1874 | this->flushRenderTargetNoColorWrites(glRT); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1875 | |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 1876 | this->disableScissor(); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 1877 | this->disableWindowRectangles(); |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 1878 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1879 | GL_CALL(StencilMask(0xffffffff)); |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 1880 | GL_CALL(ClearStencil(clearValue)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1881 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1882 | fHWStencilSettings.invalidate(); |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 1883 | if (!clearValue) { |
| 1884 | sb->cleared(); |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 1885 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 1888 | void GrGLGpu::clearStencilClip(const GrFixedClip& clip, |
| 1889 | bool insideStencilMask, |
Robert Phillips | 19e51dc | 2017-08-09 09:30:51 -0400 | [diff] [blame] | 1890 | GrRenderTarget* target, GrSurfaceOrigin origin) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1891 | SkASSERT(target); |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 1892 | SkASSERT(!this->caps()->performStencilClearsAsDraws()); |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 1893 | this->handleDirtyContext(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1894 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1895 | GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1896 | // this should only be called internally when we know we have a |
| 1897 | // stencil buffer. |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 1898 | SkASSERT(sb); |
| 1899 | GrGLint stencilBitCount = sb->bits(); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1900 | #if 0 |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1901 | SkASSERT(stencilBitCount > 0); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1902 | GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1903 | #else |
| 1904 | // we could just clear the clip bit but when we go through |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1905 | // ANGLE a partial stencil mask will cause clears to be |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 1906 | // turned into draws. Our contract on GrOpsTask says that |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1907 | // changing the clip between stencil passes may or may not |
| 1908 | // zero the client's clip bits. So we just clear the whole thing. |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1909 | static const GrGLint clipStencilMask = ~0; |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1910 | #endif |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1911 | GrGLint value; |
csmartdalton | 29df760 | 2016-08-31 11:55:52 -0700 | [diff] [blame] | 1912 | if (insideStencilMask) { |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1913 | value = (1 << (stencilBitCount - 1)); |
| 1914 | } else { |
| 1915 | value = 0; |
| 1916 | } |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1917 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 1918 | this->flushRenderTargetNoColorWrites(glRT); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1919 | |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 1920 | this->flushScissor(clip.scissorState(), glRT->width(), glRT->height(), origin); |
Robert Phillips | b0e93a2 | 2017-08-29 08:26:54 -0400 | [diff] [blame] | 1921 | this->flushWindowRectangles(clip.windowRectsState(), glRT, origin); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1922 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1923 | GL_CALL(StencilMask((uint32_t) clipStencilMask)); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1924 | GL_CALL(ClearStencil(value)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1925 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1926 | fHWStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 1929 | bool GrGLGpu::readOrTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 1930 | GrColorType surfaceColorType, GrColorType dstColorType, |
| 1931 | void* offsetOrPtr, int rowWidthInPixels) { |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 1932 | SkASSERT(surface); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 1933 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 1934 | auto format = surface->backendFormat().asGLFormat(); |
bsalomon | e957331 | 2016-01-25 14:33:25 -0800 | [diff] [blame] | 1935 | GrGLRenderTarget* renderTarget = static_cast<GrGLRenderTarget*>(surface->asRenderTarget()); |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 1936 | if (!renderTarget && !this->glCaps().isFormatRenderable(format, 1)) { |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 1937 | return false; |
| 1938 | } |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1939 | GrGLenum externalFormat = 0; |
| 1940 | GrGLenum externalType = 0; |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 1941 | this->glCaps().getReadPixelsFormat(surface->backendFormat().asGLFormat(), |
| 1942 | surfaceColorType, |
| 1943 | dstColorType, |
| 1944 | &externalFormat, |
| 1945 | &externalType); |
Greg Daniel | ba88ab6 | 2019-07-26 09:14:01 -0400 | [diff] [blame] | 1946 | if (!externalFormat || !externalType) { |
bsalomon | 76148af | 2016-01-12 11:13:47 -0800 | [diff] [blame] | 1947 | return false; |
| 1948 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1949 | |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1950 | if (renderTarget) { |
| 1951 | // resolve the render target if necessary |
| 1952 | switch (renderTarget->getResolveType()) { |
| 1953 | case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1954 | return false; |
| 1955 | case GrGLRenderTarget::kAutoResolves_ResolveType: |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 1956 | this->flushRenderTargetNoColorWrites(renderTarget); |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1957 | break; |
| 1958 | case GrGLRenderTarget::kCanResolve_ResolveType: |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 1959 | this->onResolveRenderTarget(renderTarget); |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1960 | // we don't track the state of the READ FBO ID. |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 1961 | this->bindFramebuffer(GR_GL_READ_FRAMEBUFFER, renderTarget->textureFBOID()); |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1962 | break; |
| 1963 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 1964 | SK_ABORT("Unknown resolve type"); |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1965 | } |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 1966 | } else { |
| 1967 | // Use a temporary FBO. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 1968 | this->bindSurfaceFBOForPixelOps(surface, 0, GR_GL_FRAMEBUFFER, kSrc_TempFBOTarget); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 1969 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1970 | } |
| 1971 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1972 | // the read rect is viewport-relative |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 1973 | GrNativeRect readRect = {left, top, width, height}; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1974 | |
Brian Salomon | a694870 | 2018-06-01 15:33:20 -0400 | [diff] [blame] | 1975 | // determine if GL can read using the passed rowBytes or if we need a scratch buffer. |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 1976 | if (rowWidthInPixels != width) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 1977 | SkASSERT(this->glCaps().readPixelsRowBytesSupport()); |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 1978 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, rowWidthInPixels)); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1979 | } |
Brian Salomon | 8cbf662 | 2019-07-30 11:03:14 -0400 | [diff] [blame] | 1980 | GL_CALL(PixelStorei(GR_GL_PACK_ALIGNMENT, 1)); |
bsalomon | f46a124 | 2015-12-15 12:37:38 -0800 | [diff] [blame] | 1981 | |
Brian Osman | 1348ed0 | 2018-09-12 09:08:39 -0400 | [diff] [blame] | 1982 | bool reattachStencil = false; |
| 1983 | if (this->glCaps().detachStencilFromMSAABuffersBeforeReadPixels() && |
| 1984 | renderTarget && |
| 1985 | renderTarget->renderTargetPriv().getStencilAttachment() && |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 1986 | renderTarget->numSamples() > 1) { |
Brian Osman | 1348ed0 | 2018-09-12 09:08:39 -0400 | [diff] [blame] | 1987 | // Fix Adreno devices that won't read from MSAA framebuffers with stencil attached |
| 1988 | reattachStencil = true; |
| 1989 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, |
| 1990 | GR_GL_RENDERBUFFER, 0)); |
| 1991 | } |
| 1992 | |
Chris Dalton | 76500e5 | 2019-09-05 02:13:05 -0600 | [diff] [blame] | 1993 | GL_CALL(ReadPixels(readRect.fX, readRect.fY, readRect.fWidth, readRect.fHeight, |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 1994 | externalFormat, externalType, offsetOrPtr)); |
Brian Osman | 1348ed0 | 2018-09-12 09:08:39 -0400 | [diff] [blame] | 1995 | |
| 1996 | if (reattachStencil) { |
| 1997 | GrGLStencilAttachment* stencilAttachment = static_cast<GrGLStencilAttachment*>( |
| 1998 | renderTarget->renderTargetPriv().getStencilAttachment()); |
| 1999 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, |
| 2000 | GR_GL_RENDERBUFFER, stencilAttachment->renderbufferID())); |
| 2001 | } |
| 2002 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 2003 | if (rowWidthInPixels != width) { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 2004 | SkASSERT(this->glCaps().readPixelsRowBytesSupport()); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 2005 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 2006 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2007 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 2008 | if (!renderTarget) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 2009 | this->unbindSurfaceFBOForPixelOps(surface, 0, GR_GL_FRAMEBUFFER); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 2010 | } |
| 2011 | return true; |
| 2012 | } |
| 2013 | |
| 2014 | bool GrGLGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 2015 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
| 2016 | size_t rowBytes) { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 2017 | SkASSERT(surface); |
| 2018 | |
Brian Salomon | b28cb68 | 2019-07-26 12:48:47 -0400 | [diff] [blame] | 2019 | size_t bytesPerPixel = GrColorTypeBytesPerPixel(dstColorType); |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 2020 | |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 2021 | // GL_PACK_ROW_LENGTH is in terms of pixels not bytes. |
| 2022 | int rowPixelWidth; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 2023 | |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 2024 | if (rowBytes == SkToSizeT(width * bytesPerPixel)) { |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 2025 | rowPixelWidth = width; |
| 2026 | } else { |
Brian Salomon | 1047a49 | 2019-07-02 12:25:21 -0400 | [diff] [blame] | 2027 | SkASSERT(!(rowBytes % bytesPerPixel)); |
| 2028 | rowPixelWidth = rowBytes / bytesPerPixel; |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 2029 | } |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 2030 | return this->readOrTransferPixelsFrom(surface, left, top, width, height, surfaceColorType, |
| 2031 | dstColorType, buffer, rowPixelWidth); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2032 | } |
| 2033 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 2034 | GrOpsRenderPass* GrGLGpu::getOpsRenderPass( |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 2035 | GrRenderTarget* rt, GrSurfaceOrigin origin, const SkRect& bounds, |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 2036 | const GrOpsRenderPass::LoadAndStoreInfo& colorInfo, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 2037 | const GrOpsRenderPass::StencilLoadAndStoreInfo& stencilInfo, |
| 2038 | const SkTArray<GrTextureProxy*, true>& sampledProxies) { |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 2039 | if (!fCachedOpsRenderPass) { |
| 2040 | fCachedOpsRenderPass.reset(new GrGLOpsRenderPass(this)); |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 2041 | } |
| 2042 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 2043 | fCachedOpsRenderPass->set(rt, origin, colorInfo, stencilInfo); |
| 2044 | return fCachedOpsRenderPass.get(); |
egdaniel | 066df7c | 2016-06-08 14:02:27 -0700 | [diff] [blame] | 2045 | } |
| 2046 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 2047 | void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, GrSurfaceOrigin origin, |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 2048 | const SkIRect& bounds) { |
Brian Osman | 9aa30c6 | 2018-07-02 15:21:46 -0400 | [diff] [blame] | 2049 | this->flushRenderTargetNoColorWrites(target); |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 2050 | this->didWriteToSurface(target, origin, &bounds); |
| 2051 | } |
bsalomon | 6ba6fa1 | 2015-03-04 11:57:37 -0800 | [diff] [blame] | 2052 | |
Chris Dalton | c8ece3d | 2018-07-30 15:03:45 -0600 | [diff] [blame] | 2053 | void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target) { |
| 2054 | this->flushRenderTargetNoColorWrites(target); |
| 2055 | this->didWriteToSurface(target, kTopLeft_GrSurfaceOrigin, nullptr); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 2056 | } |
| 2057 | |
Brian Osman | 9aa30c6 | 2018-07-02 15:21:46 -0400 | [diff] [blame] | 2058 | void GrGLGpu::flushRenderTargetNoColorWrites(GrGLRenderTarget* target) { |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 2059 | SkASSERT(target); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 2060 | GrGpuResource::UniqueID rtID = target->uniqueID(); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2061 | if (fHWBoundRenderTargetUniqueID != rtID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 2062 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID()); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2063 | #ifdef SK_DEBUG |
| 2064 | // don't do this check in Chromium -- this is causing |
| 2065 | // lots of repeated command buffer flushes when the compositor is |
| 2066 | // rendering with Ganesh, which is really slow; even too slow for |
| 2067 | // Debug mode. |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 2068 | if (kChromium_GrGLDriver != this->glContext().driver()) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2069 | GrGLenum status; |
| 2070 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 2071 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 2072 | SkDebugf("GrGLGpu::flushRenderTarget glCheckFramebufferStatus %x\n", status); |
| 2073 | } |
bsalomon | 160f24c | 2015-03-17 15:55:42 -0700 | [diff] [blame] | 2074 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2075 | #endif |
| 2076 | fHWBoundRenderTargetUniqueID = rtID; |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 2077 | this->flushViewport(target->width(), target->height()); |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
brianosman | 35b784d | 2016-05-05 11:52:53 -0700 | [diff] [blame] | 2080 | if (this->glCaps().srgbWriteControl()) { |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 2081 | this->flushFramebufferSRGB(this->caps()->isFormatSRGB(target->backendFormat())); |
bsalomon | 5cd020f | 2015-03-17 12:46:56 -0700 | [diff] [blame] | 2082 | } |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 2083 | } |
bsalomon | a990912 | 2016-01-23 10:41:40 -0800 | [diff] [blame] | 2084 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 2085 | void GrGLGpu::flushFramebufferSRGB(bool enable) { |
| 2086 | if (enable && kYes_TriState != fHWSRGBFramebuffer) { |
| 2087 | GL_CALL(Enable(GR_GL_FRAMEBUFFER_SRGB)); |
| 2088 | fHWSRGBFramebuffer = kYes_TriState; |
| 2089 | } else if (!enable && kNo_TriState != fHWSRGBFramebuffer) { |
| 2090 | GL_CALL(Disable(GR_GL_FRAMEBUFFER_SRGB)); |
| 2091 | fHWSRGBFramebuffer = kNo_TriState; |
| 2092 | } |
| 2093 | } |
| 2094 | |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 2095 | void GrGLGpu::flushViewport(int width, int height) { |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 2096 | GrNativeRect viewport = {0, 0, width, height}; |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 2097 | if (fHWViewport != viewport) { |
Chris Dalton | 76500e5 | 2019-09-05 02:13:05 -0600 | [diff] [blame] | 2098 | GL_CALL(Viewport(viewport.fX, viewport.fY, viewport.fWidth, viewport.fHeight)); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 2099 | fHWViewport = viewport; |
| 2100 | } |
| 2101 | } |
| 2102 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2103 | #define SWAP_PER_DRAW 0 |
| 2104 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 2105 | #if SWAP_PER_DRAW |
commit-bot@chromium.org | 4382330 | 2013-09-25 20:57:51 +0000 | [diff] [blame] | 2106 | #if defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2107 | #include <AGL/agl.h> |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 2108 | #elif defined(SK_BUILD_FOR_WIN) |
bsalomon@google.com | ce7357d | 2012-06-25 17:49:25 +0000 | [diff] [blame] | 2109 | #include <gl/GL.h> |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2110 | void SwapBuf() { |
| 2111 | DWORD procID = GetCurrentProcessId(); |
| 2112 | HWND hwnd = GetTopWindow(GetDesktopWindow()); |
| 2113 | while(hwnd) { |
| 2114 | DWORD wndProcID = 0; |
| 2115 | GetWindowThreadProcessId(hwnd, &wndProcID); |
| 2116 | if(wndProcID == procID) { |
| 2117 | SwapBuffers(GetDC(hwnd)); |
| 2118 | } |
| 2119 | hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
| 2120 | } |
| 2121 | } |
| 2122 | #endif |
| 2123 | #endif |
| 2124 | |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 2125 | void GrGLGpu::draw(GrRenderTarget* renderTarget, GrSurfaceOrigin origin, |
| 2126 | const GrPrimitiveProcessor& primProc, |
Brian Salomon | ff168d9 | 2018-06-23 15:17:27 -0400 | [diff] [blame] | 2127 | const GrPipeline& pipeline, |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 2128 | const GrPipeline::FixedDynamicState* fixedDynamicState, |
| 2129 | const GrPipeline::DynamicStateArrays* dynamicStateArrays, |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 2130 | const GrMesh meshes[], |
egdaniel | 9cb6340 | 2016-06-23 08:37:05 -0700 | [diff] [blame] | 2131 | int meshCount) { |
| 2132 | this->handleDirtyContext(); |
| 2133 | |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 2134 | bool hasPoints = false; |
| 2135 | for (int i = 0; i < meshCount; ++i) { |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 2136 | if (meshes[i].primitiveType() == GrPrimitiveType::kPoints) { |
bsalomon | 2eda5b3 | 2016-09-21 10:53:24 -0700 | [diff] [blame] | 2137 | hasPoints = true; |
| 2138 | break; |
| 2139 | } |
| 2140 | } |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 2141 | if (!this->flushGLState(renderTarget, origin, primProc, pipeline, fixedDynamicState, |
| 2142 | dynamicStateArrays, meshCount, hasPoints)) { |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 2143 | return; |
| 2144 | } |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 2145 | |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 2146 | bool dynamicScissor = false; |
| 2147 | bool dynamicPrimProcTextures = false; |
| 2148 | if (dynamicStateArrays) { |
| 2149 | dynamicScissor = pipeline.isScissorEnabled() && dynamicStateArrays->fScissorRects; |
| 2150 | dynamicPrimProcTextures = dynamicStateArrays->fPrimitiveProcessorTextures; |
| 2151 | } |
| 2152 | for (int m = 0; m < meshCount; ++m) { |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 2153 | if (GrXferBarrierType barrierType = pipeline.xferBarrierType(renderTarget->asTexture(), |
| 2154 | *this->caps())) { |
| 2155 | this->xferBarrier(renderTarget, barrierType); |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 2156 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2157 | |
Brian Salomon | 4934890 | 2018-06-26 09:12:38 -0400 | [diff] [blame] | 2158 | if (dynamicScissor) { |
Robert Phillips | d0fe875 | 2019-01-31 14:13:59 -0500 | [diff] [blame] | 2159 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 2160 | this->flushScissor(GrScissorState(dynamicStateArrays->fScissorRects[m]), |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 2161 | glRT->width(), glRT->height(), origin); |
Chris Dalton | 46983b7 | 2017-06-06 12:27:16 -0600 | [diff] [blame] | 2162 | } |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 2163 | if (dynamicPrimProcTextures) { |
| 2164 | auto texProxyArray = dynamicStateArrays->fPrimitiveProcessorTextures + |
| 2165 | m * primProc.numTextureSamplers(); |
| 2166 | fHWProgram->updatePrimitiveProcessorTextureBindings(primProc, texProxyArray); |
| 2167 | } |
Brian Salomon | 6d9c88b | 2017-06-12 10:24:42 -0400 | [diff] [blame] | 2168 | if (this->glCaps().requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() && |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 2169 | GrIsPrimTypeLines(meshes[m].primitiveType()) && |
Brian Salomon | 6d9c88b | 2017-06-12 10:24:42 -0400 | [diff] [blame] | 2170 | !GrIsPrimTypeLines(fLastPrimitiveType)) { |
| 2171 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2172 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
| 2173 | } |
Brian Salomon | f723264 | 2018-09-19 08:58:08 -0400 | [diff] [blame] | 2174 | meshes[m].sendToGpu(this); |
| 2175 | fLastPrimitiveType = meshes[m].primitiveType(); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 2176 | } |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 2177 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2178 | #if SWAP_PER_DRAW |
| 2179 | glFlush(); |
commit-bot@chromium.org | 4382330 | 2013-09-25 20:57:51 +0000 | [diff] [blame] | 2180 | #if defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2181 | aglSwapBuffers(aglGetCurrentContext()); |
| 2182 | int set_a_break_pt_here = 9; |
| 2183 | aglSwapBuffers(aglGetCurrentContext()); |
Mike Klein | 8f11d4d | 2018-01-24 12:42:55 -0500 | [diff] [blame] | 2184 | #elif defined(SK_BUILD_FOR_WIN) |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2185 | SwapBuf(); |
| 2186 | int set_a_break_pt_here = 9; |
| 2187 | SwapBuf(); |
| 2188 | #endif |
| 2189 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 2192 | static GrGLenum gr_primitive_type_to_gl_mode(GrPrimitiveType primitiveType) { |
| 2193 | switch (primitiveType) { |
| 2194 | case GrPrimitiveType::kTriangles: |
| 2195 | return GR_GL_TRIANGLES; |
| 2196 | case GrPrimitiveType::kTriangleStrip: |
| 2197 | return GR_GL_TRIANGLE_STRIP; |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 2198 | case GrPrimitiveType::kPoints: |
| 2199 | return GR_GL_POINTS; |
| 2200 | case GrPrimitiveType::kLines: |
| 2201 | return GR_GL_LINES; |
| 2202 | case GrPrimitiveType::kLineStrip: |
| 2203 | return GR_GL_LINE_STRIP; |
| 2204 | case GrPrimitiveType::kLinesAdjacency: |
| 2205 | return GR_GL_LINES_ADJACENCY; |
| 2206 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 2207 | SK_ABORT("invalid GrPrimitiveType"); |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 2208 | } |
| 2209 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2210 | void GrGLGpu::sendMeshToGpu(GrPrimitiveType primitiveType, const GrBuffer* vertexBuffer, |
| 2211 | int vertexCount, int baseVertex) { |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 2212 | const GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2213 | if (this->glCaps().drawArraysBaseVertexIsBroken()) { |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2214 | this->setupGeometry(nullptr, vertexBuffer, baseVertex, nullptr, 0, GrPrimitiveRestart::kNo); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2215 | GL_CALL(DrawArrays(glPrimType, 0, vertexCount)); |
| 2216 | } else { |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2217 | this->setupGeometry(nullptr, vertexBuffer, 0, nullptr, 0, GrPrimitiveRestart::kNo); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2218 | GL_CALL(DrawArrays(glPrimType, baseVertex, vertexCount)); |
| 2219 | } |
| 2220 | fStats.incNumDraws(); |
| 2221 | } |
| 2222 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 2223 | static const GrGLvoid* element_ptr(const GrBuffer* indexBuffer, int baseIndex) { |
| 2224 | size_t baseOffset = baseIndex * sizeof(uint16_t); |
| 2225 | if (indexBuffer->isCpuBuffer()) { |
| 2226 | return static_cast<const GrCpuBuffer*>(indexBuffer)->data() + baseOffset; |
| 2227 | } else { |
| 2228 | return reinterpret_cast<const GrGLvoid*>(baseOffset); |
| 2229 | } |
| 2230 | } |
| 2231 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2232 | void GrGLGpu::sendIndexedMeshToGpu(GrPrimitiveType primitiveType, const GrBuffer* indexBuffer, |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2233 | int indexCount, int baseIndex, uint16_t minIndexValue, |
| 2234 | uint16_t maxIndexValue, const GrBuffer* vertexBuffer, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2235 | int baseVertex, GrPrimitiveRestart enablePrimitiveRestart) { |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 2236 | const GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 2237 | const GrGLvoid* elementPtr = element_ptr(indexBuffer, baseIndex); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2238 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2239 | this->setupGeometry(indexBuffer, vertexBuffer, baseVertex, nullptr, 0, enablePrimitiveRestart); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2240 | |
| 2241 | if (this->glCaps().drawRangeElementsSupport()) { |
| 2242 | GL_CALL(DrawRangeElements(glPrimType, minIndexValue, maxIndexValue, indexCount, |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 2243 | GR_GL_UNSIGNED_SHORT, elementPtr)); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2244 | } else { |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 2245 | GL_CALL(DrawElements(glPrimType, indexCount, GR_GL_UNSIGNED_SHORT, elementPtr)); |
Chris Dalton | 114a3c0 | 2017-05-26 15:17:19 -0600 | [diff] [blame] | 2246 | } |
| 2247 | fStats.incNumDraws(); |
| 2248 | } |
| 2249 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2250 | void GrGLGpu::sendInstancedMeshToGpu(GrPrimitiveType primitiveType, const GrBuffer* vertexBuffer, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 2251 | int vertexCount, int baseVertex, |
| 2252 | const GrBuffer* instanceBuffer, int instanceCount, |
| 2253 | int baseInstance) { |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 2254 | GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType); |
Chris Dalton | 1b4ad76 | 2018-10-04 11:58:09 -0600 | [diff] [blame] | 2255 | int maxInstances = this->glCaps().maxInstancesPerDrawWithoutCrashing(instanceCount); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 2256 | for (int i = 0; i < instanceCount; i += maxInstances) { |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2257 | this->setupGeometry(nullptr, vertexBuffer, 0, instanceBuffer, baseInstance + i, |
| 2258 | GrPrimitiveRestart::kNo); |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 2259 | GL_CALL(DrawArraysInstanced(glPrimType, baseVertex, vertexCount, |
| 2260 | SkTMin(instanceCount - i, maxInstances))); |
| 2261 | fStats.incNumDraws(); |
| 2262 | } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 2263 | } |
| 2264 | |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2265 | void GrGLGpu::sendIndexedInstancedMeshToGpu(GrPrimitiveType primitiveType, |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 2266 | const GrBuffer* indexBuffer, int indexCount, |
| 2267 | int baseIndex, const GrBuffer* vertexBuffer, |
| 2268 | int baseVertex, const GrBuffer* instanceBuffer, |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 2269 | int instanceCount, int baseInstance, |
| 2270 | GrPrimitiveRestart enablePrimitiveRestart) { |
Chris Dalton | 3809bab | 2017-06-13 10:55:06 -0600 | [diff] [blame] | 2271 | const GrGLenum glPrimType = gr_primitive_type_to_gl_mode(primitiveType); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 2272 | const GrGLvoid* elementPtr = element_ptr(indexBuffer, baseIndex); |
Chris Dalton | 1b4ad76 | 2018-10-04 11:58:09 -0600 | [diff] [blame] | 2273 | int maxInstances = this->glCaps().maxInstancesPerDrawWithoutCrashing(instanceCount); |
| 2274 | for (int i = 0; i < instanceCount; i += maxInstances) { |
| 2275 | this->setupGeometry(indexBuffer, vertexBuffer, baseVertex, instanceBuffer, baseInstance + i, |
| 2276 | enablePrimitiveRestart); |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 2277 | GL_CALL(DrawElementsInstanced(glPrimType, indexCount, GR_GL_UNSIGNED_SHORT, elementPtr, |
Chris Dalton | 1b4ad76 | 2018-10-04 11:58:09 -0600 | [diff] [blame] | 2278 | SkTMin(instanceCount - i, maxInstances))); |
| 2279 | fStats.incNumDraws(); |
| 2280 | } |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 2281 | } |
| 2282 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 2283 | void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 2284 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 2285 | if (rt->needsResolve()) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 2286 | // Some extensions automatically resolves the texture when it is read. |
| 2287 | if (this->glCaps().usesMSAARenderBuffers()) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2288 | SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
Brian Osman | cfe83d1 | 2018-01-19 11:13:45 -0500 | [diff] [blame] | 2289 | SkASSERT(rt->textureFBOID() != 0 && rt->renderFBOID() != 0); |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 2290 | this->bindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID()); |
| 2291 | this->bindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()); |
| 2292 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2293 | // make sure we go through flushRenderTarget() since we've modified |
| 2294 | // the bound DRAW FBO ID. |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 2295 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 2296 | const SkIRect dirtyRect = rt->getResolveRect(); |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 2297 | // The dirty rect tracked on the RT is always stored in the native coordinates of the |
| 2298 | // surface. Choose kTopLeft so no adjustments are made |
| 2299 | static constexpr auto kDirtyRectOrigin = kTopLeft_GrSurfaceOrigin; |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 2300 | if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 2301 | // Apple's extension uses the scissor as the blit bounds. |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 2302 | GrScissorState scissorState; |
| 2303 | scissorState.set(dirtyRect); |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 2304 | this->flushScissor(scissorState, rt->width(), rt->height(), kDirtyRectOrigin); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 2305 | this->disableWindowRectangles(); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 2306 | GL_CALL(ResolveMultisampleFramebuffer()); |
| 2307 | } else { |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 2308 | int l, b, r, t; |
| 2309 | if (GrGLCaps::kResolveMustBeFull_BlitFrambufferFlag & |
| 2310 | this->glCaps().blitFramebufferSupportFlags()) { |
| 2311 | l = 0; |
| 2312 | b = 0; |
| 2313 | r = target->width(); |
| 2314 | t = target->height(); |
| 2315 | } else { |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 2316 | auto rect = GrNativeRect::MakeRelativeTo( |
Chris Dalton | 76500e5 | 2019-09-05 02:13:05 -0600 | [diff] [blame] | 2317 | kDirtyRectOrigin, rt->height(), dirtyRect); |
| 2318 | l = rect.fX; |
| 2319 | b = rect.fY; |
| 2320 | r = rect.fX + rect.fWidth; |
| 2321 | t = rect.fY + rect.fHeight; |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 2322 | } |
derekf | 8c8f71a | 2014-09-16 06:24:57 -0700 | [diff] [blame] | 2323 | |
| 2324 | // BlitFrameBuffer respects the scissor, so disable it. |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 2325 | this->disableScissor(); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 2326 | this->disableWindowRectangles(); |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 2327 | GL_CALL(BlitFramebuffer(l, b, r, t, l, b, r, t, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 2328 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 2329 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2330 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 2331 | rt->flagAsResolved(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2335 | namespace { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2336 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2337 | |
| 2338 | GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 2339 | static const GrGLenum gTable[kGrStencilOpCount] = { |
| 2340 | GR_GL_KEEP, // kKeep |
| 2341 | GR_GL_ZERO, // kZero |
| 2342 | GR_GL_REPLACE, // kReplace |
| 2343 | GR_GL_INVERT, // kInvert |
| 2344 | GR_GL_INCR_WRAP, // kIncWrap |
| 2345 | GR_GL_DECR_WRAP, // kDecWrap |
| 2346 | GR_GL_INCR, // kIncClamp |
| 2347 | GR_GL_DECR, // kDecClamp |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2348 | }; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 2349 | GR_STATIC_ASSERT(0 == (int)GrStencilOp::kKeep); |
| 2350 | GR_STATIC_ASSERT(1 == (int)GrStencilOp::kZero); |
| 2351 | GR_STATIC_ASSERT(2 == (int)GrStencilOp::kReplace); |
| 2352 | GR_STATIC_ASSERT(3 == (int)GrStencilOp::kInvert); |
| 2353 | GR_STATIC_ASSERT(4 == (int)GrStencilOp::kIncWrap); |
| 2354 | GR_STATIC_ASSERT(5 == (int)GrStencilOp::kDecWrap); |
| 2355 | GR_STATIC_ASSERT(6 == (int)GrStencilOp::kIncClamp); |
| 2356 | GR_STATIC_ASSERT(7 == (int)GrStencilOp::kDecClamp); |
| 2357 | SkASSERT(op < (GrStencilOp)kGrStencilOpCount); |
| 2358 | return gTable[(int)op]; |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | void set_gl_stencil(const GrGLInterface* gl, |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 2362 | const GrStencilSettings::Face& face, |
| 2363 | GrGLenum glFace) { |
| 2364 | GrGLenum glFunc = GrToGLStencilFunc(face.fTest); |
| 2365 | GrGLenum glFailOp = gr_to_gl_stencil_op(face.fFailOp); |
| 2366 | GrGLenum glPassOp = gr_to_gl_stencil_op(face.fPassOp); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2367 | |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 2368 | GrGLint ref = face.fRef; |
| 2369 | GrGLint mask = face.fTestMask; |
| 2370 | GrGLint writeMask = face.fWriteMask; |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2371 | |
| 2372 | if (GR_GL_FRONT_AND_BACK == glFace) { |
| 2373 | // we call the combined func just in case separate stencil is not |
| 2374 | // supported. |
| 2375 | GR_GL_CALL(gl, StencilFunc(glFunc, ref, mask)); |
| 2376 | GR_GL_CALL(gl, StencilMask(writeMask)); |
vbuzinov | c5d58f0 | 2015-08-21 05:24:24 -0700 | [diff] [blame] | 2377 | GR_GL_CALL(gl, StencilOp(glFailOp, GR_GL_KEEP, glPassOp)); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2378 | } else { |
| 2379 | GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); |
| 2380 | GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); |
vbuzinov | c5d58f0 | 2015-08-21 05:24:24 -0700 | [diff] [blame] | 2381 | GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, GR_GL_KEEP, glPassOp)); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2385 | |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 2386 | void GrGLGpu::flushStencil(const GrStencilSettings& stencilSettings, GrSurfaceOrigin origin) { |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 2387 | if (stencilSettings.isDisabled()) { |
| 2388 | this->disableStencil(); |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 2389 | } else if (fHWStencilSettings != stencilSettings || |
| 2390 | (stencilSettings.isTwoSided() && fHWStencilOrigin != origin)) { |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 2391 | if (kYes_TriState != fHWStencilTestEnabled) { |
| 2392 | GL_CALL(Enable(GR_GL_STENCIL_TEST)); |
Brian Salomon | af971de | 2017-06-08 16:11:33 -0400 | [diff] [blame] | 2393 | |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 2394 | fHWStencilTestEnabled = kYes_TriState; |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2395 | } |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 2396 | if (stencilSettings.isTwoSided()) { |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 2397 | set_gl_stencil(this->glInterface(), stencilSettings.front(origin), GR_GL_FRONT); |
| 2398 | set_gl_stencil(this->glInterface(), stencilSettings.back(origin), GR_GL_BACK); |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 2399 | } else { |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 2400 | set_gl_stencil( |
| 2401 | this->glInterface(), stencilSettings.frontAndBack(), GR_GL_FRONT_AND_BACK); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2402 | } |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 2403 | fHWStencilSettings = stencilSettings; |
Chris Dalton | 71713f6 | 2019-04-18 12:41:03 -0600 | [diff] [blame] | 2404 | fHWStencilOrigin = origin; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 2408 | void GrGLGpu::disableStencil() { |
| 2409 | if (kNo_TriState != fHWStencilTestEnabled) { |
| 2410 | GL_CALL(Disable(GR_GL_STENCIL_TEST)); |
Brian Salomon | af971de | 2017-06-08 16:11:33 -0400 | [diff] [blame] | 2411 | |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 2412 | fHWStencilTestEnabled = kNo_TriState; |
| 2413 | fHWStencilSettings.invalidate(); |
| 2414 | } |
| 2415 | } |
| 2416 | |
Chris Dalton | 4c56b03 | 2019-03-04 12:28:42 -0700 | [diff] [blame] | 2417 | void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA) { |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 2418 | // rt is only optional if useHWAA is false. |
| 2419 | SkASSERT(rt || !useHWAA); |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 2420 | #ifdef SK_DEBUG |
| 2421 | if (useHWAA && rt->numSamples() <= 1) { |
| 2422 | SkASSERT(this->caps()->mixedSamplesSupport()); |
| 2423 | SkASSERT(0 != static_cast<GrGLRenderTarget*>(rt)->renderFBOID()); |
| 2424 | SkASSERT(rt->renderTargetPriv().getStencilAttachment()); |
| 2425 | } |
| 2426 | #endif |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 2427 | |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 2428 | if (this->caps()->multisampleDisableSupport()) { |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 2429 | if (useHWAA) { |
| 2430 | if (kYes_TriState != fMSAAEnabled) { |
| 2431 | GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
| 2432 | fMSAAEnabled = kYes_TriState; |
| 2433 | } |
| 2434 | } else { |
| 2435 | if (kNo_TriState != fMSAAEnabled) { |
| 2436 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 2437 | fMSAAEnabled = kNo_TriState; |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | } |
| 2441 | } |
| 2442 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2443 | void GrGLGpu::flushBlendAndColorWrite( |
| 2444 | const GrXferProcessor::BlendInfo& blendInfo, const GrSwizzle& swizzle) { |
| 2445 | if (this->glCaps().neverDisableColorWrites() && !blendInfo.fWriteColor) { |
| 2446 | // We need to work around a driver bug by using a blend state that preserves the dst color, |
| 2447 | // rather than disabling color writes. |
| 2448 | GrXferProcessor::BlendInfo preserveDstBlend; |
| 2449 | preserveDstBlend.fSrcBlend = kZero_GrBlendCoeff; |
| 2450 | preserveDstBlend.fDstBlend = kOne_GrBlendCoeff; |
| 2451 | this->flushBlendAndColorWrite(preserveDstBlend, swizzle); |
| 2452 | return; |
| 2453 | } |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 2454 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2455 | GrBlendEquation equation = blendInfo.fEquation; |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 2456 | GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
| 2457 | GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2458 | |
| 2459 | // Any optimization to disable blending should have already been applied and |
| 2460 | // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). |
Dongseong Hwang | 4e1f022 | 2018-11-01 09:10:51 -0700 | [diff] [blame] | 2461 | bool blendOff = |
| 2462 | ((kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquation == equation) && |
| 2463 | kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff) || |
| 2464 | !blendInfo.fWriteColor; |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2465 | |
egdaniel | b414f25 | 2014-07-29 13:15:47 -0700 | [diff] [blame] | 2466 | if (blendOff) { |
| 2467 | if (kNo_TriState != fHWBlendState.fEnabled) { |
| 2468 | GL_CALL(Disable(GR_GL_BLEND)); |
joel.liang | 9764c40 | 2015-07-09 19:46:18 -0700 | [diff] [blame] | 2469 | |
| 2470 | // Workaround for the ARM KHR_blend_equation_advanced blacklist issue |
| 2471 | // https://code.google.com/p/skia/issues/detail?id=3943 |
| 2472 | if (kARM_GrGLVendor == this->ctxInfo().vendor() && |
| 2473 | GrBlendEquationIsAdvanced(fHWBlendState.fEquation)) { |
| 2474 | SkASSERT(this->caps()->advancedBlendEquationSupport()); |
| 2475 | // Set to any basic blending equation. |
| 2476 | GrBlendEquation blend_equation = kAdd_GrBlendEquation; |
| 2477 | GL_CALL(BlendEquation(gXfermodeEquation2Blend[blend_equation])); |
| 2478 | fHWBlendState.fEquation = blend_equation; |
| 2479 | } |
| 2480 | |
egdaniel | b414f25 | 2014-07-29 13:15:47 -0700 | [diff] [blame] | 2481 | fHWBlendState.fEnabled = kNo_TriState; |
| 2482 | } |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2483 | } else { |
| 2484 | if (kYes_TriState != fHWBlendState.fEnabled) { |
| 2485 | GL_CALL(Enable(GR_GL_BLEND)); |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2486 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2487 | fHWBlendState.fEnabled = kYes_TriState; |
| 2488 | } |
Brian Salomon | af971de | 2017-06-08 16:11:33 -0400 | [diff] [blame] | 2489 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2490 | if (fHWBlendState.fEquation != equation) { |
| 2491 | GL_CALL(BlendEquation(gXfermodeEquation2Blend[equation])); |
| 2492 | fHWBlendState.fEquation = equation; |
| 2493 | } |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2494 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2495 | if (GrBlendEquationIsAdvanced(equation)) { |
| 2496 | SkASSERT(this->caps()->advancedBlendEquationSupport()); |
| 2497 | // Advanced equations have no other blend state. |
| 2498 | return; |
| 2499 | } |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2500 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2501 | if (fHWBlendState.fSrcCoeff != srcCoeff || fHWBlendState.fDstCoeff != dstCoeff) { |
| 2502 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 2503 | gXfermodeCoeff2Blend[dstCoeff])); |
| 2504 | fHWBlendState.fSrcCoeff = srcCoeff; |
| 2505 | fHWBlendState.fDstCoeff = dstCoeff; |
| 2506 | } |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2507 | |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2508 | if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant(dstCoeff))) { |
| 2509 | SkPMColor4f blendConst = swizzle.applyTo(blendInfo.fBlendConstant); |
| 2510 | if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blendConst) { |
| 2511 | GL_CALL(BlendColor(blendConst.fR, blendConst.fG, blendConst.fB, blendConst.fA)); |
| 2512 | fHWBlendState.fConstColor = blendConst; |
| 2513 | fHWBlendState.fConstColorValid = true; |
| 2514 | } |
bsalomon | 7f9b2e4 | 2016-01-12 13:29:26 -0800 | [diff] [blame] | 2515 | } |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2516 | } |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 2517 | |
| 2518 | this->flushColorWrite(blendInfo.fWriteColor); |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2519 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2520 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2521 | static void get_gl_swizzle_values(const GrSwizzle& swizzle, GrGLenum glValues[4]) { |
Brian Salomon | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 2522 | for (int i = 0; i < 4; ++i) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2523 | switch (swizzle[i]) { |
| 2524 | case 'r': glValues[i] = GR_GL_RED; break; |
| 2525 | case 'g': glValues[i] = GR_GL_GREEN; break; |
| 2526 | case 'b': glValues[i] = GR_GL_BLUE; break; |
| 2527 | case 'a': glValues[i] = GR_GL_ALPHA; break; |
Brian Salomon | f30b1c1 | 2019-06-20 12:25:02 -0400 | [diff] [blame] | 2528 | case '0': glValues[i] = GR_GL_ZERO; break; |
Greg Daniel | 216a9d7 | 2019-02-20 10:12:29 -0500 | [diff] [blame] | 2529 | case '1': glValues[i] = GR_GL_ONE; break; |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2530 | default: SK_ABORT("Unsupported component"); |
| 2531 | } |
Brian Salomon | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 2532 | } |
| 2533 | } |
| 2534 | |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 2535 | void GrGLGpu::bindTexture(int unitIdx, GrSamplerState samplerState, const GrSwizzle& swizzle, |
| 2536 | GrGLTexture* texture) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2537 | SkASSERT(texture); |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 2538 | |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 2539 | #ifdef SK_DEBUG |
| 2540 | if (!this->caps()->npotTextureTileSupport()) { |
Brian Salomon | 2bbdcc4 | 2017-09-07 12:36:34 -0400 | [diff] [blame] | 2541 | if (samplerState.isRepeated()) { |
reed | 856e9d9 | 2015-09-30 12:21:45 -0700 | [diff] [blame] | 2542 | const int w = texture->width(); |
| 2543 | const int h = texture->height(); |
| 2544 | SkASSERT(SkIsPow2(w) && SkIsPow2(h)); |
| 2545 | } |
| 2546 | } |
| 2547 | #endif |
| 2548 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2549 | // If we created a rt/tex and rendered to it without using a texture and now we're texturing |
| 2550 | // from the rt it will still be the last bound texture, but it needs resolving. So keep this |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2551 | // out of the "last != next" check. |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 2552 | GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTarget()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2553 | if (texRT) { |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 2554 | this->onResolveRenderTarget(texRT); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2555 | } |
| 2556 | |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 2557 | GrGpuResource::UniqueID textureID = texture->uniqueID(); |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 2558 | GrGLenum target = texture->target(); |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 2559 | if (fHWTextureUnitBindings[unitIdx].boundID(target) != textureID) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2560 | this->setTextureUnit(unitIdx); |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 2561 | GL_CALL(BindTexture(target, texture->textureID())); |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 2562 | fHWTextureUnitBindings[unitIdx].setBoundID(target, textureID); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2565 | if (samplerState.filter() == GrSamplerState::Filter::kMipMap) { |
Greg Daniel | 8f5bbda | 2018-06-08 17:22:23 -0400 | [diff] [blame] | 2566 | if (!this->caps()->mipMapSupport() || |
| 2567 | texture->texturePriv().mipMapped() == GrMipMapped::kNo) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2568 | samplerState.setFilterMode(GrSamplerState::Filter::kBilerp); |
bsalomon | efd7d45 | 2014-10-23 14:17:46 -0700 | [diff] [blame] | 2569 | } |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 2570 | } |
bsalomon | efd7d45 | 2014-10-23 14:17:46 -0700 | [diff] [blame] | 2571 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 2572 | #ifdef SK_DEBUG |
Brian Osman | 2b23c4b | 2018-06-01 12:25:08 -0400 | [diff] [blame] | 2573 | // We were supposed to ensure MipMaps were up-to-date before getting here. |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2574 | if (samplerState.filter() == GrSamplerState::Filter::kMipMap) { |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 2575 | SkASSERT(!texture->texturePriv().mipMapsAreDirty()); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 2576 | } |
| 2577 | #endif |
| 2578 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2579 | auto timestamp = texture->parameters()->resetTimestamp(); |
| 2580 | bool setAll = timestamp < fResetTimestampForTextureParameters; |
cblume | 55f2d2d | 2016-02-26 13:20:48 -0800 | [diff] [blame] | 2581 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2582 | const GrGLTextureParameters::SamplerOverriddenState* samplerStateToRecord = nullptr; |
| 2583 | GrGLTextureParameters::SamplerOverriddenState newSamplerState; |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2584 | if (fSamplerObjectCache) { |
| 2585 | fSamplerObjectCache->bindSampler(unitIdx, samplerState); |
| 2586 | } else { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2587 | const GrGLTextureParameters::SamplerOverriddenState& oldSamplerState = |
| 2588 | texture->parameters()->samplerOverriddenState(); |
| 2589 | samplerStateToRecord = &newSamplerState; |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2590 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2591 | newSamplerState.fMinFilter = filter_to_gl_min_filter(samplerState.filter()); |
| 2592 | newSamplerState.fMagFilter = filter_to_gl_mag_filter(samplerState.filter()); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2593 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2594 | newSamplerState.fWrapS = wrap_mode_to_gl_wrap(samplerState.wrapModeX(), this->glCaps()); |
| 2595 | newSamplerState.fWrapT = wrap_mode_to_gl_wrap(samplerState.wrapModeY(), this->glCaps()); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2596 | |
| 2597 | // These are the OpenGL default values. |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2598 | newSamplerState.fMinLOD = -1000.f; |
| 2599 | newSamplerState.fMaxLOD = 1000.f; |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2600 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2601 | if (setAll || newSamplerState.fMagFilter != oldSamplerState.fMagFilter) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2602 | this->setTextureUnit(unitIdx); |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2603 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newSamplerState.fMagFilter)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2604 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2605 | if (setAll || newSamplerState.fMinFilter != oldSamplerState.fMinFilter) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2606 | this->setTextureUnit(unitIdx); |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2607 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MIN_FILTER, newSamplerState.fMinFilter)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2608 | } |
Mike Klein | 1bccae5 | 2018-10-19 11:38:44 +0000 | [diff] [blame] | 2609 | if (this->glCaps().mipMapLevelAndLodControlSupport()) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2610 | if (setAll || newSamplerState.fMinLOD != oldSamplerState.fMinLOD) { |
Mike Klein | 1bccae5 | 2018-10-19 11:38:44 +0000 | [diff] [blame] | 2611 | this->setTextureUnit(unitIdx); |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2612 | GL_CALL(TexParameterf(target, GR_GL_TEXTURE_MIN_LOD, newSamplerState.fMinLOD)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2613 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2614 | if (setAll || newSamplerState.fMaxLOD != oldSamplerState.fMaxLOD) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2615 | this->setTextureUnit(unitIdx); |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2616 | GL_CALL(TexParameterf(target, GR_GL_TEXTURE_MAX_LOD, newSamplerState.fMaxLOD)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2617 | } |
| 2618 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2619 | if (setAll || newSamplerState.fWrapS != oldSamplerState.fWrapS) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2620 | this->setTextureUnit(unitIdx); |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2621 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_S, newSamplerState.fWrapS)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2622 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2623 | if (setAll || newSamplerState.fWrapT != oldSamplerState.fWrapT) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2624 | this->setTextureUnit(unitIdx); |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2625 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newSamplerState.fWrapT)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2626 | } |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 2627 | if (this->glCaps().clampToBorderSupport()) { |
| 2628 | // Make sure the border color is transparent black (the default) |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2629 | if (setAll || oldSamplerState.fBorderColorInvalid) { |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 2630 | this->setTextureUnit(unitIdx); |
Brian Salomon | 89f2ff1 | 2018-12-07 19:30:25 -0500 | [diff] [blame] | 2631 | static const GrGLfloat kTransparentBlack[4] = {0.f, 0.f, 0.f, 0.f}; |
| 2632 | GL_CALL(TexParameterfv(target, GR_GL_TEXTURE_BORDER_COLOR, kTransparentBlack)); |
Michael Ludwig | f23a152 | 2018-12-10 11:36:13 -0500 | [diff] [blame] | 2633 | } |
| 2634 | } |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2635 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2636 | GrGLTextureParameters::NonsamplerState newNonsamplerState; |
| 2637 | newNonsamplerState.fBaseMipMapLevel = 0; |
| 2638 | newNonsamplerState.fMaxMipMapLevel = texture->texturePriv().maxMipMapLevel(); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2639 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2640 | const GrGLTextureParameters::NonsamplerState& oldNonsamplerState = |
| 2641 | texture->parameters()->nonsamplerState(); |
Brian Salomon | 68ba117 | 2019-06-05 11:15:08 -0400 | [diff] [blame] | 2642 | if (!this->caps()->shaderCaps()->textureSwizzleAppliedInShader()) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2643 | newNonsamplerState.fSwizzleKey = swizzle.asKey(); |
| 2644 | if (setAll || swizzle.asKey() != oldNonsamplerState.fSwizzleKey) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2645 | GrGLenum glValues[4]; |
| 2646 | get_gl_swizzle_values(swizzle, glValues); |
| 2647 | this->setTextureUnit(unitIdx); |
Kevin Lubick | 8aa203c | 2019-03-19 13:23:10 -0400 | [diff] [blame] | 2648 | if (GR_IS_GR_GL(this->glStandard())) { |
| 2649 | GR_STATIC_ASSERT(sizeof(glValues[0]) == sizeof(GrGLint)); |
| 2650 | GL_CALL(TexParameteriv(target, GR_GL_TEXTURE_SWIZZLE_RGBA, |
| 2651 | reinterpret_cast<const GrGLint*>(glValues))); |
| 2652 | } else if (GR_IS_GR_GL_ES(this->glStandard())) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2653 | // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. |
| 2654 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_R, glValues[0])); |
| 2655 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_G, glValues[1])); |
| 2656 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_B, glValues[2])); |
| 2657 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_SWIZZLE_A, glValues[3])); |
Brian Salomon | bfb3df4 | 2018-10-19 19:24:31 +0000 | [diff] [blame] | 2658 | } |
Brian Salomon | bfb3df4 | 2018-10-19 19:24:31 +0000 | [diff] [blame] | 2659 | } |
| 2660 | } |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2661 | // These are not supported in ES2 contexts |
Brian Salomon | f384193 | 2018-11-29 09:13:37 -0500 | [diff] [blame] | 2662 | if (this->glCaps().mipMapLevelAndLodControlSupport() && |
| 2663 | (texture->texturePriv().textureType() != GrTextureType::kExternal || |
| 2664 | !this->glCaps().dontSetBaseOrMaxLevelForExternalTextures())) { |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2665 | if (newNonsamplerState.fBaseMipMapLevel != oldNonsamplerState.fBaseMipMapLevel) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2666 | this->setTextureUnit(unitIdx); |
| 2667 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_BASE_LEVEL, |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2668 | newNonsamplerState.fBaseMipMapLevel)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2669 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2670 | if (newNonsamplerState.fMaxMipMapLevel != oldNonsamplerState.fMaxMipMapLevel) { |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2671 | this->setTextureUnit(unitIdx); |
| 2672 | GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAX_LEVEL, |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2673 | newNonsamplerState.fMaxMipMapLevel)); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 2674 | } |
Brian Salomon | 327955b | 2018-10-22 15:39:22 +0000 | [diff] [blame] | 2675 | } |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 2676 | texture->parameters()->set(samplerStateToRecord, newNonsamplerState, |
| 2677 | fResetTimestampForTextureParameters); |
cdalton | 74b8d32 | 2016-04-11 14:47:28 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 2680 | void GrGLGpu::onResetTextureBindings() { |
| 2681 | static constexpr GrGLenum kTargets[] = {GR_GL_TEXTURE_2D, GR_GL_TEXTURE_RECTANGLE, |
| 2682 | GR_GL_TEXTURE_EXTERNAL}; |
| 2683 | for (int i = 0; i < this->numTextureUnits(); ++i) { |
| 2684 | this->setTextureUnit(i); |
| 2685 | for (auto target : kTargets) { |
| 2686 | if (fHWTextureUnitBindings[i].hasBeenModified(target)) { |
| 2687 | GL_CALL(BindTexture(target, 0)); |
| 2688 | } |
| 2689 | } |
| 2690 | fHWTextureUnitBindings[i].invalidateAllTargets(true); |
| 2691 | } |
| 2692 | } |
| 2693 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 2694 | void GrGLGpu::flushColorWrite(bool writeColor) { |
| 2695 | if (!writeColor) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2696 | if (kNo_TriState != fHWWriteToColor) { |
Brian Osman | a9aaef0 | 2019-05-06 20:07:20 +0000 | [diff] [blame] | 2697 | GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE, |
| 2698 | GR_GL_FALSE, GR_GL_FALSE)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2699 | fHWWriteToColor = kNo_TriState; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2700 | } |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2701 | } else { |
| 2702 | if (kYes_TriState != fHWWriteToColor) { |
Brian Osman | a9aaef0 | 2019-05-06 20:07:20 +0000 | [diff] [blame] | 2703 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2704 | fHWWriteToColor = kYes_TriState; |
| 2705 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2706 | } |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 2707 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2708 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame] | 2709 | void GrGLGpu::flushClearColor(GrGLfloat r, GrGLfloat g, GrGLfloat b, GrGLfloat a) { |
Brian Salomon | 805cc7a | 2019-01-28 09:52:34 -0500 | [diff] [blame] | 2710 | if (r != fHWClearColor[0] || g != fHWClearColor[1] || |
| 2711 | b != fHWClearColor[2] || a != fHWClearColor[3]) { |
| 2712 | GL_CALL(ClearColor(r, g, b, a)); |
| 2713 | fHWClearColor[0] = r; |
| 2714 | fHWClearColor[1] = g; |
| 2715 | fHWClearColor[2] = b; |
| 2716 | fHWClearColor[3] = a; |
| 2717 | } |
| 2718 | } |
| 2719 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2720 | void GrGLGpu::setTextureUnit(int unit) { |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 2721 | SkASSERT(unit >= 0 && unit < this->numTextureUnits()); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2722 | if (unit != fHWActiveTextureUnitIdx) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2723 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 2724 | fHWActiveTextureUnitIdx = unit; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2725 | } |
| 2726 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2727 | |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 2728 | void GrGLGpu::bindTextureToScratchUnit(GrGLenum target, GrGLint textureID) { |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2729 | // Bind the last texture unit since it is the least likely to be used by GrGLProgram. |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 2730 | int lastUnitIdx = this->numTextureUnits() - 1; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2731 | if (lastUnitIdx != fHWActiveTextureUnitIdx) { |
| 2732 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx)); |
| 2733 | fHWActiveTextureUnitIdx = lastUnitIdx; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2734 | } |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 2735 | // Clear out the this field so that if a GrGLProgram does use this unit it will rebind the |
| 2736 | // correct texture. |
Brian Salomon | 1f05d45 | 2019-02-08 12:33:08 -0500 | [diff] [blame] | 2737 | fHWTextureUnitBindings[lastUnitIdx].invalidateForScratchUse(target); |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 2738 | GL_CALL(BindTexture(target, textureID)); |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2739 | } |
| 2740 | |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 2741 | // Determines whether glBlitFramebuffer could be used between src and dst by onCopySurface. |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2742 | static inline bool can_blit_framebuffer_for_copy_surface(const GrSurface* dst, |
| 2743 | const GrSurface* src, |
| 2744 | const SkIRect& srcRect, |
| 2745 | const SkIPoint& dstPoint, |
| 2746 | const GrGLCaps& caps) { |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2747 | int dstSampleCnt = 0; |
| 2748 | int srcSampleCnt = 0; |
| 2749 | if (const GrRenderTarget* rt = dst->asRenderTarget()) { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2750 | dstSampleCnt = rt->numSamples(); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2751 | } |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2752 | if (const GrRenderTarget* rt = src->asRenderTarget()) { |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2753 | srcSampleCnt = rt->numSamples(); |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2754 | } |
| 2755 | SkASSERT((dstSampleCnt > 0) == SkToBool(dst->asRenderTarget())); |
| 2756 | SkASSERT((srcSampleCnt > 0) == SkToBool(src->asRenderTarget())); |
| 2757 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 2758 | GrGLFormat dstFormat = dst->backendFormat().asGLFormat(); |
| 2759 | GrGLFormat srcFormat = src->backendFormat().asGLFormat(); |
| 2760 | |
Brian Salomon | e5e7eb1 | 2016-10-14 16:18:33 -0400 | [diff] [blame] | 2761 | const GrGLTexture* dstTex = static_cast<const GrGLTexture*>(dst->asTexture()); |
Mike Klein | 1d74620 | 2018-01-25 17:32:51 -0500 | [diff] [blame] | 2762 | const GrGLTexture* srcTex = static_cast<const GrGLTexture*>(src->asTexture()); |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2763 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2764 | GrTextureType dstTexType; |
| 2765 | GrTextureType* dstTexTypePtr = nullptr; |
| 2766 | GrTextureType srcTexType; |
| 2767 | GrTextureType* srcTexTypePtr = nullptr; |
| 2768 | if (dstTex) { |
| 2769 | dstTexType = dstTex->texturePriv().textureType(); |
| 2770 | dstTexTypePtr = &dstTexType; |
| 2771 | } |
| 2772 | if (srcTex) { |
| 2773 | srcTexType = srcTex->texturePriv().textureType(); |
| 2774 | srcTexTypePtr = &srcTexType; |
| 2775 | } |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2776 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 2777 | return caps.canCopyAsBlit(dstFormat, dstSampleCnt, dstTexTypePtr, |
| 2778 | srcFormat, srcSampleCnt, srcTexTypePtr, |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2779 | src->getBoundsRect(), true, srcRect, dstPoint); |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2780 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2781 | |
Brian Osman | a9c8a05 | 2018-01-19 10:31:56 -0500 | [diff] [blame] | 2782 | static bool rt_has_msaa_render_buffer(const GrGLRenderTarget* rt, const GrGLCaps& glCaps) { |
| 2783 | // A RT has a separate MSAA renderbuffer if: |
| 2784 | // 1) It's multisampled |
| 2785 | // 2) We're using an extension with separate MSAA renderbuffers |
| 2786 | // 3) It's not FBO 0, which is special and always auto-resolves |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 2787 | return rt->numSamples() > 1 && glCaps.usesMSAARenderBuffers() && rt->renderFBOID() != 0; |
Brian Osman | a9c8a05 | 2018-01-19 10:31:56 -0500 | [diff] [blame] | 2788 | } |
| 2789 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2790 | static inline bool can_copy_texsubimage(const GrSurface* dst, const GrSurface* src, |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2791 | const GrGLCaps& caps) { |
| 2792 | |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2793 | const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->asRenderTarget()); |
bsalomon@google.com | a271985 | 2013-04-17 14:25:27 +0000 | [diff] [blame] | 2794 | const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->asRenderTarget()); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 2795 | const GrGLTexture* dstTex = static_cast<const GrGLTexture*>(dst->asTexture()); |
bsalomon | 7ea33f5 | 2015-11-22 14:51:00 -0800 | [diff] [blame] | 2796 | const GrGLTexture* srcTex = static_cast<const GrGLTexture*>(src->asTexture()); |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 2797 | |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2798 | bool dstHasMSAARenderBuffer = dstRT ? rt_has_msaa_render_buffer(dstRT, caps) : false; |
| 2799 | bool srcHasMSAARenderBuffer = srcRT ? rt_has_msaa_render_buffer(srcRT, caps) : false; |
| 2800 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 2801 | GrGLFormat dstFormat = dst->backendFormat().asGLFormat(); |
| 2802 | GrGLFormat srcFormat = src->backendFormat().asGLFormat(); |
| 2803 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2804 | GrTextureType dstTexType; |
| 2805 | GrTextureType* dstTexTypePtr = nullptr; |
| 2806 | GrTextureType srcTexType; |
| 2807 | GrTextureType* srcTexTypePtr = nullptr; |
| 2808 | if (dstTex) { |
| 2809 | dstTexType = dstTex->texturePriv().textureType(); |
| 2810 | dstTexTypePtr = &dstTexType; |
| 2811 | } |
| 2812 | if (srcTex) { |
| 2813 | srcTexType = srcTex->texturePriv().textureType(); |
| 2814 | srcTexTypePtr = &srcTexType; |
| 2815 | } |
Greg Daniel | 26dbe3b | 2018-05-03 10:35:42 -0400 | [diff] [blame] | 2816 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 2817 | return caps.canCopyTexSubImage(dstFormat, dstHasMSAARenderBuffer, dstTexTypePtr, |
| 2818 | srcFormat, srcHasMSAARenderBuffer, srcTexTypePtr); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2819 | } |
| 2820 | |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 2821 | // If a temporary FBO was created, its non-zero ID is returned. |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 2822 | void GrGLGpu::bindSurfaceFBOForPixelOps(GrSurface* surface, int mipLevel, GrGLenum fboTarget, |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 2823 | TempFBOTarget tempFBOTarget) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2824 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarget()); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 2825 | if (!rt || mipLevel > 0) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2826 | SkASSERT(surface->asTexture()); |
Brian Salomon | 9bada54 | 2017-06-12 12:09:30 -0400 | [diff] [blame] | 2827 | GrGLTexture* texture = static_cast<GrGLTexture*>(surface->asTexture()); |
| 2828 | GrGLuint texID = texture->textureID(); |
| 2829 | GrGLenum target = texture->target(); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2830 | GrGLuint* tempFBOID; |
| 2831 | tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTempDstFBOID; |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2832 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2833 | if (0 == *tempFBOID) { |
| 2834 | GR_GL_CALL(this->glInterface(), GenFramebuffers(1, tempFBOID)); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2835 | } |
| 2836 | |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 2837 | this->bindFramebuffer(fboTarget, *tempFBOID); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 2838 | GR_GL_CALL( |
| 2839 | this->glInterface(), |
| 2840 | FramebufferTexture2D(fboTarget, GR_GL_COLOR_ATTACHMENT0, target, texID, mipLevel)); |
| 2841 | if (mipLevel == 0) { |
| 2842 | texture->baseLevelWasBoundToFBO(); |
| 2843 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2844 | } else { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 2845 | this->bindFramebuffer(fboTarget, rt->renderFBOID()); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2846 | } |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2847 | } |
| 2848 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 2849 | void GrGLGpu::unbindSurfaceFBOForPixelOps(GrSurface* surface, int mipLevel, GrGLenum fboTarget) { |
Brian Salomon | 71d9d84 | 2016-11-03 13:42:00 -0400 | [diff] [blame] | 2850 | // bindSurfaceFBOForPixelOps temporarily binds textures that are not render targets to |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 2851 | if (mipLevel > 0 || !surface->asRenderTarget()) { |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 2852 | SkASSERT(surface->asTexture()); |
| 2853 | GrGLenum textureTarget = static_cast<GrGLTexture*>(surface->asTexture())->target(); |
| 2854 | GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
| 2855 | GR_GL_COLOR_ATTACHMENT0, |
| 2856 | textureTarget, |
| 2857 | 0, |
| 2858 | 0)); |
| 2859 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2860 | } |
| 2861 | |
Adrienne Walker | ca0cdef | 2018-08-20 13:49:40 -0700 | [diff] [blame] | 2862 | void GrGLGpu::onFBOChanged() { |
| 2863 | if (this->caps()->workarounds().flush_on_framebuffer_change || |
| 2864 | this->caps()->workarounds().restore_scissor_on_fbo_change) { |
| 2865 | GL_CALL(Flush()); |
| 2866 | } |
| 2867 | } |
| 2868 | |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 2869 | void GrGLGpu::bindFramebuffer(GrGLenum target, GrGLuint fboid) { |
| 2870 | fStats.incRenderTargetBinds(); |
| 2871 | GL_CALL(BindFramebuffer(target, fboid)); |
| 2872 | if (target == GR_GL_FRAMEBUFFER || target == GR_GL_DRAW_FRAMEBUFFER) { |
| 2873 | fBoundDrawFramebuffer = fboid; |
| 2874 | } |
| 2875 | |
Adrienne Walker | ca0cdef | 2018-08-20 13:49:40 -0700 | [diff] [blame] | 2876 | if (this->caps()->workarounds().restore_scissor_on_fbo_change) { |
| 2877 | // The driver forgets the correct scissor when modifying the FBO binding. |
| 2878 | if (!fHWScissorSettings.fRect.isInvalid()) { |
Chris Dalton | d6cda8d | 2019-09-05 02:30:04 -0600 | [diff] [blame] | 2879 | const GrNativeRect& r = fHWScissorSettings.fRect; |
Chris Dalton | 76500e5 | 2019-09-05 02:13:05 -0600 | [diff] [blame] | 2880 | GL_CALL(Scissor(r.fX, r.fY, r.fWidth, r.fHeight)); |
Adrienne Walker | ca0cdef | 2018-08-20 13:49:40 -0700 | [diff] [blame] | 2881 | } |
Adrienne Walker | 3ed3399 | 2018-05-15 11:44:34 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Adrienne Walker | ca0cdef | 2018-08-20 13:49:40 -0700 | [diff] [blame] | 2884 | this->onFBOChanged(); |
Adrienne Walker | 3ed3399 | 2018-05-15 11:44:34 -0700 | [diff] [blame] | 2885 | } |
| 2886 | |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 2887 | void GrGLGpu::deleteFramebuffer(GrGLuint fboid) { |
| 2888 | if (fboid == fBoundDrawFramebuffer && |
| 2889 | this->caps()->workarounds().unbind_attachments_on_bound_render_fbo_delete) { |
| 2890 | // This workaround only applies to deleting currently bound framebuffers |
| 2891 | // on Adreno 420. Because this is a somewhat rare case, instead of |
| 2892 | // tracking all the attachments of every framebuffer instead just always |
| 2893 | // unbind all attachments. |
| 2894 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, |
| 2895 | GR_GL_RENDERBUFFER, 0)); |
| 2896 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, |
| 2897 | GR_GL_RENDERBUFFER, 0)); |
| 2898 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT, |
| 2899 | GR_GL_RENDERBUFFER, 0)); |
| 2900 | } |
| 2901 | |
| 2902 | GL_CALL(DeleteFramebuffers(1, &fboid)); |
Adrienne Walker | ca0cdef | 2018-08-20 13:49:40 -0700 | [diff] [blame] | 2903 | |
| 2904 | // Deleting the currently bound framebuffer rebinds to 0. |
| 2905 | if (fboid == fBoundDrawFramebuffer) { |
| 2906 | this->onFBOChanged(); |
| 2907 | } |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 2908 | } |
| 2909 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2910 | bool GrGLGpu::onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 2911 | const SkIPoint& dstPoint) { |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2912 | // Don't prefer copying as a draw if the dst doesn't already have a FBO object. |
| 2913 | // This implicitly handles this->glCaps().useDrawInsteadOfAllRenderTargetWrites(). |
| 2914 | bool preferCopy = SkToBool(dst->asRenderTarget()); |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 2915 | auto dstFormat = dst->backendFormat().asGLFormat(); |
| 2916 | if (preferCopy && this->glCaps().canCopyAsDraw(dstFormat, SkToBool(src->asTexture()))) { |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2917 | if (this->copySurfaceAsDraw(dst, src, srcRect, dstPoint)) { |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2918 | return true; |
| 2919 | } |
| 2920 | } |
cblume | 6121405 | 2016-01-26 09:10:48 -0800 | [diff] [blame] | 2921 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2922 | if (can_copy_texsubimage(dst, src, this->glCaps())) { |
| 2923 | this->copySurfaceAsCopyTexSubImage(dst, src, srcRect, dstPoint); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 2924 | return true; |
| 2925 | } |
| 2926 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2927 | if (can_blit_framebuffer_for_copy_surface(dst, src, srcRect, dstPoint, this->glCaps())) { |
| 2928 | return this->copySurfaceAsBlitFramebuffer(dst, src, srcRect, dstPoint); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2929 | } |
| 2930 | |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 2931 | if (!preferCopy && this->glCaps().canCopyAsDraw(dstFormat, SkToBool(src->asTexture()))) { |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 2932 | if (this->copySurfaceAsDraw(dst, src, srcRect, dstPoint)) { |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2933 | return true; |
| 2934 | } |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 2935 | } |
| 2936 | |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 2937 | return false; |
| 2938 | } |
| 2939 | |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2940 | bool GrGLGpu::createCopyProgram(GrTexture* srcTex) { |
Brian Salomon | 5f39427 | 2019-07-02 14:07:49 -0400 | [diff] [blame] | 2941 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2942 | |
| 2943 | int progIdx = TextureToCopyProgramIdx(srcTex); |
| 2944 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
| 2945 | GrSLType samplerType = |
| 2946 | GrSLCombinedSamplerTypeForTextureType(srcTex->texturePriv().textureType()); |
| 2947 | |
| 2948 | if (!fCopyProgramArrayBuffer) { |
| 2949 | static const GrGLfloat vdata[] = { |
| 2950 | 0, 0, |
| 2951 | 0, 1, |
| 2952 | 1, 0, |
| 2953 | 1, 1 |
| 2954 | }; |
| 2955 | fCopyProgramArrayBuffer = GrGLBuffer::Make(this, sizeof(vdata), GrGpuBufferType::kVertex, |
| 2956 | kStatic_GrAccessPattern, vdata); |
| 2957 | } |
| 2958 | if (!fCopyProgramArrayBuffer) { |
| 2959 | return false; |
| 2960 | } |
| 2961 | |
| 2962 | SkASSERT(!fCopyPrograms[progIdx].fProgram); |
| 2963 | GL_CALL_RET(fCopyPrograms[progIdx].fProgram, CreateProgram()); |
| 2964 | if (!fCopyPrograms[progIdx].fProgram) { |
| 2965 | return false; |
| 2966 | } |
| 2967 | |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2968 | GrShaderVar aVertex("a_vertex", kHalf2_GrSLType, GrShaderVar::kIn_TypeModifier); |
| 2969 | GrShaderVar uTexCoordXform("u_texCoordXform", kHalf4_GrSLType, |
| 2970 | GrShaderVar::kUniform_TypeModifier); |
| 2971 | GrShaderVar uPosXform("u_posXform", kHalf4_GrSLType, GrShaderVar::kUniform_TypeModifier); |
| 2972 | GrShaderVar uTexture("u_texture", samplerType, GrShaderVar::kUniform_TypeModifier); |
| 2973 | GrShaderVar vTexCoord("v_texCoord", kHalf2_GrSLType, GrShaderVar::kOut_TypeModifier); |
| 2974 | GrShaderVar oFragColor("o_FragColor", kHalf4_GrSLType, GrShaderVar::kOut_TypeModifier); |
| 2975 | |
Greg Daniel | 9e3169b | 2019-06-06 14:38:17 -0400 | [diff] [blame] | 2976 | SkString vshaderTxt; |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 2977 | if (shaderCaps->noperspectiveInterpolationSupport()) { |
| 2978 | if (const char* extension = shaderCaps->noperspectiveInterpolationExtensionString()) { |
| 2979 | vshaderTxt.appendf("#extension %s : require\n", extension); |
| 2980 | } |
| 2981 | vTexCoord.addModifier("noperspective"); |
| 2982 | } |
| 2983 | |
| 2984 | aVertex.appendDecl(shaderCaps, &vshaderTxt); |
| 2985 | vshaderTxt.append(";"); |
| 2986 | uTexCoordXform.appendDecl(shaderCaps, &vshaderTxt); |
| 2987 | vshaderTxt.append(";"); |
| 2988 | uPosXform.appendDecl(shaderCaps, &vshaderTxt); |
| 2989 | vshaderTxt.append(";"); |
| 2990 | vTexCoord.appendDecl(shaderCaps, &vshaderTxt); |
| 2991 | vshaderTxt.append(";"); |
| 2992 | |
| 2993 | vshaderTxt.append( |
| 2994 | "// Copy Program VS\n" |
| 2995 | "void main() {" |
| 2996 | " v_texCoord = half2(a_vertex.xy * u_texCoordXform.xy + u_texCoordXform.zw);" |
| 2997 | " sk_Position.xy = a_vertex * u_posXform.xy + u_posXform.zw;" |
| 2998 | " sk_Position.zw = half2(0, 1);" |
| 2999 | "}" |
| 3000 | ); |
| 3001 | |
Greg Daniel | 9e3169b | 2019-06-06 14:38:17 -0400 | [diff] [blame] | 3002 | SkString fshaderTxt; |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3003 | if (shaderCaps->noperspectiveInterpolationSupport()) { |
| 3004 | if (const char* extension = shaderCaps->noperspectiveInterpolationExtensionString()) { |
| 3005 | fshaderTxt.appendf("#extension %s : require\n", extension); |
| 3006 | } |
| 3007 | } |
| 3008 | vTexCoord.setTypeModifier(GrShaderVar::kIn_TypeModifier); |
| 3009 | vTexCoord.appendDecl(shaderCaps, &fshaderTxt); |
| 3010 | fshaderTxt.append(";"); |
| 3011 | uTexture.appendDecl(shaderCaps, &fshaderTxt); |
| 3012 | fshaderTxt.append(";"); |
| 3013 | fshaderTxt.appendf( |
| 3014 | "// Copy Program FS\n" |
| 3015 | "void main() {" |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 3016 | " sk_FragColor = sample(u_texture, v_texCoord);" |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3017 | "}" |
| 3018 | ); |
| 3019 | |
| 3020 | auto errorHandler = this->getContext()->priv().getShaderErrorHandler(); |
| 3021 | SkSL::String sksl(vshaderTxt.c_str(), vshaderTxt.size()); |
| 3022 | SkSL::Program::Settings settings; |
| 3023 | settings.fCaps = shaderCaps; |
| 3024 | SkSL::String glsl; |
| 3025 | std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind, |
| 3026 | sksl, settings, &glsl, errorHandler); |
| 3027 | GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram, |
| 3028 | GR_GL_VERTEX_SHADER, glsl, &fStats, errorHandler); |
| 3029 | SkASSERT(program->fInputs.isEmpty()); |
| 3030 | |
| 3031 | sksl.assign(fshaderTxt.c_str(), fshaderTxt.size()); |
| 3032 | program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl, |
| 3033 | errorHandler); |
| 3034 | GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fCopyPrograms[progIdx].fProgram, |
| 3035 | GR_GL_FRAGMENT_SHADER, glsl, &fStats, |
| 3036 | errorHandler); |
| 3037 | SkASSERT(program->fInputs.isEmpty()); |
| 3038 | |
| 3039 | GL_CALL(LinkProgram(fCopyPrograms[progIdx].fProgram)); |
| 3040 | |
| 3041 | GL_CALL_RET(fCopyPrograms[progIdx].fTextureUniform, |
| 3042 | GetUniformLocation(fCopyPrograms[progIdx].fProgram, "u_texture")); |
| 3043 | GL_CALL_RET(fCopyPrograms[progIdx].fPosXformUniform, |
| 3044 | GetUniformLocation(fCopyPrograms[progIdx].fProgram, "u_posXform")); |
| 3045 | GL_CALL_RET(fCopyPrograms[progIdx].fTexCoordXformUniform, |
| 3046 | GetUniformLocation(fCopyPrograms[progIdx].fProgram, "u_texCoordXform")); |
| 3047 | |
| 3048 | GL_CALL(BindAttribLocation(fCopyPrograms[progIdx].fProgram, 0, "a_vertex")); |
| 3049 | |
| 3050 | GL_CALL(DeleteShader(vshader)); |
| 3051 | GL_CALL(DeleteShader(fshader)); |
| 3052 | |
| 3053 | return true; |
| 3054 | } |
| 3055 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3056 | bool GrGLGpu::createMipmapProgram(int progIdx) { |
| 3057 | const bool oddWidth = SkToBool(progIdx & 0x2); |
| 3058 | const bool oddHeight = SkToBool(progIdx & 0x1); |
| 3059 | const int numTaps = (oddWidth ? 2 : 1) * (oddHeight ? 2 : 1); |
| 3060 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3061 | const GrShaderCaps* shaderCaps = this->caps()->shaderCaps(); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3062 | |
| 3063 | SkASSERT(!fMipmapPrograms[progIdx].fProgram); |
| 3064 | GL_CALL_RET(fMipmapPrograms[progIdx].fProgram, CreateProgram()); |
| 3065 | if (!fMipmapPrograms[progIdx].fProgram) { |
| 3066 | return false; |
| 3067 | } |
| 3068 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 3069 | GrShaderVar aVertex("a_vertex", kHalf2_GrSLType, GrShaderVar::kIn_TypeModifier); |
| 3070 | GrShaderVar uTexCoordXform("u_texCoordXform", kHalf4_GrSLType, |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 3071 | GrShaderVar::kUniform_TypeModifier); |
| 3072 | GrShaderVar uTexture("u_texture", kTexture2DSampler_GrSLType, |
| 3073 | GrShaderVar::kUniform_TypeModifier); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3074 | // We need 1, 2, or 4 texture coordinates (depending on parity of each dimension): |
Brian Salomon | 99938a8 | 2016-11-21 13:41:08 -0500 | [diff] [blame] | 3075 | GrShaderVar vTexCoords[] = { |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 3076 | GrShaderVar("v_texCoord0", kHalf2_GrSLType, GrShaderVar::kOut_TypeModifier), |
| 3077 | GrShaderVar("v_texCoord1", kHalf2_GrSLType, GrShaderVar::kOut_TypeModifier), |
| 3078 | GrShaderVar("v_texCoord2", kHalf2_GrSLType, GrShaderVar::kOut_TypeModifier), |
| 3079 | GrShaderVar("v_texCoord3", kHalf2_GrSLType, GrShaderVar::kOut_TypeModifier), |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3080 | }; |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 3081 | GrShaderVar oFragColor("o_FragColor", kHalf4_GrSLType,GrShaderVar::kOut_TypeModifier); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3082 | |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 3083 | SkString vshaderTxt; |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3084 | if (shaderCaps->noperspectiveInterpolationSupport()) { |
| 3085 | if (const char* extension = shaderCaps->noperspectiveInterpolationExtensionString()) { |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3086 | vshaderTxt.appendf("#extension %s : require\n", extension); |
| 3087 | } |
| 3088 | vTexCoords[0].addModifier("noperspective"); |
| 3089 | vTexCoords[1].addModifier("noperspective"); |
| 3090 | vTexCoords[2].addModifier("noperspective"); |
| 3091 | vTexCoords[3].addModifier("noperspective"); |
| 3092 | } |
| 3093 | |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3094 | aVertex.appendDecl(shaderCaps, &vshaderTxt); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3095 | vshaderTxt.append(";"); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3096 | uTexCoordXform.appendDecl(shaderCaps, &vshaderTxt); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3097 | vshaderTxt.append(";"); |
| 3098 | for (int i = 0; i < numTaps; ++i) { |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3099 | vTexCoords[i].appendDecl(shaderCaps, &vshaderTxt); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3100 | vshaderTxt.append(";"); |
| 3101 | } |
| 3102 | |
| 3103 | vshaderTxt.append( |
| 3104 | "// Mipmap Program VS\n" |
| 3105 | "void main() {" |
Ethan Nicholas | bed683a | 2017-09-26 14:23:59 -0400 | [diff] [blame] | 3106 | " sk_Position.xy = a_vertex * half2(2, 2) - half2(1, 1);" |
| 3107 | " sk_Position.zw = half2(0, 1);" |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3108 | ); |
| 3109 | |
| 3110 | // Insert texture coordinate computation: |
| 3111 | if (oddWidth && oddHeight) { |
| 3112 | vshaderTxt.append( |
| 3113 | " v_texCoord0 = a_vertex.xy * u_texCoordXform.yw;" |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 3114 | " v_texCoord1 = a_vertex.xy * u_texCoordXform.yw + half2(u_texCoordXform.x, 0);" |
| 3115 | " v_texCoord2 = a_vertex.xy * u_texCoordXform.yw + half2(0, u_texCoordXform.z);" |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3116 | " v_texCoord3 = a_vertex.xy * u_texCoordXform.yw + u_texCoordXform.xz;" |
| 3117 | ); |
| 3118 | } else if (oddWidth) { |
| 3119 | vshaderTxt.append( |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 3120 | " v_texCoord0 = a_vertex.xy * half2(u_texCoordXform.y, 1);" |
| 3121 | " v_texCoord1 = a_vertex.xy * half2(u_texCoordXform.y, 1) + half2(u_texCoordXform.x, 0);" |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3122 | ); |
| 3123 | } else if (oddHeight) { |
| 3124 | vshaderTxt.append( |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 3125 | " v_texCoord0 = a_vertex.xy * half2(1, u_texCoordXform.w);" |
| 3126 | " v_texCoord1 = a_vertex.xy * half2(1, u_texCoordXform.w) + half2(0, u_texCoordXform.z);" |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3127 | ); |
| 3128 | } else { |
| 3129 | vshaderTxt.append( |
| 3130 | " v_texCoord0 = a_vertex.xy;" |
| 3131 | ); |
| 3132 | } |
| 3133 | |
| 3134 | vshaderTxt.append("}"); |
| 3135 | |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 3136 | SkString fshaderTxt; |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3137 | if (shaderCaps->noperspectiveInterpolationSupport()) { |
| 3138 | if (const char* extension = shaderCaps->noperspectiveInterpolationExtensionString()) { |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3139 | fshaderTxt.appendf("#extension %s : require\n", extension); |
| 3140 | } |
| 3141 | } |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3142 | for (int i = 0; i < numTaps; ++i) { |
Brian Salomon | f31ae49 | 2016-11-18 15:35:33 -0500 | [diff] [blame] | 3143 | vTexCoords[i].setTypeModifier(GrShaderVar::kIn_TypeModifier); |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3144 | vTexCoords[i].appendDecl(shaderCaps, &fshaderTxt); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3145 | fshaderTxt.append(";"); |
| 3146 | } |
Brian Salomon | 1edc5b9 | 2016-11-29 13:43:46 -0500 | [diff] [blame] | 3147 | uTexture.appendDecl(shaderCaps, &fshaderTxt); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3148 | fshaderTxt.append(";"); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3149 | fshaderTxt.append( |
| 3150 | "// Mipmap Program FS\n" |
| 3151 | "void main() {" |
| 3152 | ); |
| 3153 | |
| 3154 | if (oddWidth && oddHeight) { |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 3155 | fshaderTxt.append( |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 3156 | " sk_FragColor = (sample(u_texture, v_texCoord0) + " |
| 3157 | " sample(u_texture, v_texCoord1) + " |
| 3158 | " sample(u_texture, v_texCoord2) + " |
| 3159 | " sample(u_texture, v_texCoord3)) * 0.25;" |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3160 | ); |
| 3161 | } else if (oddWidth || oddHeight) { |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 3162 | fshaderTxt.append( |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 3163 | " sk_FragColor = (sample(u_texture, v_texCoord0) + " |
| 3164 | " sample(u_texture, v_texCoord1)) * 0.5;" |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3165 | ); |
| 3166 | } else { |
Ethan Nicholas | 2b3dab6 | 2016-11-28 12:03:26 -0500 | [diff] [blame] | 3167 | fshaderTxt.append( |
Ethan Nicholas | 1386366 | 2019-07-29 13:05:15 -0400 | [diff] [blame] | 3168 | " sk_FragColor = sample(u_texture, v_texCoord0);" |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3169 | ); |
| 3170 | } |
| 3171 | |
| 3172 | fshaderTxt.append("}"); |
| 3173 | |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 3174 | auto errorHandler = this->getContext()->priv().getShaderErrorHandler(); |
Brian Osman | 6c431d5 | 2019-04-15 16:31:54 -0400 | [diff] [blame] | 3175 | SkSL::String sksl(vshaderTxt.c_str(), vshaderTxt.size()); |
Ethan Nicholas | 941e7e2 | 2016-12-12 15:33:30 -0500 | [diff] [blame] | 3176 | SkSL::Program::Settings settings; |
| 3177 | settings.fCaps = shaderCaps; |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 3178 | SkSL::String glsl; |
Brian Osman | ac9be9d | 2019-05-01 10:29:34 -0400 | [diff] [blame] | 3179 | std::unique_ptr<SkSL::Program> program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kVertex_Kind, |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 3180 | sksl, settings, &glsl, errorHandler); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3181 | GrGLuint vshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram, |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 3182 | GR_GL_VERTEX_SHADER, glsl, &fStats, errorHandler); |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 3183 | SkASSERT(program->fInputs.isEmpty()); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3184 | |
Brian Osman | 6c431d5 | 2019-04-15 16:31:54 -0400 | [diff] [blame] | 3185 | sksl.assign(fshaderTxt.c_str(), fshaderTxt.size()); |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 3186 | program = GrSkSLtoGLSL(*fGLContext, SkSL::Program::kFragment_Kind, sksl, settings, &glsl, |
| 3187 | errorHandler); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3188 | GrGLuint fshader = GrGLCompileAndAttachShader(*fGLContext, fMipmapPrograms[progIdx].fProgram, |
Brian Osman | 8518f2e | 2019-05-01 14:13:41 -0400 | [diff] [blame] | 3189 | GR_GL_FRAGMENT_SHADER, glsl, &fStats, |
Brian Osman | 5e7fbfd | 2019-05-03 13:13:35 -0400 | [diff] [blame] | 3190 | errorHandler); |
Ethan Nicholas | d1b2eec | 2017-11-01 15:45:43 -0400 | [diff] [blame] | 3191 | SkASSERT(program->fInputs.isEmpty()); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3192 | |
| 3193 | GL_CALL(LinkProgram(fMipmapPrograms[progIdx].fProgram)); |
| 3194 | |
| 3195 | GL_CALL_RET(fMipmapPrograms[progIdx].fTextureUniform, |
| 3196 | GetUniformLocation(fMipmapPrograms[progIdx].fProgram, "u_texture")); |
| 3197 | GL_CALL_RET(fMipmapPrograms[progIdx].fTexCoordXformUniform, |
| 3198 | GetUniformLocation(fMipmapPrograms[progIdx].fProgram, "u_texCoordXform")); |
| 3199 | |
| 3200 | GL_CALL(BindAttribLocation(fMipmapPrograms[progIdx].fProgram, 0, "a_vertex")); |
| 3201 | |
| 3202 | GL_CALL(DeleteShader(vshader)); |
| 3203 | GL_CALL(DeleteShader(fshader)); |
| 3204 | |
| 3205 | return true; |
| 3206 | } |
| 3207 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3208 | bool GrGLGpu::copySurfaceAsDraw(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3209 | const SkIPoint& dstPoint) { |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 3210 | auto* srcTex = static_cast<GrGLTexture*>(src->asTexture()); |
| 3211 | auto* dstTex = static_cast<GrGLTexture*>(src->asTexture()); |
| 3212 | auto* dstRT = static_cast<GrGLRenderTarget*>(src->asRenderTarget()); |
| 3213 | if (!srcTex) { |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3214 | return false; |
| 3215 | } |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 3216 | int progIdx = TextureToCopyProgramIdx(srcTex); |
| 3217 | if (!dstRT) { |
| 3218 | SkASSERT(dstTex); |
| 3219 | if (!this->glCaps().isFormatRenderable(dstTex->format(), 1)) { |
| 3220 | return false; |
| 3221 | } |
| 3222 | } |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3223 | if (!fCopyPrograms[progIdx].fProgram) { |
| 3224 | if (!this->createCopyProgram(srcTex)) { |
| 3225 | SkDebugf("Failed to create copy program.\n"); |
| 3226 | return false; |
| 3227 | } |
| 3228 | } |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3229 | int w = srcRect.width(); |
| 3230 | int h = srcRect.height(); |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 3231 | // We don't swizzle at all in our copies. |
| 3232 | this->bindTexture(0, GrSamplerState::ClampNearest(), GrSwizzle::RGBA(), srcTex); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3233 | this->bindSurfaceFBOForPixelOps(dst, 0, GR_GL_FRAMEBUFFER, kDst_TempFBOTarget); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3234 | this->flushViewport(dst->width(), dst->height()); |
| 3235 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3236 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, w, h); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3237 | this->flushProgram(fCopyPrograms[progIdx].fProgram); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3238 | fHWVertexArrayState.setVertexArrayID(this, 0); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3239 | GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this); |
| 3240 | attribs->enableVertexArrays(this, 1); |
| 3241 | attribs->set(this, 0, fCopyProgramArrayBuffer.get(), kFloat2_GrVertexAttribType, |
| 3242 | kFloat2_GrSLType, 2 * sizeof(GrGLfloat), 0); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3243 | // dst rect edges in NDC (-1 to 1) |
| 3244 | int dw = dst->width(); |
| 3245 | int dh = dst->height(); |
| 3246 | GrGLfloat dx0 = 2.f * dstPoint.fX / dw - 1.f; |
| 3247 | GrGLfloat dx1 = 2.f * (dstPoint.fX + w) / dw - 1.f; |
| 3248 | GrGLfloat dy0 = 2.f * dstPoint.fY / dh - 1.f; |
| 3249 | GrGLfloat dy1 = 2.f * (dstPoint.fY + h) / dh - 1.f; |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3250 | GrGLfloat sx0 = (GrGLfloat)srcRect.fLeft; |
| 3251 | GrGLfloat sx1 = (GrGLfloat)(srcRect.fLeft + w); |
| 3252 | GrGLfloat sy0 = (GrGLfloat)srcRect.fTop; |
| 3253 | GrGLfloat sy1 = (GrGLfloat)(srcRect.fTop + h); |
| 3254 | int sw = src->width(); |
| 3255 | int sh = src->height(); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3256 | if (srcTex->texturePriv().textureType() != GrTextureType::kRectangle) { |
| 3257 | // src rect edges in normalized texture space (0 to 1) |
| 3258 | sx0 /= sw; |
| 3259 | sx1 /= sw; |
| 3260 | sy0 /= sh; |
| 3261 | sy1 /= sh; |
| 3262 | } |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3263 | GL_CALL(Uniform4f(fCopyPrograms[progIdx].fPosXformUniform, dx1 - dx0, dy1 - dy0, dx0, dy0)); |
| 3264 | GL_CALL(Uniform4f(fCopyPrograms[progIdx].fTexCoordXformUniform, |
| 3265 | sx1 - sx0, sy1 - sy0, sx0, sy0)); |
| 3266 | GL_CALL(Uniform1i(fCopyPrograms[progIdx].fTextureUniform, 0)); |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 3267 | this->flushBlendAndColorWrite(GrXferProcessor::BlendInfo(), GrSwizzle::RGBA()); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3268 | this->flushHWAAState(nullptr, false); |
| 3269 | this->disableScissor(); |
| 3270 | this->disableWindowRectangles(); |
| 3271 | this->disableStencil(); |
| 3272 | if (this->glCaps().srgbWriteControl()) { |
| 3273 | this->flushFramebufferSRGB(true); |
| 3274 | } |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3275 | GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3276 | this->unbindSurfaceFBOForPixelOps(dst, 0, GR_GL_FRAMEBUFFER); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3277 | // The rect is already in device space so we pass in kTopLeft so no flip is done. |
| 3278 | this->didWriteToSurface(dst, kTopLeft_GrSurfaceOrigin, &dstRect); |
Greg Daniel | 4c6f9b7 | 2019-06-06 13:40:59 -0400 | [diff] [blame] | 3279 | return true; |
| 3280 | } |
| 3281 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3282 | void GrGLGpu::copySurfaceAsCopyTexSubImage(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3283 | const SkIPoint& dstPoint) { |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3284 | SkASSERT(can_copy_texsubimage(dst, src, this->glCaps())); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3285 | this->bindSurfaceFBOForPixelOps(src, 0, GR_GL_FRAMEBUFFER, kSrc_TempFBOTarget); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 3286 | GrGLTexture* dstTex = static_cast<GrGLTexture *>(dst->asTexture()); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3287 | SkASSERT(dstTex); |
| 3288 | // We modified the bound FBO |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 3289 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3290 | |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 3291 | this->bindTextureToScratchUnit(dstTex->target(), dstTex->textureID()); |
bsalomon | 10528f1 | 2015-10-14 12:54:52 -0700 | [diff] [blame] | 3292 | GL_CALL(CopyTexSubImage2D(dstTex->target(), 0, |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3293 | dstPoint.fX, dstPoint.fY, |
| 3294 | srcRect.fLeft, srcRect.fTop, |
| 3295 | srcRect.width(), srcRect.height())); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3296 | this->unbindSurfaceFBOForPixelOps(src, 0, GR_GL_FRAMEBUFFER); |
bsalomon | 083617b | 2016-02-12 12:10:14 -0800 | [diff] [blame] | 3297 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 3298 | srcRect.width(), srcRect.height()); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3299 | // The rect is already in device space so we pass in kTopLeft so no flip is done. |
| 3300 | this->didWriteToSurface(dst, kTopLeft_GrSurfaceOrigin, &dstRect); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3301 | } |
| 3302 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3303 | bool GrGLGpu::copySurfaceAsBlitFramebuffer(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3304 | const SkIPoint& dstPoint) { |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3305 | SkASSERT(can_blit_framebuffer_for_copy_surface(dst, src, srcRect, dstPoint, this->glCaps())); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3306 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 3307 | srcRect.width(), srcRect.height()); |
| 3308 | if (dst == src) { |
Mike Reed | 3012cba | 2019-08-26 10:31:13 -0400 | [diff] [blame] | 3309 | if (SkIRect::Intersects(dstRect, srcRect)) { |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3310 | return false; |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame] | 3311 | } |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 3312 | } |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3313 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3314 | this->bindSurfaceFBOForPixelOps(dst, 0, GR_GL_DRAW_FRAMEBUFFER, kDst_TempFBOTarget); |
| 3315 | this->bindSurfaceFBOForPixelOps(src, 0, GR_GL_READ_FRAMEBUFFER, kSrc_TempFBOTarget); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3316 | // We modified the bound FBO |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 3317 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3318 | |
| 3319 | // BlitFrameBuffer respects the scissor, so disable it. |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 3320 | this->disableScissor(); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 3321 | this->disableWindowRectangles(); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3322 | |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3323 | GL_CALL(BlitFramebuffer(srcRect.fLeft, |
| 3324 | srcRect.fTop, |
| 3325 | srcRect.fRight, |
| 3326 | srcRect.fBottom, |
| 3327 | dstRect.fLeft, |
| 3328 | dstRect.fTop, |
| 3329 | dstRect.fRight, |
| 3330 | dstRect.fBottom, |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3331 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3332 | this->unbindSurfaceFBOForPixelOps(dst, 0, GR_GL_DRAW_FRAMEBUFFER); |
| 3333 | this->unbindSurfaceFBOForPixelOps(src, 0, GR_GL_READ_FRAMEBUFFER); |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 3334 | |
| 3335 | // The rect is already in device space so we pass in kTopLeft so no flip is done. |
| 3336 | this->didWriteToSurface(dst, kTopLeft_GrSurfaceOrigin, &dstRect); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3337 | return true; |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 3338 | } |
| 3339 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 3340 | bool GrGLGpu::onRegenerateMipMapLevels(GrTexture* texture) { |
| 3341 | auto glTex = static_cast<GrGLTexture*>(texture); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3342 | // Mipmaps are only supported on 2D textures: |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 3343 | if (GR_GL_TEXTURE_2D != glTex->target()) { |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3344 | return false; |
| 3345 | } |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 3346 | GrGLFormat format = glTex->format(); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 3347 | // Manual implementation of mipmap generation, to work around driver bugs w/sRGB. |
| 3348 | // Uses draw calls to do a series of downsample operations to successive mips. |
| 3349 | |
| 3350 | // The manual approach requires the ability to limit which level we're sampling and that the |
| 3351 | // destination can be bound to a FBO: |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 3352 | if (!this->glCaps().doManualMipmapping() || !this->glCaps().isFormatRenderable(format, 1)) { |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 3353 | GrGLenum target = glTex->target(); |
Brian Salomon | d978b90 | 2019-02-07 15:09:18 -0500 | [diff] [blame] | 3354 | this->bindTextureToScratchUnit(target, glTex->textureID()); |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 3355 | GL_CALL(GenerateMipmap(glTex->target())); |
| 3356 | return true; |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3357 | } |
| 3358 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3359 | int width = texture->width(); |
| 3360 | int height = texture->height(); |
| 3361 | int levelCount = SkMipMap::ComputeLevelCount(width, height) + 1; |
Greg Daniel | da86e28 | 2018-06-13 09:41:19 -0400 | [diff] [blame] | 3362 | SkASSERT(levelCount == texture->texturePriv().maxMipMapLevel() + 1); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3363 | |
| 3364 | // Create (if necessary), then bind temporary FBO: |
| 3365 | if (0 == fTempDstFBOID) { |
| 3366 | GL_CALL(GenFramebuffers(1, &fTempDstFBOID)); |
| 3367 | } |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 3368 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, fTempDstFBOID); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 3369 | fHWBoundRenderTargetUniqueID.makeInvalid(); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3370 | |
| 3371 | // Bind the texture, to get things configured for filtering. |
| 3372 | // We'll be changing our base level further below: |
| 3373 | this->setTextureUnit(0); |
Greg Daniel | 2c3398d | 2019-06-19 11:58:01 -0400 | [diff] [blame] | 3374 | // The mipmap program does not do any swizzling. |
| 3375 | this->bindTexture(0, GrSamplerState::ClampBilerp(), GrSwizzle::RGBA(), glTex); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3376 | |
| 3377 | // Vertex data: |
| 3378 | if (!fMipmapProgramArrayBuffer) { |
| 3379 | static const GrGLfloat vdata[] = { |
| 3380 | 0, 0, |
| 3381 | 0, 1, |
| 3382 | 1, 0, |
| 3383 | 1, 1 |
| 3384 | }; |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 3385 | fMipmapProgramArrayBuffer = GrGLBuffer::Make(this, sizeof(vdata), GrGpuBufferType::kVertex, |
Brian Salomon | 12d2264 | 2019-01-29 14:38:50 -0500 | [diff] [blame] | 3386 | kStatic_GrAccessPattern, vdata); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3387 | } |
| 3388 | if (!fMipmapProgramArrayBuffer) { |
| 3389 | return false; |
| 3390 | } |
| 3391 | |
| 3392 | fHWVertexArrayState.setVertexArrayID(this, 0); |
| 3393 | |
| 3394 | GrGLAttribArrayState* attribs = fHWVertexArrayState.bindInternalVertexArray(this); |
Chris Dalton | 8e45b4f | 2017-05-05 14:00:56 -0400 | [diff] [blame] | 3395 | attribs->enableVertexArrays(this, 1); |
Brian Osman | d4c2970 | 2018-09-14 16:16:55 -0400 | [diff] [blame] | 3396 | attribs->set(this, 0, fMipmapProgramArrayBuffer.get(), kFloat2_GrVertexAttribType, |
Brian Osman | 4a3f5c8 | 2018-09-18 16:16:38 -0400 | [diff] [blame] | 3397 | kFloat2_GrSLType, 2 * sizeof(GrGLfloat), 0); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3398 | |
| 3399 | // Set "simple" state once: |
Chris Dalton | bbb3f64 | 2019-07-24 12:25:08 -0400 | [diff] [blame] | 3400 | this->flushBlendAndColorWrite(GrXferProcessor::BlendInfo(), GrSwizzle::RGBA()); |
Chris Dalton | 4c56b03 | 2019-03-04 12:28:42 -0700 | [diff] [blame] | 3401 | this->flushHWAAState(nullptr, false); |
Brian Salomon | d818ebf | 2018-07-02 14:08:49 +0000 | [diff] [blame] | 3402 | this->disableScissor(); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 3403 | this->disableWindowRectangles(); |
csmartdalton | c7d8533 | 2016-10-26 10:13:46 -0700 | [diff] [blame] | 3404 | this->disableStencil(); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3405 | |
| 3406 | // Do all the blits: |
| 3407 | width = texture->width(); |
| 3408 | height = texture->height(); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 3409 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3410 | for (GrGLint level = 1; level < levelCount; ++level) { |
| 3411 | // Get and bind the program for this particular downsample (filter shape can vary): |
| 3412 | int progIdx = TextureSizeToMipmapProgramIdx(width, height); |
| 3413 | if (!fMipmapPrograms[progIdx].fProgram) { |
| 3414 | if (!this->createMipmapProgram(progIdx)) { |
| 3415 | SkDebugf("Failed to create mipmap program.\n"); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 3416 | // Invalidate all params to cover base level change in a previous iteration. |
| 3417 | glTex->textureParamsModified(); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3418 | return false; |
| 3419 | } |
| 3420 | } |
Brian Salomon | 802cb31 | 2018-06-08 18:05:20 -0400 | [diff] [blame] | 3421 | this->flushProgram(fMipmapPrograms[progIdx].fProgram); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3422 | |
| 3423 | // Texcoord uniform is expected to contain (1/w, (w-1)/w, 1/h, (h-1)/h) |
| 3424 | const float invWidth = 1.0f / width; |
| 3425 | const float invHeight = 1.0f / height; |
| 3426 | GL_CALL(Uniform4f(fMipmapPrograms[progIdx].fTexCoordXformUniform, |
| 3427 | invWidth, (width - 1) * invWidth, invHeight, (height - 1) * invHeight)); |
| 3428 | GL_CALL(Uniform1i(fMipmapPrograms[progIdx].fTextureUniform, 0)); |
| 3429 | |
| 3430 | // Only sample from previous mip |
| 3431 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_BASE_LEVEL, level - 1)); |
| 3432 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 3433 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, GR_GL_TEXTURE_2D, |
| 3434 | glTex->textureID(), level)); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3435 | |
| 3436 | width = SkTMax(1, width / 2); |
| 3437 | height = SkTMax(1, height / 2); |
Greg Daniel | acd66b4 | 2019-05-22 16:29:12 -0400 | [diff] [blame] | 3438 | this->flushViewport(width, height); |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3439 | |
| 3440 | GL_CALL(DrawArrays(GR_GL_TRIANGLE_STRIP, 0, 4)); |
| 3441 | } |
| 3442 | |
| 3443 | // Unbind: |
| 3444 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, |
| 3445 | GR_GL_TEXTURE_2D, 0, 0)); |
| 3446 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 3447 | // We modified the base level param. |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 3448 | GrGLTextureParameters::NonsamplerState nonsamplerState = glTex->parameters()->nonsamplerState(); |
| 3449 | // We drew the 2nd to last level into the last level. |
| 3450 | nonsamplerState.fBaseMipMapLevel = levelCount - 2; |
| 3451 | glTex->parameters()->set(nullptr, nonsamplerState, fResetTimestampForTextureParameters); |
Brian Salomon | dc82994 | 2018-10-23 16:07:24 -0400 | [diff] [blame] | 3452 | |
brianosman | 33f6b3f | 2016-06-02 05:49:21 -0700 | [diff] [blame] | 3453 | return true; |
| 3454 | } |
| 3455 | |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 3456 | void GrGLGpu::querySampleLocations( |
Chris Dalton | 8c4cafd | 2019-04-15 19:14:36 -0600 | [diff] [blame] | 3457 | GrRenderTarget* renderTarget, SkTArray<SkPoint>* sampleLocations) { |
| 3458 | this->flushRenderTargetNoColorWrites(static_cast<GrGLRenderTarget*>(renderTarget)); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 3459 | |
| 3460 | int effectiveSampleCnt; |
| 3461 | GR_GL_GetIntegerv(this->glInterface(), GR_GL_SAMPLES, &effectiveSampleCnt); |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 3462 | SkASSERT(effectiveSampleCnt >= renderTarget->numSamples()); |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 3463 | |
| 3464 | sampleLocations->reset(effectiveSampleCnt); |
| 3465 | for (int i = 0; i < effectiveSampleCnt; ++i) { |
| 3466 | GL_CALL(GetMultisamplefv(GR_GL_SAMPLE_POSITION, i, &(*sampleLocations)[i].fX)); |
| 3467 | } |
| 3468 | } |
| 3469 | |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 3470 | void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 3471 | SkASSERT(type); |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 3472 | switch (type) { |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 3473 | case kTexture_GrXferBarrierType: { |
| 3474 | GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); |
Brian Osman | cfe83d1 | 2018-01-19 11:13:45 -0500 | [diff] [blame] | 3475 | SkASSERT(glrt->textureFBOID() != 0 && glrt->renderFBOID() != 0); |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 3476 | if (glrt->textureFBOID() != glrt->renderFBOID()) { |
| 3477 | // The render target uses separate storage so no need for glTextureBarrier. |
| 3478 | // FIXME: The render target will resolve automatically when its texture is bound, |
| 3479 | // but we could resolve only the bounds that will be read if we do it here instead. |
| 3480 | return; |
| 3481 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 3482 | SkASSERT(this->caps()->textureBarrierSupport()); |
| 3483 | GL_CALL(TextureBarrier()); |
| 3484 | return; |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 3485 | } |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 3486 | case kBlend_GrXferBarrierType: |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 3487 | SkASSERT(GrCaps::kAdvanced_BlendEquationSupport == |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 3488 | this->caps()->blendEquationSupport()); |
| 3489 | GL_CALL(BlendBarrier()); |
| 3490 | return; |
bsalomon | cb02b38 | 2015-08-12 11:14:50 -0700 | [diff] [blame] | 3491 | default: break; // placate compiler warnings that kNone not handled |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 3492 | } |
| 3493 | } |
| 3494 | |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3495 | static GrPixelConfig gl_format_to_pixel_config(GrGLFormat format) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 3496 | switch (format) { |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3497 | case GrGLFormat::kRGBA8: return kRGBA_8888_GrPixelConfig; |
| 3498 | case GrGLFormat::kRGB8: return kRGB_888_GrPixelConfig; |
| 3499 | case GrGLFormat::kRG8: return kRG_88_GrPixelConfig; |
| 3500 | case GrGLFormat::kBGRA8: return kBGRA_8888_GrPixelConfig; |
| 3501 | case GrGLFormat::kLUMINANCE8: return kGray_8_GrPixelConfig; |
| 3502 | case GrGLFormat::kSRGB8_ALPHA8: return kSRGBA_8888_GrPixelConfig; |
| 3503 | case GrGLFormat::kRGB10_A2: return kRGBA_1010102_GrPixelConfig; |
| 3504 | case GrGLFormat::kRGB565: return kRGB_565_GrPixelConfig; |
| 3505 | case GrGLFormat::kRGBA4: return kRGBA_4444_GrPixelConfig; |
| 3506 | case GrGLFormat::kRGBA32F: return kRGBA_float_GrPixelConfig; |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3507 | case GrGLFormat::kRGBA16F: return kRGBA_half_GrPixelConfig; |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3508 | case GrGLFormat::kR16: return kR_16_GrPixelConfig; |
| 3509 | case GrGLFormat::kRG16: return kRG_1616_GrPixelConfig; |
| 3510 | case GrGLFormat::kRGBA16: return kRGBA_16161616_GrPixelConfig; |
| 3511 | case GrGLFormat::kRG16F: return kRG_half_GrPixelConfig; |
| 3512 | case GrGLFormat::kUnknown: return kUnknown_GrPixelConfig; |
Robert Phillips | 66a4603 | 2019-06-18 08:00:42 -0400 | [diff] [blame] | 3513 | |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3514 | // Configs with multiple equivalent formats. |
| 3515 | |
Robert Phillips | ebab03f | 2019-07-22 08:48:18 -0400 | [diff] [blame] | 3516 | case GrGLFormat::kR16F: return kAlpha_half_GrPixelConfig; |
| 3517 | case GrGLFormat::kLUMINANCE16F: return kAlpha_half_GrPixelConfig; |
| 3518 | |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3519 | case GrGLFormat::kALPHA8: return kAlpha_8_GrPixelConfig; |
| 3520 | case GrGLFormat::kR8: return kAlpha_8_GrPixelConfig; |
| 3521 | |
| 3522 | case GrGLFormat::kCOMPRESSED_RGB8_ETC2: return kRGB_ETC1_GrPixelConfig; |
| 3523 | case GrGLFormat::kCOMPRESSED_ETC1_RGB8: return kRGB_ETC1_GrPixelConfig; |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 3524 | } |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3525 | SkUNREACHABLE; |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 3526 | } |
| 3527 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 3528 | GrBackendTexture GrGLGpu::createBackendTexture(int w, int h, |
| 3529 | const GrBackendFormat& format, |
| 3530 | GrMipMapped mipMapped, |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 3531 | GrRenderable renderable, |
Robert Phillips | 28a5a43 | 2019-06-07 12:46:21 -0400 | [diff] [blame] | 3532 | const void* srcPixels, size_t rowBytes, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 3533 | const SkColor4f* color, |
| 3534 | GrProtected isProtected) { |
Brian Salomon | 8a37583 | 2018-03-14 10:21:40 -0400 | [diff] [blame] | 3535 | this->handleDirtyContext(); |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 3536 | |
Brian Salomon | d4764a1 | 2019-08-08 12:08:24 -0400 | [diff] [blame] | 3537 | GrGLFormat glFormat = format.asGLFormat(); |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3538 | if (glFormat == GrGLFormat::kUnknown) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 3539 | return GrBackendTexture(); // invalid |
| 3540 | } |
| 3541 | |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3542 | GrPixelConfig config = gl_format_to_pixel_config(glFormat); |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 3543 | |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3544 | if (config == kUnknown_GrPixelConfig) { |
Robert Phillips | 9dbcdcc | 2019-05-13 10:40:06 -0400 | [diff] [blame] | 3545 | return GrBackendTexture(); // invalid |
| 3546 | } |
| 3547 | |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 3548 | auto textureColorType = GrPixelConfigToColorType(config); |
| 3549 | |
| 3550 | if (!this->caps()->isFormatTexturableAndUploadable(textureColorType, format)) { |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3551 | return GrBackendTexture(); // invalid |
| 3552 | } |
| 3553 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3554 | if (w < 1 || w > this->caps()->maxTextureSize() || |
| 3555 | h < 1 || h > this->caps()->maxTextureSize()) { |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 3556 | return GrBackendTexture(); // invalid |
| 3557 | } |
| 3558 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3559 | // Currently we don't support uploading pixel data when mipped. |
Robert Phillips | 28a5a43 | 2019-06-07 12:46:21 -0400 | [diff] [blame] | 3560 | if (srcPixels && GrMipMapped::kYes == mipMapped) { |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3561 | return GrBackendTexture(); // invalid |
| 3562 | } |
| 3563 | |
Brian Salomon | 4687bdd | 2019-05-09 16:28:04 -0400 | [diff] [blame] | 3564 | if (mipMapped == GrMipMapped::kYes && !this->caps()->mipMapSupport()) { |
Robert Phillips | e3bd673 | 2019-05-29 14:20:35 -0400 | [diff] [blame] | 3565 | return GrBackendTexture(); // invalid |
Brian Salomon | 4687bdd | 2019-05-09 16:28:04 -0400 | [diff] [blame] | 3566 | } |
Robert Phillips | 646f637 | 2018-09-25 09:31:10 -0400 | [diff] [blame] | 3567 | |
Greg Daniel | 1550064 | 2019-06-27 03:05:55 +0000 | [diff] [blame] | 3568 | GrGLTextureInfo info; |
| 3569 | GrGLTextureParameters::SamplerOverriddenState initialState; |
| 3570 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3571 | SkTDArray<GrMipLevel> texels; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3572 | SkAutoMalloc pixelStorage; |
| 3573 | SkImage::CompressionType compressionType; |
Brian Salomon | 5043f1f | 2019-07-11 21:27:54 -0400 | [diff] [blame] | 3574 | if (GrGLFormatToCompressionType(glFormat, &compressionType)) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3575 | // Compressed textures currently must be non-MIP mapped and have initial data. |
| 3576 | if (mipMapped == GrMipMapped::kYes) { |
| 3577 | return GrBackendTexture(); |
| 3578 | } |
| 3579 | if (!srcPixels) { |
| 3580 | if (!color) { |
| 3581 | return GrBackendTexture(); |
| 3582 | } |
| 3583 | SkASSERT(0 == rowBytes); |
| 3584 | size_t size = GrCompressedDataSize(compressionType, w, h); |
| 3585 | srcPixels = pixelStorage.reset(size); |
| 3586 | GrFillInCompressedData(compressionType, w, h, (char*)srcPixels, *color); |
| 3587 | } |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 3588 | info.fID = this->createCompressedTexture2D( |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 3589 | {w, h}, glFormat, compressionType, &initialState, srcPixels); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 3590 | if (!info.fID) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3591 | return GrBackendTexture(); |
| 3592 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 3593 | info.fFormat = GrGLFormatToEnum(glFormat); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 3594 | info.fTarget = GR_GL_TEXTURE_2D; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3595 | } else { |
| 3596 | if (srcPixels) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3597 | texels.append(1); |
| 3598 | texels[0] = {srcPixels, rowBytes}; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3599 | } else if (color) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3600 | int mipLevelCount = 1; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3601 | if (GrMipMapped::kYes == mipMapped) { |
| 3602 | mipLevelCount = SkMipMap::ComputeLevelCount(w, h) + 1; |
| 3603 | } |
| 3604 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3605 | texels.append(mipLevelCount); |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3606 | SkTArray<size_t> individualMipOffsets(mipLevelCount); |
| 3607 | |
| 3608 | size_t bytesPerPixel = GrBytesPerPixel(config); |
| 3609 | |
| 3610 | size_t totalSize = GrComputeTightCombinedBufferSize( |
| 3611 | bytesPerPixel, w, h, &individualMipOffsets, mipLevelCount); |
| 3612 | |
| 3613 | char* tmpPixels = (char*)pixelStorage.reset(totalSize); |
| 3614 | |
| 3615 | GrFillInData(config, w, h, individualMipOffsets, tmpPixels, *color); |
| 3616 | for (int i = 0; i < mipLevelCount; ++i) { |
| 3617 | size_t offset = individualMipOffsets[i]; |
| 3618 | |
| 3619 | int twoToTheMipLevel = 1 << i; |
| 3620 | int currentWidth = SkTMax(1, w / twoToTheMipLevel); |
| 3621 | |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3622 | texels[i] = {&(tmpPixels[offset]), currentWidth * bytesPerPixel}; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3623 | } |
| 3624 | } |
| 3625 | GrSurfaceDesc desc; |
| 3626 | desc.fWidth = w; |
| 3627 | desc.fHeight = h; |
| 3628 | desc.fConfig = config; |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 3629 | |
| 3630 | info.fTarget = GR_GL_TEXTURE_2D; |
| 3631 | info.fFormat = GrGLFormatToEnum(glFormat); |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3632 | info.fID = this->createTexture2D({desc.fWidth, desc.fHeight}, glFormat, renderable, |
| 3633 | &initialState, SkTMax(1, texels.count())); |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 3634 | if (!info.fID) { |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 3635 | return GrBackendTexture(); // invalid |
| 3636 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3637 | auto srcColorType = GrPixelConfigToColorType(desc.fConfig); |
| 3638 | if (!texels.empty() && |
| 3639 | !this->uploadTexData(glFormat, textureColorType, desc.fWidth, desc.fHeight, |
| 3640 | GR_GL_TEXTURE_2D, 0, 0, desc.fWidth, desc.fHeight, srcColorType, |
| 3641 | texels.begin(), texels.count())) { |
| 3642 | GL_CALL(DeleteTextures(1, &info.fID)); |
| 3643 | return GrBackendTexture(); |
| 3644 | } |
Robert Phillips | e3bd673 | 2019-05-29 14:20:35 -0400 | [diff] [blame] | 3645 | } |
Robert Phillips | b04b694 | 2019-05-21 17:24:31 -0400 | [diff] [blame] | 3646 | |
Robert Phillips | e8fabb2 | 2018-02-04 14:33:21 -0500 | [diff] [blame] | 3647 | // unbind the texture from the texture unit to avoid asserts |
| 3648 | GL_CALL(BindTexture(info.fTarget, 0)); |
| 3649 | |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 3650 | auto parameters = sk_make_sp<GrGLTextureParameters>(); |
| 3651 | parameters->set(&initialState, GrGLTextureParameters::NonsamplerState(), |
| 3652 | fResetTimestampForTextureParameters); |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 3653 | |
| 3654 | return GrBackendTexture(w, h, mipMapped, info, std::move(parameters)); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3655 | } |
| 3656 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 3657 | void GrGLGpu::deleteBackendTexture(const GrBackendTexture& tex) { |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 3658 | SkASSERT(GrBackendApi::kOpenGL == tex.backend()); |
| 3659 | |
| 3660 | GrGLTextureInfo info; |
| 3661 | if (tex.getGLTextureInfo(&info)) { |
| 3662 | GL_CALL(DeleteTextures(1, &info.fID)); |
| 3663 | } |
| 3664 | } |
| 3665 | |
| 3666 | #if GR_TEST_UTILS |
| 3667 | |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3668 | bool GrGLGpu::isTestingOnlyBackendTexture(const GrBackendTexture& tex) const { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 3669 | SkASSERT(GrBackendApi::kOpenGL == tex.backend()); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3670 | |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 3671 | GrGLTextureInfo info; |
| 3672 | if (!tex.getGLTextureInfo(&info)) { |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3673 | return false; |
| 3674 | } |
| 3675 | |
| 3676 | GrGLboolean result; |
Greg Daniel | 52e16d9 | 2018-04-10 09:34:07 -0400 | [diff] [blame] | 3677 | GL_CALL_RET(result, IsTexture(info.fID)); |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 3678 | |
| 3679 | return (GR_GL_TRUE == result); |
| 3680 | } |
| 3681 | |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3682 | GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(int w, int h, |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 3683 | GrColorType colorType) { |
Greg Daniel | 92cbf3f | 2018-04-12 16:50:17 -0400 | [diff] [blame] | 3684 | if (w > this->caps()->maxRenderTargetSize() || h > this->caps()->maxRenderTargetSize()) { |
| 3685 | return GrBackendRenderTarget(); // invalid |
| 3686 | } |
Brian Salomon | 8a37583 | 2018-03-14 10:21:40 -0400 | [diff] [blame] | 3687 | this->handleDirtyContext(); |
Greg Daniel | 0258c90 | 2019-08-01 13:08:33 -0400 | [diff] [blame] | 3688 | auto format = this->glCaps().getFormatFromColorType(colorType); |
Greg Daniel | 900583a | 2019-08-06 12:05:31 -0400 | [diff] [blame] | 3689 | if (!this->glCaps().isFormatRenderable(format, 1)) { |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3690 | return {}; |
| 3691 | } |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3692 | bool useTexture = format == GrGLFormat::kBGRA8; |
Brian Salomon | f6da146 | 2019-07-11 14:21:59 -0400 | [diff] [blame] | 3693 | int sFormatIdx = this->getCompatibleStencilIndex(format); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3694 | if (sFormatIdx < 0) { |
| 3695 | return {}; |
| 3696 | } |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3697 | GrGLuint colorID = 0; |
| 3698 | GrGLuint stencilID = 0; |
| 3699 | auto deleteIDs = [&] { |
| 3700 | if (colorID) { |
| 3701 | if (useTexture) { |
| 3702 | GL_CALL(DeleteTextures(1, &colorID)); |
| 3703 | } else { |
| 3704 | GL_CALL(DeleteRenderbuffers(1, &colorID)); |
| 3705 | } |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3706 | } |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3707 | if (stencilID) { |
| 3708 | GL_CALL(DeleteRenderbuffers(1, &stencilID)); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3709 | } |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3710 | }; |
| 3711 | |
| 3712 | if (useTexture) { |
| 3713 | GL_CALL(GenTextures(1, &colorID)); |
| 3714 | } else { |
| 3715 | GL_CALL(GenRenderbuffers(1, &colorID)); |
| 3716 | } |
| 3717 | GL_CALL(GenRenderbuffers(1, &stencilID)); |
| 3718 | if (!stencilID || !colorID) { |
| 3719 | deleteIDs(); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3720 | return {}; |
| 3721 | } |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3722 | |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3723 | GrGLFramebufferInfo info; |
| 3724 | info.fFBOID = 0; |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3725 | info.fFormat = GrGLFormatToEnum(format); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3726 | GL_CALL(GenFramebuffers(1, &info.fFBOID)); |
| 3727 | if (!info.fFBOID) { |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3728 | deleteIDs(); |
| 3729 | return {}; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3730 | } |
| 3731 | |
| 3732 | this->invalidateBoundRenderTarget(); |
| 3733 | |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 3734 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, info.fFBOID); |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3735 | if (useTexture) { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3736 | GrGLTextureParameters::SamplerOverriddenState initialState; |
| 3737 | colorID = this->createTexture2D({w, h}, format, GrRenderable::kYes, &initialState, 1); |
| 3738 | if (!colorID) { |
| 3739 | deleteIDs(); |
| 3740 | return {}; |
| 3741 | } |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3742 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, GR_GL_TEXTURE_2D, |
| 3743 | colorID, 0)); |
| 3744 | } else { |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3745 | GrGLenum renderBufferFormat = this->glCaps().getRenderbufferInternalFormat(format); |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3746 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, colorID)); |
| 3747 | GL_ALLOC_CALL(this->glInterface(), |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame^] | 3748 | RenderbufferStorage(GR_GL_RENDERBUFFER, renderBufferFormat, w, h)); |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3749 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_COLOR_ATTACHMENT0, |
| 3750 | GR_GL_RENDERBUFFER, colorID)); |
| 3751 | } |
| 3752 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, stencilID)); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3753 | auto stencilBufferFormat = this->glCaps().stencilFormats()[sFormatIdx].fInternalFormat; |
| 3754 | GL_ALLOC_CALL(this->glInterface(), |
| 3755 | RenderbufferStorage(GR_GL_RENDERBUFFER, stencilBufferFormat, w, h)); |
| 3756 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_STENCIL_ATTACHMENT, GR_GL_RENDERBUFFER, |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3757 | stencilID)); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3758 | if (this->glCaps().stencilFormats()[sFormatIdx].fPacked) { |
| 3759 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, GR_GL_DEPTH_ATTACHMENT, |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3760 | GR_GL_RENDERBUFFER, stencilID)); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3761 | } |
| 3762 | |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3763 | // We don't want to have to recover the renderbuffer/texture IDs later to delete them. OpenGL |
| 3764 | // has this rule that if a renderbuffer/texture is deleted and a FBO other than the current FBO |
| 3765 | // has the RB attached then deletion is delayed. So we unbind the FBO here and delete the |
| 3766 | // renderbuffers/texture. |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 3767 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, 0); |
Brian Salomon | 93348dd | 2018-08-29 12:56:23 -0400 | [diff] [blame] | 3768 | deleteIDs(); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3769 | |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 3770 | this->bindFramebuffer(GR_GL_FRAMEBUFFER, info.fFBOID); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3771 | GrGLenum status; |
| 3772 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 3773 | if (GR_GL_FRAMEBUFFER_COMPLETE != status) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 3774 | this->deleteFramebuffer(info.fFBOID); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3775 | return {}; |
| 3776 | } |
| 3777 | auto stencilBits = SkToInt(this->glCaps().stencilFormats()[sFormatIdx].fStencilBits); |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 3778 | |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 3779 | GrBackendRenderTarget beRT = GrBackendRenderTarget(w, h, 1, stencilBits, info); |
Robert Phillips | 62221e7 | 2019-07-24 15:07:38 -0400 | [diff] [blame] | 3780 | SkASSERT(this->caps()->areColorTypeAndFormatCompatible(colorType, beRT.getBackendFormat())); |
Greg Daniel | 108bb23 | 2018-07-03 16:18:29 -0400 | [diff] [blame] | 3781 | return beRT; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | void GrGLGpu::deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget& backendRT) { |
Greg Daniel | bdf12ad | 2018-10-12 09:31:11 -0400 | [diff] [blame] | 3785 | SkASSERT(GrBackendApi::kOpenGL == backendRT.backend()); |
Greg Daniel | 323fbcf | 2018-04-10 13:46:30 -0400 | [diff] [blame] | 3786 | GrGLFramebufferInfo info; |
| 3787 | if (backendRT.getGLFramebufferInfo(&info)) { |
| 3788 | if (info.fFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 3789 | this->deleteFramebuffer(info.fFBOID); |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3790 | } |
| 3791 | } |
joshualitt | 8fd844f | 2015-12-02 13:36:47 -0800 | [diff] [blame] | 3792 | } |
| 3793 | |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 3794 | void GrGLGpu::testingOnly_flushGpuAndSync() { |
| 3795 | GL_CALL(Finish()); |
| 3796 | } |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 3797 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 3798 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 3799 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3800 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 3801 | GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray(GrGLGpu* gpu, |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 3802 | const GrBuffer* ibuf) { |
robertphillips@google.com | 4f65a27 | 2013-03-26 19:40:46 +0000 | [diff] [blame] | 3803 | GrGLAttribArrayState* attribState; |
| 3804 | |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 3805 | if (gpu->glCaps().isCoreProfile()) { |
| 3806 | if (!fCoreProfileVertexArray) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 3807 | GrGLuint arrayID; |
| 3808 | GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); |
| 3809 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 3810 | fCoreProfileVertexArray = new GrGLVertexArray(arrayID, attrCount); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 3811 | } |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 3812 | if (ibuf) { |
| 3813 | attribState = fCoreProfileVertexArray->bindWithIndexBuffer(gpu, ibuf); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3814 | } else { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 3815 | attribState = fCoreProfileVertexArray->bind(gpu); |
bsalomon | 6df8640 | 2015-06-01 10:41:49 -0700 | [diff] [blame] | 3816 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 3817 | } else { |
cdalton | e2e71c2 | 2016-04-07 18:13:29 -0700 | [diff] [blame] | 3818 | if (ibuf) { |
| 3819 | // bindBuffer implicitly binds VAO 0 when binding an index buffer. |
Brian Salomon | ae64c19 | 2019-02-05 09:41:37 -0500 | [diff] [blame] | 3820 | gpu->bindBuffer(GrGpuBufferType::kIndex, ibuf); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 3821 | } else { |
| 3822 | this->setVertexArrayID(gpu, 0); |
| 3823 | } |
| 3824 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 3825 | if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 3826 | fDefaultVertexArrayAttribState.resize(attrCount); |
| 3827 | } |
| 3828 | attribState = &fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 3829 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 3830 | return attribState; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 3831 | } |
bsalomon | e179a91 | 2016-01-20 06:18:10 -0800 | [diff] [blame] | 3832 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 3833 | void GrGLGpu::onFinishFlush(GrSurfaceProxy*[], int, SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 3834 | const GrFlushInfo& info, const GrPrepareForExternalIORequests&) { |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 3835 | // If we inserted semaphores during the flush, we need to call GLFlush. |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 3836 | bool insertedSemaphore = info.fNumSemaphores > 0 && this->caps()->semaphoreSupport(); |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 3837 | // We call finish if the client told us to sync or if we have a finished proc but don't support |
| 3838 | // GLsync objects. |
| 3839 | bool finish = (info.fFlags & kSyncCpu_GrFlushFlag) || |
| 3840 | (info.fFinishedProc && !this->caps()->fenceSyncSupport()); |
| 3841 | if (finish) { |
Greg Daniel | bae7121 | 2019-03-01 15:24:35 -0500 | [diff] [blame] | 3842 | GL_CALL(Finish()); |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 3843 | // After a finish everything previously sent to GL is done. |
| 3844 | for (const auto& cb : fFinishCallbacks) { |
| 3845 | cb.fCallback(cb.fContext); |
| 3846 | this->deleteSync(cb.fSync); |
| 3847 | } |
| 3848 | fFinishCallbacks.clear(); |
| 3849 | if (info.fFinishedProc) { |
| 3850 | info.fFinishedProc(info.fFinishedContext); |
| 3851 | } |
| 3852 | } else { |
| 3853 | if (info.fFinishedProc) { |
| 3854 | FinishCallback callback; |
| 3855 | callback.fCallback = info.fFinishedProc; |
| 3856 | callback.fContext = info.fFinishedContext; |
| 3857 | callback.fSync = (GrGLsync)this->insertFence(); |
| 3858 | fFinishCallbacks.push_back(callback); |
| 3859 | GL_CALL(Flush()); |
| 3860 | } else if (insertedSemaphore) { |
| 3861 | // Must call flush after semaphores in case they are waited on another GL context. |
| 3862 | GL_CALL(Flush()); |
| 3863 | } |
| 3864 | // See if any previously inserted finish procs are good to go. |
| 3865 | this->checkFinishProcs(); |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 3866 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 3867 | } |
| 3868 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 3869 | void GrGLGpu::submit(GrOpsRenderPass* renderPass) { |
| 3870 | // The GrGLOpsRenderPass doesn't buffer ops so there is nothing to do here |
| 3871 | SkASSERT(fCachedOpsRenderPass.get() == renderPass); |
| 3872 | fCachedOpsRenderPass->reset(); |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 3873 | } |
| 3874 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3875 | GrFence SK_WARN_UNUSED_RESULT GrGLGpu::insertFence() { |
Greg Daniel | c64ee46 | 2017-06-15 16:59:49 -0400 | [diff] [blame] | 3876 | SkASSERT(this->caps()->fenceSyncSupport()); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3877 | GrGLsync sync; |
| 3878 | GL_CALL_RET(sync, FenceSync(GR_GL_SYNC_GPU_COMMANDS_COMPLETE, 0)); |
| 3879 | GR_STATIC_ASSERT(sizeof(GrFence) >= sizeof(GrGLsync)); |
| 3880 | return (GrFence)sync; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 3881 | } |
| 3882 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 3883 | bool GrGLGpu::waitSync(GrGLsync sync, uint64_t timeout, bool flush) { |
| 3884 | GrGLbitfield flags = flush ? GR_GL_SYNC_FLUSH_COMMANDS_BIT : 0; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 3885 | GrGLenum result; |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 3886 | GL_CALL_RET(result, ClientWaitSync(sync, flags, timeout)); |
| 3887 | return (GR_GL_CONDITION_SATISFIED == result || GR_GL_ALREADY_SIGNALED == result); |
| 3888 | } |
| 3889 | |
| 3890 | bool GrGLGpu::waitFence(GrFence fence, uint64_t timeout) { |
| 3891 | return this->waitSync((GrGLsync)fence, timeout, /* flush = */ true); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | void GrGLGpu::deleteFence(GrFence fence) const { |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3895 | this->deleteSync((GrGLsync)fence); |
| 3896 | } |
| 3897 | |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 3898 | sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT GrGLGpu::makeSemaphore(bool isOwned) { |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 3899 | SkASSERT(this->caps()->semaphoreSupport()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 3900 | return GrGLSemaphore::Make(this, isOwned); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3901 | } |
| 3902 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 3903 | sk_sp<GrSemaphore> GrGLGpu::wrapBackendSemaphore(const GrBackendSemaphore& semaphore, |
| 3904 | GrResourceProvider::SemaphoreWrapType wrapType, |
| 3905 | GrWrapOwnership ownership) { |
Brian Salomon | 9ff5acb | 2019-05-08 09:04:47 -0400 | [diff] [blame] | 3906 | SkASSERT(this->caps()->semaphoreSupport()); |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 3907 | return GrGLSemaphore::MakeWrapped(this, semaphore.glSync(), ownership); |
| 3908 | } |
| 3909 | |
Greg Daniel | 858e12c | 2018-12-06 11:11:37 -0500 | [diff] [blame] | 3910 | void GrGLGpu::insertSemaphore(sk_sp<GrSemaphore> semaphore) { |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3911 | GrGLSemaphore* glSem = static_cast<GrGLSemaphore*>(semaphore.get()); |
| 3912 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 3913 | GrGLsync sync; |
| 3914 | GL_CALL_RET(sync, FenceSync(GR_GL_SYNC_GPU_COMMANDS_COMPLETE, 0)); |
| 3915 | glSem->setSync(sync); |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3916 | } |
| 3917 | |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 3918 | void GrGLGpu::waitSemaphore(sk_sp<GrSemaphore> semaphore) { |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3919 | GrGLSemaphore* glSem = static_cast<GrGLSemaphore*>(semaphore.get()); |
| 3920 | |
| 3921 | GL_CALL(WaitSync(glSem->sync(), 0, GR_GL_TIMEOUT_IGNORED)); |
| 3922 | } |
| 3923 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 3924 | void GrGLGpu::checkFinishProcs() { |
| 3925 | // Bail after the first unfinished sync since we expect they signal in the order inserted. |
| 3926 | while (!fFinishCallbacks.empty() && this->waitSync(fFinishCallbacks.front().fSync, |
| 3927 | /* timeout = */ 0, /* flush = */ false)) { |
| 3928 | fFinishCallbacks.front().fCallback(fFinishCallbacks.front().fContext); |
| 3929 | this->deleteSync(fFinishCallbacks.front().fSync); |
| 3930 | fFinishCallbacks.pop_front(); |
| 3931 | } |
| 3932 | } |
| 3933 | |
Greg Daniel | 6be3523 | 2017-03-01 17:01:09 -0500 | [diff] [blame] | 3934 | void GrGLGpu::deleteSync(GrGLsync sync) const { |
| 3935 | GL_CALL(DeleteSync(sync)); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 3936 | } |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 3937 | |
Robert Phillips | 65a88fa | 2017-08-08 08:36:22 -0400 | [diff] [blame] | 3938 | void GrGLGpu::insertEventMarker(const char* msg) { |
| 3939 | GL_CALL(InsertEventMarker(strlen(msg), msg)); |
| 3940 | } |
| 3941 | |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 3942 | sk_sp<GrSemaphore> GrGLGpu::prepareTextureForCrossContextUsage(GrTexture* texture) { |
| 3943 | // Set up a semaphore to be signaled once the data is ready, and flush GL |
Greg Daniel | a5cb781 | 2017-06-16 09:45:32 -0400 | [diff] [blame] | 3944 | sk_sp<GrSemaphore> semaphore = this->makeSemaphore(true); |
Greg Daniel | 858e12c | 2018-12-06 11:11:37 -0500 | [diff] [blame] | 3945 | this->insertSemaphore(semaphore); |
| 3946 | // We must call flush here to make sure the GrGLSync object gets created and sent to the gpu. |
| 3947 | GL_CALL(Flush()); |
Brian Osman | 13dddce | 2017-05-09 13:19:50 -0400 | [diff] [blame] | 3948 | |
| 3949 | return semaphore; |
| 3950 | } |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 3951 | |
| 3952 | int GrGLGpu::TextureToCopyProgramIdx(GrTexture* texture) { |
Brian Salomon | 60dd8c7 | 2018-07-30 10:24:13 -0400 | [diff] [blame] | 3953 | switch (GrSLCombinedSamplerTypeForTextureType(texture->texturePriv().textureType())) { |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 3954 | case kTexture2DSampler_GrSLType: |
| 3955 | return 0; |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 3956 | case kTexture2DRectSampler_GrSLType: |
Brian Salomon | 5711133 | 2018-02-05 15:55:54 -0500 | [diff] [blame] | 3957 | return 1; |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 3958 | case kTextureExternalSampler_GrSLType: |
Brian Salomon | 5711133 | 2018-02-05 15:55:54 -0500 | [diff] [blame] | 3959 | return 2; |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 3960 | default: |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 3961 | SK_ABORT("Unexpected samper type"); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 3962 | } |
| 3963 | } |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 3964 | |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 3965 | #ifdef SK_ENABLE_DUMP_GPU |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3966 | #include "src/utils/SkJSONWriter.h" |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 3967 | void GrGLGpu::onDumpJSON(SkJSONWriter* writer) const { |
| 3968 | // We are called by the base class, which has already called beginObject(). We choose to nest |
| 3969 | // all of our caps information in a named sub-object. |
| 3970 | writer->beginObject("GL GPU"); |
| 3971 | |
| 3972 | const GrGLubyte* str; |
| 3973 | GL_CALL_RET(str, GetString(GR_GL_VERSION)); |
| 3974 | writer->appendString("GL_VERSION", (const char*)(str)); |
| 3975 | GL_CALL_RET(str, GetString(GR_GL_RENDERER)); |
| 3976 | writer->appendString("GL_RENDERER", (const char*)(str)); |
| 3977 | GL_CALL_RET(str, GetString(GR_GL_VENDOR)); |
| 3978 | writer->appendString("GL_VENDOR", (const char*)(str)); |
| 3979 | GL_CALL_RET(str, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 3980 | writer->appendString("GL_SHADING_LANGUAGE_VERSION", (const char*)(str)); |
| 3981 | |
| 3982 | writer->appendName("extensions"); |
| 3983 | glInterface()->fExtensions.dumpJSON(writer); |
| 3984 | |
| 3985 | writer->endObject(); |
| 3986 | } |
Kevin Lubick | f4def34 | 2018-10-04 12:52:50 -0400 | [diff] [blame] | 3987 | #endif |