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