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 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 8 | |
jvanverth | 39edf76 | 2014-12-22 11:44:19 -0800 | [diff] [blame] | 9 | #include "GrGLGpu.h" |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 10 | #include "GrGLStencilAttachment.h" |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 11 | #include "GrGLTextureRenderTarget.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 12 | #include "GrGpuResourcePriv.h" |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 13 | #include "GrPipeline.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 14 | #include "GrRenderTargetPriv.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 15 | #include "GrSurfacePriv.h" |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 16 | #include "GrTemplates.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 17 | #include "GrTexturePriv.h" |
senorblanco@chromium.org | ef3913b | 2011-05-19 17:11:07 +0000 | [diff] [blame] | 18 | #include "GrTypes.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 19 | #include "GrVertices.h" |
commit-bot@chromium.org | 32184d8 | 2013-10-09 15:14:18 +0000 | [diff] [blame] | 20 | #include "SkStrokeRec.h" |
bsalomon@google.com | 3582bf9 | 2011-06-30 21:32:31 +0000 | [diff] [blame] | 21 | #include "SkTemplates.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 23 | #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 24 | #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] | 25 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 26 | #define SKIP_CACHE_CHECK true |
| 27 | |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 28 | #if GR_GL_CHECK_ALLOC_WITH_GET_ERROR |
| 29 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) GrGLClearErr(iface) |
| 30 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL_NOERRCHECK(iface, call) |
| 31 | #define CHECK_ALLOC_ERROR(iface) GR_GL_GET_ERROR(iface) |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 32 | #else |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 33 | #define CLEAR_ERROR_BEFORE_ALLOC(iface) |
| 34 | #define GL_ALLOC_CALL(iface, call) GR_GL_CALL(iface, call) |
| 35 | #define CHECK_ALLOC_ERROR(iface) GR_GL_NO_ERROR |
| 36 | #endif |
| 37 | |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 38 | |
| 39 | /////////////////////////////////////////////////////////////////////////////// |
| 40 | |
cdalton | b85a0aa | 2014-07-21 15:32:44 -0700 | [diff] [blame] | 41 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 42 | static const GrGLenum gXfermodeEquation2Blend[] = { |
| 43 | // Basic OpenGL blend equations. |
| 44 | GR_GL_FUNC_ADD, |
| 45 | GR_GL_FUNC_SUBTRACT, |
| 46 | GR_GL_FUNC_REVERSE_SUBTRACT, |
| 47 | |
| 48 | // GL_KHR_blend_equation_advanced. |
| 49 | GR_GL_SCREEN, |
| 50 | GR_GL_OVERLAY, |
| 51 | GR_GL_DARKEN, |
| 52 | GR_GL_LIGHTEN, |
| 53 | GR_GL_COLORDODGE, |
| 54 | GR_GL_COLORBURN, |
| 55 | GR_GL_HARDLIGHT, |
| 56 | GR_GL_SOFTLIGHT, |
| 57 | GR_GL_DIFFERENCE, |
| 58 | GR_GL_EXCLUSION, |
| 59 | GR_GL_MULTIPLY, |
| 60 | GR_GL_HSL_HUE, |
| 61 | GR_GL_HSL_SATURATION, |
| 62 | GR_GL_HSL_COLOR, |
| 63 | GR_GL_HSL_LUMINOSITY |
| 64 | }; |
| 65 | GR_STATIC_ASSERT(0 == kAdd_GrBlendEquation); |
| 66 | GR_STATIC_ASSERT(1 == kSubtract_GrBlendEquation); |
| 67 | GR_STATIC_ASSERT(2 == kReverseSubtract_GrBlendEquation); |
| 68 | GR_STATIC_ASSERT(3 == kScreen_GrBlendEquation); |
| 69 | GR_STATIC_ASSERT(4 == kOverlay_GrBlendEquation); |
| 70 | GR_STATIC_ASSERT(5 == kDarken_GrBlendEquation); |
| 71 | GR_STATIC_ASSERT(6 == kLighten_GrBlendEquation); |
| 72 | GR_STATIC_ASSERT(7 == kColorDodge_GrBlendEquation); |
| 73 | GR_STATIC_ASSERT(8 == kColorBurn_GrBlendEquation); |
| 74 | GR_STATIC_ASSERT(9 == kHardLight_GrBlendEquation); |
| 75 | GR_STATIC_ASSERT(10 == kSoftLight_GrBlendEquation); |
| 76 | GR_STATIC_ASSERT(11 == kDifference_GrBlendEquation); |
| 77 | GR_STATIC_ASSERT(12 == kExclusion_GrBlendEquation); |
| 78 | GR_STATIC_ASSERT(13 == kMultiply_GrBlendEquation); |
| 79 | GR_STATIC_ASSERT(14 == kHSLHue_GrBlendEquation); |
| 80 | GR_STATIC_ASSERT(15 == kHSLSaturation_GrBlendEquation); |
| 81 | GR_STATIC_ASSERT(16 == kHSLColor_GrBlendEquation); |
| 82 | GR_STATIC_ASSERT(17 == kHSLLuminosity_GrBlendEquation); |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 83 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gXfermodeEquation2Blend) == kGrBlendEquationCnt); |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 84 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 85 | static const GrGLenum gXfermodeCoeff2Blend[] = { |
| 86 | GR_GL_ZERO, |
| 87 | GR_GL_ONE, |
| 88 | GR_GL_SRC_COLOR, |
| 89 | GR_GL_ONE_MINUS_SRC_COLOR, |
| 90 | GR_GL_DST_COLOR, |
| 91 | GR_GL_ONE_MINUS_DST_COLOR, |
| 92 | GR_GL_SRC_ALPHA, |
| 93 | GR_GL_ONE_MINUS_SRC_ALPHA, |
| 94 | GR_GL_DST_ALPHA, |
| 95 | GR_GL_ONE_MINUS_DST_ALPHA, |
| 96 | GR_GL_CONSTANT_COLOR, |
| 97 | GR_GL_ONE_MINUS_CONSTANT_COLOR, |
| 98 | GR_GL_CONSTANT_ALPHA, |
| 99 | GR_GL_ONE_MINUS_CONSTANT_ALPHA, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 100 | |
| 101 | // extended blend coeffs |
| 102 | GR_GL_SRC1_COLOR, |
| 103 | GR_GL_ONE_MINUS_SRC1_COLOR, |
| 104 | GR_GL_SRC1_ALPHA, |
| 105 | GR_GL_ONE_MINUS_SRC1_ALPHA, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 108 | bool GrGLGpu::BlendCoeffReferencesConstant(GrBlendCoeff coeff) { |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 109 | static const bool gCoeffReferencesBlendConst[] = { |
| 110 | false, |
| 111 | false, |
| 112 | false, |
| 113 | false, |
| 114 | false, |
| 115 | false, |
| 116 | false, |
| 117 | false, |
| 118 | false, |
| 119 | false, |
| 120 | true, |
| 121 | true, |
| 122 | true, |
| 123 | true, |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 124 | |
| 125 | // extended blend coeffs |
| 126 | false, |
| 127 | false, |
| 128 | false, |
| 129 | false, |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 130 | }; |
| 131 | return gCoeffReferencesBlendConst[coeff]; |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 132 | GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gCoeffReferencesBlendConst)); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 133 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 134 | GR_STATIC_ASSERT(0 == kZero_GrBlendCoeff); |
| 135 | GR_STATIC_ASSERT(1 == kOne_GrBlendCoeff); |
| 136 | GR_STATIC_ASSERT(2 == kSC_GrBlendCoeff); |
| 137 | GR_STATIC_ASSERT(3 == kISC_GrBlendCoeff); |
| 138 | GR_STATIC_ASSERT(4 == kDC_GrBlendCoeff); |
| 139 | GR_STATIC_ASSERT(5 == kIDC_GrBlendCoeff); |
| 140 | GR_STATIC_ASSERT(6 == kSA_GrBlendCoeff); |
| 141 | GR_STATIC_ASSERT(7 == kISA_GrBlendCoeff); |
| 142 | GR_STATIC_ASSERT(8 == kDA_GrBlendCoeff); |
| 143 | GR_STATIC_ASSERT(9 == kIDA_GrBlendCoeff); |
| 144 | GR_STATIC_ASSERT(10 == kConstC_GrBlendCoeff); |
| 145 | GR_STATIC_ASSERT(11 == kIConstC_GrBlendCoeff); |
| 146 | GR_STATIC_ASSERT(12 == kConstA_GrBlendCoeff); |
| 147 | GR_STATIC_ASSERT(13 == kIConstA_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 148 | |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 149 | GR_STATIC_ASSERT(14 == kS2C_GrBlendCoeff); |
| 150 | GR_STATIC_ASSERT(15 == kIS2C_GrBlendCoeff); |
| 151 | GR_STATIC_ASSERT(16 == kS2A_GrBlendCoeff); |
| 152 | GR_STATIC_ASSERT(17 == kIS2A_GrBlendCoeff); |
bsalomon@google.com | 271cffc | 2011-05-20 14:13:56 +0000 | [diff] [blame] | 153 | |
| 154 | // assertion for gXfermodeCoeff2Blend have to be in GrGpu scope |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 155 | GR_STATIC_ASSERT(kGrBlendCoeffCnt == SK_ARRAY_COUNT(gXfermodeCoeff2Blend)); |
bsalomon@google.com | 080773c | 2011-03-15 19:09:25 +0000 | [diff] [blame] | 156 | } |
| 157 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 158 | /////////////////////////////////////////////////////////////////////////////// |
| 159 | |
rileya@google.com | e38160c | 2012-07-03 18:03:04 +0000 | [diff] [blame] | 160 | static bool gPrintStartupSpew; |
bsalomon@google.com | 42ab7ea | 2011-01-19 17:19:40 +0000 | [diff] [blame] | 161 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 162 | GrGLGpu::GrGLGpu(const GrGLContext& ctx, GrContext* context) |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 163 | : GrGpu(context) |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 164 | , fGLContext(ctx) { |
bsalomon@google.com | 89ec61e | 2012-02-10 20:05:18 +0000 | [diff] [blame] | 165 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 166 | SkASSERT(ctx.isInitialized()); |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 167 | fCaps.reset(SkRef(ctx.caps())); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 168 | |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 169 | fHWBoundTextureUniqueIDs.reset(this->glCaps().maxFragmentTextureUnits()); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 170 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 171 | GrGLClearErr(fGLContext.interface()); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 172 | if (gPrintStartupSpew) { |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 173 | const GrGLubyte* vendor; |
| 174 | const GrGLubyte* renderer; |
| 175 | const GrGLubyte* version; |
| 176 | GL_CALL_RET(vendor, GetString(GR_GL_VENDOR)); |
| 177 | GL_CALL_RET(renderer, GetString(GR_GL_RENDERER)); |
| 178 | GL_CALL_RET(version, GetString(GR_GL_VERSION)); |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 179 | SkDebugf("------------------------- create GrGLGpu %p --------------\n", |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 180 | this); |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 181 | SkDebugf("------ VENDOR %s\n", vendor); |
| 182 | SkDebugf("------ RENDERER %s\n", renderer); |
| 183 | SkDebugf("------ VERSION %s\n", version); |
| 184 | SkDebugf("------ EXTENSIONS\n"); |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 185 | ctx.extensions().print(); |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 186 | SkDebugf("\n"); |
kkinnunen | 297aaf9 | 2015-02-19 06:32:12 -0800 | [diff] [blame] | 187 | SkDebugf("%s", this->glCaps().dump().c_str()); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 188 | } |
| 189 | |
commit-bot@chromium.org | 9188a15 | 2013-09-05 18:28:24 +0000 | [diff] [blame] | 190 | fProgramCache = SkNEW_ARGS(ProgramCache, (this)); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 191 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 192 | SkASSERT(this->glCaps().maxVertexAttributes() >= GrGeometryProcessor::kMaxVertexAttribs); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 193 | |
bsalomon@google.com | fe67652 | 2011-06-17 18:12:21 +0000 | [diff] [blame] | 194 | fLastSuccessfulStencilFmtIdx = 0; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 195 | fHWProgramID = 0; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 196 | fTempSrcFBOID = 0; |
| 197 | fTempDstFBOID = 0; |
| 198 | fStencilClearFBOID = 0; |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 199 | |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 200 | if (this->glCaps().shaderCaps()->pathRenderingSupport()) { |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 201 | fPathRendering.reset(new GrGLPathRendering(this)); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 202 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 203 | } |
| 204 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 205 | GrGLGpu::~GrGLGpu() { |
bsalomon@google.com | 9ba4fa6 | 2012-07-16 17:36:28 +0000 | [diff] [blame] | 206 | if (0 != fHWProgramID) { |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 207 | // detach the current program so there is no confusion on OpenGL's part |
| 208 | // that we want it to be deleted |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 209 | SkASSERT(fHWProgramID == fCurrentProgram->programID()); |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 210 | GL_CALL(UseProgram(0)); |
| 211 | } |
| 212 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 213 | if (0 != fTempSrcFBOID) { |
| 214 | GL_CALL(DeleteFramebuffers(1, &fTempSrcFBOID)); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 215 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 216 | if (0 != fTempDstFBOID) { |
| 217 | GL_CALL(DeleteFramebuffers(1, &fTempDstFBOID)); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 218 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 219 | if (0 != fStencilClearFBOID) { |
| 220 | GL_CALL(DeleteFramebuffers(1, &fStencilClearFBOID)); |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 221 | } |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 222 | |
bsalomon@google.com | c1d2a58 | 2012-06-01 15:08:19 +0000 | [diff] [blame] | 223 | delete fProgramCache; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 224 | } |
| 225 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 226 | void GrGLGpu::contextAbandoned() { |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 227 | INHERITED::contextAbandoned(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 228 | fProgramCache->abandon(); |
| 229 | fHWProgramID = 0; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 230 | fTempSrcFBOID = 0; |
| 231 | fTempDstFBOID = 0; |
| 232 | fStencilClearFBOID = 0; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 233 | if (this->glCaps().shaderCaps()->pathRenderingSupport()) { |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 234 | this->glPathRendering()->abandonGpuResources(); |
| 235 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 236 | } |
| 237 | |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 238 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 239 | GrPixelConfig GrGLGpu::preferredReadPixelsConfig(GrPixelConfig readConfig, |
commit-bot@chromium.org | 2862151 | 2013-08-07 19:43:45 +0000 | [diff] [blame] | 240 | GrPixelConfig surfaceConfig) const { |
| 241 | if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == readConfig) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 242 | return kBGRA_8888_GrPixelConfig; |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 243 | } else if (this->glContext().isMesa() && |
commit-bot@chromium.org | 2862151 | 2013-08-07 19:43:45 +0000 | [diff] [blame] | 244 | GrBytesPerPixel(readConfig) == 4 && |
| 245 | GrPixelConfigSwapRAndB(readConfig) == surfaceConfig) { |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 246 | // Mesa 3D takes a slow path on when reading back BGRA from an RGBA surface and vice-versa. |
| 247 | // Perhaps this should be guarded by some compiletime or runtime check. |
| 248 | return surfaceConfig; |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 249 | } else if (readConfig == kBGRA_8888_GrPixelConfig |
| 250 | && !this->glCaps().readPixelsSupported( |
| 251 | this->glInterface(), |
| 252 | GR_GL_BGRA, |
| 253 | GR_GL_UNSIGNED_BYTE, |
| 254 | surfaceConfig |
| 255 | )) { |
commit-bot@chromium.org | 2862151 | 2013-08-07 19:43:45 +0000 | [diff] [blame] | 256 | return kRGBA_8888_GrPixelConfig; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 257 | } else { |
commit-bot@chromium.org | 2862151 | 2013-08-07 19:43:45 +0000 | [diff] [blame] | 258 | return readConfig; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 259 | } |
| 260 | } |
| 261 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 262 | GrPixelConfig GrGLGpu::preferredWritePixelsConfig(GrPixelConfig writeConfig, |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 263 | GrPixelConfig surfaceConfig) const { |
commit-bot@chromium.org | 2862151 | 2013-08-07 19:43:45 +0000 | [diff] [blame] | 264 | if (GR_GL_RGBA_8888_PIXEL_OPS_SLOW && kRGBA_8888_GrPixelConfig == writeConfig) { |
| 265 | return kBGRA_8888_GrPixelConfig; |
| 266 | } else { |
| 267 | return writeConfig; |
| 268 | } |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 269 | } |
| 270 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 271 | bool GrGLGpu::canWriteTexturePixels(const GrTexture* texture, GrPixelConfig srcConfig) const { |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 272 | if (kIndex_8_GrPixelConfig == srcConfig || kIndex_8_GrPixelConfig == texture->config()) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 273 | return false; |
| 274 | } |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 275 | if (srcConfig != texture->config() && kGLES_GrGLStandard == this->glStandard()) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 276 | // In general ES2 requires the internal format of the texture and the format of the src |
| 277 | // pixels to match. However, It may or may not be possible to upload BGRA data to a RGBA |
| 278 | // texture. It depends upon which extension added BGRA. The Apple extension allows it |
| 279 | // (BGRA's internal format is RGBA) while the EXT extension does not (BGRA is its own |
| 280 | // internal format). |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 281 | if (this->glCaps().isConfigTexturable(kBGRA_8888_GrPixelConfig) && |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 282 | !this->glCaps().bgraIsInternalFormat() && |
| 283 | kBGRA_8888_GrPixelConfig == srcConfig && |
| 284 | kRGBA_8888_GrPixelConfig == texture->config()) { |
| 285 | return true; |
| 286 | } else { |
| 287 | return false; |
| 288 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 289 | } else { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 290 | return true; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 294 | bool GrGLGpu::fullReadPixelsIsFasterThanPartial() const { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 295 | return SkToBool(GR_GL_FULL_READPIXELS_FASTER_THAN_PARTIAL); |
| 296 | } |
| 297 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 298 | void GrGLGpu::onResetContext(uint32_t resetBits) { |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 299 | // we don't use the zb at all |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 300 | if (resetBits & kMisc_GrGLBackendState) { |
| 301 | GL_CALL(Disable(GR_GL_DEPTH_TEST)); |
| 302 | GL_CALL(DepthMask(GR_GL_FALSE)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 303 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 304 | fHWDrawFace = GrPipelineBuilder::kInvalid_DrawFace; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 305 | fHWDitherEnabled = kUnknown_TriState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 306 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 307 | if (kGL_GrGLStandard == this->glStandard()) { |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 308 | // Desktop-only state that we never change |
| 309 | if (!this->glCaps().isCoreProfile()) { |
| 310 | GL_CALL(Disable(GR_GL_POINT_SMOOTH)); |
| 311 | GL_CALL(Disable(GR_GL_LINE_SMOOTH)); |
| 312 | GL_CALL(Disable(GR_GL_POLYGON_SMOOTH)); |
| 313 | GL_CALL(Disable(GR_GL_POLYGON_STIPPLE)); |
| 314 | GL_CALL(Disable(GR_GL_COLOR_LOGIC_OP)); |
| 315 | GL_CALL(Disable(GR_GL_INDEX_LOGIC_OP)); |
| 316 | } |
| 317 | // The windows NVIDIA driver has GL_ARB_imaging in the extension string when using a |
| 318 | // core profile. This seems like a bug since the core spec removes any mention of |
| 319 | // GL_ARB_imaging. |
| 320 | if (this->glCaps().imagingSupport() && !this->glCaps().isCoreProfile()) { |
| 321 | GL_CALL(Disable(GR_GL_COLOR_TABLE)); |
| 322 | } |
| 323 | GL_CALL(Disable(GR_GL_POLYGON_OFFSET_FILL)); |
| 324 | // Since ES doesn't support glPointSize at all we always use the VS to |
| 325 | // set the point size |
| 326 | GL_CALL(Enable(GR_GL_VERTEX_PROGRAM_POINT_SIZE)); |
| 327 | |
| 328 | // We should set glPolygonMode(FRONT_AND_BACK,FILL) here, too. It isn't |
| 329 | // currently part of our gl interface. There are probably others as |
| 330 | // well. |
bsalomon@google.com | 2b1b8c0 | 2013-02-28 22:06:02 +0000 | [diff] [blame] | 331 | } |
joshualitt | 5816233 | 2014-08-01 06:44:53 -0700 | [diff] [blame] | 332 | |
| 333 | if (kGLES_GrGLStandard == this->glStandard() && |
| 334 | fGLContext.hasExtension("GL_ARM_shader_framebuffer_fetch")) { |
| 335 | // The arm extension requires specifically enabling MSAA fetching per sample. |
| 336 | // On some devices this may have a perf hit. Also multiple render targets are disabled |
| 337 | GL_CALL(Enable(GR_GL_FETCH_PER_SAMPLE_ARM)); |
| 338 | } |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 339 | fHWWriteToColor = kUnknown_TriState; |
| 340 | // we only ever use lines in hairline mode |
| 341 | GL_CALL(LineWidth(1)); |
bsalomon@google.com | cad107b | 2013-06-28 14:32:08 +0000 | [diff] [blame] | 342 | } |
edisonn@google.com | ba66999 | 2013-06-28 16:03:21 +0000 | [diff] [blame] | 343 | |
egdaniel | b414f25 | 2014-07-29 13:15:47 -0700 | [diff] [blame] | 344 | if (resetBits & kMSAAEnable_GrGLBackendState) { |
| 345 | fMSAAEnabled = kUnknown_TriState; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 346 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 347 | |
commit-bot@chromium.org | 46fbfe0 | 2013-08-30 15:52:12 +0000 | [diff] [blame] | 348 | fHWActiveTextureUnitIdx = -1; // invalid |
| 349 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 350 | if (resetBits & kTextureBinding_GrGLBackendState) { |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 351 | for (int s = 0; s < fHWBoundTextureUniqueIDs.count(); ++s) { |
| 352 | fHWBoundTextureUniqueIDs[s] = SK_InvalidUniqueID; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 353 | } |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 354 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 355 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 356 | if (resetBits & kBlend_GrGLBackendState) { |
| 357 | fHWBlendState.invalidate(); |
| 358 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 359 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 360 | if (resetBits & kView_GrGLBackendState) { |
| 361 | fHWScissorSettings.invalidate(); |
| 362 | fHWViewport.invalidate(); |
| 363 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 364 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 365 | if (resetBits & kStencil_GrGLBackendState) { |
| 366 | fHWStencilSettings.invalidate(); |
| 367 | fHWStencilTestEnabled = kUnknown_TriState; |
| 368 | } |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 369 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 370 | // Vertex |
| 371 | if (resetBits & kVertex_GrGLBackendState) { |
| 372 | fHWGeometryState.invalidate(); |
| 373 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 374 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 375 | if (resetBits & kRenderTarget_GrGLBackendState) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 376 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 377 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 378 | |
commit-bot@chromium.org | 0a6fe71 | 2014-04-23 19:26:26 +0000 | [diff] [blame] | 379 | if (resetBits & kPathRendering_GrGLBackendState) { |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 380 | if (this->caps()->shaderCaps()->pathRenderingSupport()) { |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 381 | this->glPathRendering()->resetContext(); |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 382 | } |
bsalomon@google.com | 05a718c | 2012-06-29 14:01:53 +0000 | [diff] [blame] | 383 | } |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 384 | |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 385 | // we assume these values |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 386 | if (resetBits & kPixelStore_GrGLBackendState) { |
| 387 | if (this->glCaps().unpackRowLengthSupport()) { |
| 388 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
| 389 | } |
| 390 | if (this->glCaps().packRowLengthSupport()) { |
| 391 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 392 | } |
| 393 | if (this->glCaps().unpackFlipYSupport()) { |
| 394 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 395 | } |
| 396 | if (this->glCaps().packFlipYSupport()) { |
| 397 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, GR_GL_FALSE)); |
| 398 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 399 | } |
bsalomon@google.com | 5739d2c | 2012-05-31 15:07:19 +0000 | [diff] [blame] | 400 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 401 | if (resetBits & kProgram_GrGLBackendState) { |
| 402 | fHWProgramID = 0; |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 403 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 404 | } |
| 405 | |
egdaniel | cf614fd | 2015-04-22 13:58:58 -0700 | [diff] [blame] | 406 | static GrSurfaceOrigin resolve_origin(GrSurfaceOrigin origin, bool renderTarget) { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 407 | // By default, GrRenderTargets are GL's normal orientation so that they |
| 408 | // can be drawn to by the outside world without the client having |
| 409 | // to render upside down. |
| 410 | if (kDefault_GrSurfaceOrigin == origin) { |
| 411 | return renderTarget ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; |
| 412 | } else { |
| 413 | return origin; |
| 414 | } |
| 415 | } |
| 416 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 417 | GrTexture* GrGLGpu::onWrapBackendTexture(const GrBackendTextureDesc& desc) { |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 418 | if (!this->configToGLFormats(desc.fConfig, false, NULL, NULL, NULL)) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 419 | return NULL; |
| 420 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 421 | |
robertphillips@google.com | b72e5d3 | 2012-10-30 15:18:10 +0000 | [diff] [blame] | 422 | if (0 == desc.fTextureHandle) { |
| 423 | return NULL; |
| 424 | } |
| 425 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 426 | int maxSize = this->caps()->maxTextureSize(); |
robertphillips@google.com | b72e5d3 | 2012-10-30 15:18:10 +0000 | [diff] [blame] | 427 | if (desc.fWidth > maxSize || desc.fHeight > maxSize) { |
| 428 | return NULL; |
| 429 | } |
| 430 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 431 | GrGLTexture::IDDesc idDesc; |
| 432 | GrSurfaceDesc surfDesc; |
| 433 | |
| 434 | idDesc.fTextureID = static_cast<GrGLuint>(desc.fTextureHandle); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 435 | idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle; |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 436 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 437 | // next line relies on GrBackendTextureDesc's flags matching GrTexture's |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 438 | surfDesc.fFlags = (GrSurfaceFlags) desc.fFlags; |
| 439 | surfDesc.fWidth = desc.fWidth; |
| 440 | surfDesc.fHeight = desc.fHeight; |
| 441 | surfDesc.fConfig = desc.fConfig; |
senorblanco | 94e5010 | 2015-04-06 09:42:57 -0700 | [diff] [blame] | 442 | surfDesc.fSampleCnt = SkTMin(desc.fSampleCnt, this->caps()->maxSampleCount()); |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 443 | bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrBackendTextureFlag); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 444 | // FIXME: this should be calling resolve_origin(), but Chrome code is currently |
| 445 | // assuming the old behaviour, which is that backend textures are always |
| 446 | // BottomLeft, even for non-RT's. Once Chrome is fixed, change this to: |
| 447 | // glTexDesc.fOrigin = resolve_origin(desc.fOrigin, renderTarget); |
| 448 | if (kDefault_GrSurfaceOrigin == desc.fOrigin) { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 449 | surfDesc.fOrigin = kBottomLeft_GrSurfaceOrigin; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 450 | } else { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 451 | surfDesc.fOrigin = desc.fOrigin; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 452 | } |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 453 | |
| 454 | GrGLTexture* texture = NULL; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 455 | if (renderTarget) { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 456 | GrGLRenderTarget::IDDesc rtIDDesc; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 457 | if (!this->createRenderTargetObjects(surfDesc, GrGpuResource::kUncached_LifeCycle, |
| 458 | idDesc.fTextureID, &rtIDDesc)) { |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 459 | return NULL; |
| 460 | } |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 461 | texture = SkNEW_ARGS(GrGLTextureRenderTarget, (this, surfDesc, idDesc, rtIDDesc)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 462 | } else { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 463 | texture = SkNEW_ARGS(GrGLTexture, (this, surfDesc, idDesc)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 464 | } |
| 465 | if (NULL == texture) { |
| 466 | return NULL; |
| 467 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 468 | |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 469 | return texture; |
| 470 | } |
| 471 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 472 | GrRenderTarget* GrGLGpu::onWrapBackendRenderTarget(const GrBackendRenderTargetDesc& wrapDesc) { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 473 | GrGLRenderTarget::IDDesc idDesc; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 474 | idDesc.fRTFBOID = static_cast<GrGLuint>(wrapDesc.fRenderTargetHandle); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 475 | idDesc.fMSColorRenderbufferID = 0; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 476 | idDesc.fTexFBOID = GrGLRenderTarget::kUnresolvableFBOID; |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 477 | idDesc.fLifeCycle = GrGpuResource::kWrapped_LifeCycle; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 478 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 479 | GrSurfaceDesc desc; |
| 480 | desc.fConfig = wrapDesc.fConfig; |
| 481 | desc.fFlags = kCheckAllocation_GrSurfaceFlag; |
| 482 | desc.fWidth = wrapDesc.fWidth; |
| 483 | desc.fHeight = wrapDesc.fHeight; |
senorblanco | 94e5010 | 2015-04-06 09:42:57 -0700 | [diff] [blame] | 484 | desc.fSampleCnt = SkTMin(wrapDesc.fSampleCnt, this->caps()->maxSampleCount()); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 485 | desc.fOrigin = resolve_origin(wrapDesc.fOrigin, true); |
| 486 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 487 | GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget, (this, desc, idDesc)); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 488 | if (wrapDesc.fStencilBits) { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 489 | GrGLStencilAttachment::IDDesc sbDesc; |
| 490 | GrGLStencilAttachment::Format format; |
| 491 | format.fInternalFormat = GrGLStencilAttachment::kUnknownInternalFormat; |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 492 | format.fPacked = false; |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 493 | format.fStencilBits = wrapDesc.fStencilBits; |
| 494 | format.fTotalBits = wrapDesc.fStencilBits; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 495 | GrGLStencilAttachment* sb = SkNEW_ARGS(GrGLStencilAttachment, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 496 | (this, |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 497 | sbDesc, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 498 | desc.fWidth, |
| 499 | desc.fHeight, |
| 500 | desc.fSampleCnt, |
| 501 | format)); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 502 | tgt->renderTargetPriv().didAttachStencilAttachment(sb); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 503 | sb->unref(); |
| 504 | } |
| 505 | return tgt; |
| 506 | } |
| 507 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 508 | //////////////////////////////////////////////////////////////////////////////// |
| 509 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 510 | bool GrGLGpu::onWriteTexturePixels(GrTexture* texture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 511 | int left, int top, int width, int height, |
| 512 | GrPixelConfig config, const void* buffer, |
| 513 | size_t rowBytes) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 514 | if (NULL == buffer) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 515 | return false; |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 516 | } |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 517 | GrGLTexture* glTex = static_cast<GrGLTexture*>(texture); |
| 518 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 519 | this->setScratchTextureUnit(); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 520 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, glTex->textureID())); |
bsalomon@google.com | 9d6cfd8 | 2011-11-05 13:25:21 +0000 | [diff] [blame] | 521 | |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 522 | bool success = false; |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 523 | if (GrPixelConfigIsCompressed(glTex->desc().fConfig)) { |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 524 | // We check that config == desc.fConfig in GrGLGpu::canWriteTexturePixels() |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 525 | SkASSERT(config == glTex->desc().fConfig); |
| 526 | success = this->uploadCompressedTexData(glTex->desc(), buffer, false, left, top, width, |
| 527 | height); |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 528 | } else { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 529 | success = this->uploadTexData(glTex->desc(), false, left, top, width, height, config, |
| 530 | buffer, rowBytes); |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | if (success) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 534 | texture->texturePriv().dirtyMipMaps(true); |
commit-bot@chromium.org | cffff79 | 2013-07-26 16:36:04 +0000 | [diff] [blame] | 535 | return true; |
commit-bot@chromium.org | cffff79 | 2013-07-26 16:36:04 +0000 | [diff] [blame] | 536 | } |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 537 | |
| 538 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 539 | } |
| 540 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 541 | static bool adjust_pixel_ops_params(int surfaceWidth, |
| 542 | int surfaceHeight, |
| 543 | size_t bpp, |
| 544 | int* left, int* top, int* width, int* height, |
| 545 | const void** data, |
| 546 | size_t* rowBytes) { |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 547 | if (!*rowBytes) { |
| 548 | *rowBytes = *width * bpp; |
| 549 | } |
| 550 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 551 | SkIRect subRect = SkIRect::MakeXYWH(*left, *top, *width, *height); |
| 552 | SkIRect bounds = SkIRect::MakeWH(surfaceWidth, surfaceHeight); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 553 | |
| 554 | if (!subRect.intersect(bounds)) { |
| 555 | return false; |
| 556 | } |
| 557 | *data = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>(*data) + |
| 558 | (subRect.fTop - *top) * *rowBytes + (subRect.fLeft - *left) * bpp); |
| 559 | |
| 560 | *left = subRect.fLeft; |
| 561 | *top = subRect.fTop; |
| 562 | *width = subRect.width(); |
| 563 | *height = subRect.height(); |
| 564 | return true; |
| 565 | } |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 566 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 567 | static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, |
| 568 | const GrGLInterface* interface) { |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 569 | if (SkToBool(desc.fFlags & kCheckAllocation_GrSurfaceFlag)) { |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 570 | return GR_GL_GET_ERROR(interface); |
| 571 | } else { |
| 572 | return CHECK_ALLOC_ERROR(interface); |
| 573 | } |
| 574 | } |
| 575 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 576 | bool GrGLGpu::uploadTexData(const GrSurfaceDesc& desc, |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 577 | bool isNewTexture, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 578 | int left, int top, int width, int height, |
| 579 | GrPixelConfig dataConfig, |
| 580 | const void* data, |
| 581 | size_t rowBytes) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 582 | SkASSERT(data || isNewTexture); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 583 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 584 | // If we're uploading compressed data then we should be using uploadCompressedTexData |
| 585 | SkASSERT(!GrPixelConfigIsCompressed(dataConfig)); |
| 586 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 587 | size_t bpp = GrBytesPerPixel(dataConfig); |
| 588 | if (!adjust_pixel_ops_params(desc.fWidth, desc.fHeight, bpp, &left, &top, |
| 589 | &width, &height, &data, &rowBytes)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 590 | return false; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 591 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 592 | size_t trimRowBytes = width * bpp; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 593 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 594 | // in case we need a temporary, trimmed copy of the src pixels |
george | b62508b | 2014-08-12 18:00:47 -0700 | [diff] [blame] | 595 | GrAutoMalloc<128 * 128> tempStorage; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 596 | |
commit-bot@chromium.org | cea9abb | 2013-12-09 19:15:37 +0000 | [diff] [blame] | 597 | // We currently lazily create MIPMAPs when the we see a draw with |
| 598 | // GrTextureParams::kMipMap_FilterMode. Using texture storage requires that the |
| 599 | // MIP levels are all created when the texture is created. So for now we don't use |
| 600 | // texture storage. |
| 601 | bool useTexStorage = false && |
| 602 | isNewTexture && |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 603 | this->glCaps().texStorageSupport(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 604 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 605 | if (useTexStorage && kGL_GrGLStandard == this->glStandard()) { |
bsalomon@google.com | 313f019 | 2012-07-10 17:21:02 +0000 | [diff] [blame] | 606 | // 565 is not a sized internal format on desktop GL. So on desktop with |
| 607 | // 565 we always use an unsized internal format to let the system pick |
| 608 | // the best sized format to convert the 565 data to. Since TexStorage |
| 609 | // only allows sized internal formats we will instead use TexImage2D. |
| 610 | useTexStorage = desc.fConfig != kRGB_565_GrPixelConfig; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 611 | } |
| 612 | |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 613 | GrGLenum internalFormat = 0x0; // suppress warning |
| 614 | GrGLenum externalFormat = 0x0; // suppress warning |
| 615 | GrGLenum externalType = 0x0; // suppress warning |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 616 | |
jvanverth | e1869ca | 2014-12-16 13:32:27 -0800 | [diff] [blame] | 617 | // glTexStorage requires sized internal formats on both desktop and ES. ES2 requires an unsized |
jvanverth | f72b752 | 2014-12-17 10:46:01 -0800 | [diff] [blame] | 618 | // format for glTexImage, unlike ES3 and desktop. |
jvanverth | e1869ca | 2014-12-16 13:32:27 -0800 | [diff] [blame] | 619 | bool useSizedFormat = useTexStorage; |
jvanverth | f72b752 | 2014-12-17 10:46:01 -0800 | [diff] [blame] | 620 | if (kGL_GrGLStandard == this->glStandard() || |
| 621 | (this->glVersion() >= GR_GL_VER(3, 0) && |
| 622 | // ES3 only works with sized BGRA8 format if "GL_APPLE_texture_format_BGRA8888" enabled |
| 623 | (kBGRA_8888_GrPixelConfig != dataConfig || !this->glCaps().bgraIsInternalFormat()))) { |
jvanverth | e1869ca | 2014-12-16 13:32:27 -0800 | [diff] [blame] | 624 | useSizedFormat = true; |
| 625 | } |
jvanverth | f72b752 | 2014-12-17 10:46:01 -0800 | [diff] [blame] | 626 | |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 627 | if (!this->configToGLFormats(dataConfig, useSizedFormat, &internalFormat, |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 628 | &externalFormat, &externalType)) { |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 629 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 630 | } |
| 631 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 632 | /* |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 633 | * check whether to allocate a temporary buffer for flipping y or |
| 634 | * because our srcData has extra bytes past each row. If so, we need |
| 635 | * to trim those off here, since GL ES may not let us specify |
| 636 | * GL_UNPACK_ROW_LENGTH. |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 637 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 638 | bool restoreGLRowLength = false; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 639 | bool swFlipY = false; |
| 640 | bool glFlipY = false; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 641 | if (data) { |
senorblanco@chromium.org | ef5dbe1 | 2013-01-28 16:42:38 +0000 | [diff] [blame] | 642 | if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 643 | if (this->glCaps().unpackFlipYSupport()) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 644 | glFlipY = true; |
| 645 | } else { |
| 646 | swFlipY = true; |
| 647 | } |
| 648 | } |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 649 | if (this->glCaps().unpackRowLengthSupport() && !swFlipY) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 650 | // can't use this for flipping, only non-neg values allowed. :( |
| 651 | if (rowBytes != trimRowBytes) { |
| 652 | GrGLint rowLength = static_cast<GrGLint>(rowBytes / bpp); |
| 653 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, rowLength)); |
| 654 | restoreGLRowLength = true; |
| 655 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 656 | } else { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 657 | if (trimRowBytes != rowBytes || swFlipY) { |
| 658 | // copy data into our new storage, skipping the trailing bytes |
| 659 | size_t trimSize = height * trimRowBytes; |
| 660 | const char* src = (const char*)data; |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 661 | if (swFlipY) { |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 662 | src += (height - 1) * rowBytes; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 663 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 664 | char* dst = (char*)tempStorage.reset(trimSize); |
| 665 | for (int y = 0; y < height; y++) { |
| 666 | memcpy(dst, src, trimRowBytes); |
| 667 | if (swFlipY) { |
| 668 | src -= rowBytes; |
| 669 | } else { |
| 670 | src += rowBytes; |
| 671 | } |
| 672 | dst += trimRowBytes; |
| 673 | } |
| 674 | // now point data to our copied version |
| 675 | data = tempStorage.get(); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 676 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 677 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 678 | if (glFlipY) { |
| 679 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_TRUE)); |
| 680 | } |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 681 | GL_CALL(PixelStorei(GR_GL_UNPACK_ALIGNMENT, |
| 682 | static_cast<GrGLint>(GrUnpackAlignment(dataConfig)))); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 683 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 684 | bool succeeded = true; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 685 | if (isNewTexture && |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 686 | 0 == left && 0 == top && |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 687 | desc.fWidth == width && desc.fHeight == height) { |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 688 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 689 | if (useTexStorage) { |
commit-bot@chromium.org | cea9abb | 2013-12-09 19:15:37 +0000 | [diff] [blame] | 690 | // We never resize or change formats of textures. |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 691 | GL_ALLOC_CALL(this->glInterface(), |
| 692 | TexStorage2D(GR_GL_TEXTURE_2D, |
| 693 | 1, // levels |
| 694 | internalFormat, |
| 695 | desc.fWidth, desc.fHeight)); |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 696 | } else { |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 697 | GL_ALLOC_CALL(this->glInterface(), |
| 698 | TexImage2D(GR_GL_TEXTURE_2D, |
| 699 | 0, // level |
| 700 | internalFormat, |
| 701 | desc.fWidth, desc.fHeight, |
| 702 | 0, // border |
| 703 | externalFormat, externalType, |
| 704 | data)); |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 705 | } |
senorblanco@chromium.org | d092524 | 2013-06-10 15:06:09 +0000 | [diff] [blame] | 706 | GrGLenum error = check_alloc_error(desc, this->glInterface()); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 707 | if (error != GR_GL_NO_ERROR) { |
| 708 | succeeded = false; |
| 709 | } else { |
| 710 | // if we have data and we used TexStorage to create the texture, we |
| 711 | // now upload with TexSubImage. |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 712 | if (data && useTexStorage) { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 713 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 714 | 0, // level |
| 715 | left, top, |
| 716 | width, height, |
| 717 | externalFormat, externalType, |
| 718 | data)); |
| 719 | } |
bsalomon@google.com | 136f55b | 2011-11-28 18:34:44 +0000 | [diff] [blame] | 720 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 721 | } else { |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 722 | if (swFlipY || glFlipY) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 723 | top = desc.fHeight - (top + height); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 724 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 725 | GL_CALL(TexSubImage2D(GR_GL_TEXTURE_2D, |
| 726 | 0, // level |
| 727 | left, top, |
| 728 | width, height, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 729 | externalFormat, externalType, data)); |
| 730 | } |
| 731 | |
| 732 | if (restoreGLRowLength) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 733 | SkASSERT(this->glCaps().unpackRowLengthSupport()); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 734 | GL_CALL(PixelStorei(GR_GL_UNPACK_ROW_LENGTH, 0)); |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 735 | } |
bsalomon@google.com | 8ef3fd0 | 2011-11-21 15:53:13 +0000 | [diff] [blame] | 736 | if (glFlipY) { |
| 737 | GL_CALL(PixelStorei(GR_GL_UNPACK_FLIP_Y, GR_GL_FALSE)); |
| 738 | } |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 739 | return succeeded; |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 740 | } |
| 741 | |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 742 | // TODO: This function is using a lot of wonky semantics like, if width == -1 |
piotaixr | e4b2314 | 2014-10-02 10:57:53 -0700 | [diff] [blame] | 743 | // then set width = desc.fWdith ... blah. A better way to do it might be to |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 744 | // create a CompressedTexData struct that takes a desc/ptr and figures out |
| 745 | // the proper upload semantics. Then users can construct this function how they |
| 746 | // see fit if they want to go against the "standard" way to do it. |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 747 | bool GrGLGpu::uploadCompressedTexData(const GrSurfaceDesc& desc, |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 748 | const void* data, |
| 749 | bool isNewTexture, |
| 750 | int left, int top, int width, int height) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 751 | SkASSERT(data || isNewTexture); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 752 | |
| 753 | // No support for software flip y, yet... |
| 754 | SkASSERT(kBottomLeft_GrSurfaceOrigin != desc.fOrigin); |
| 755 | |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 756 | if (-1 == width) { |
| 757 | width = desc.fWidth; |
| 758 | } |
| 759 | #ifdef SK_DEBUG |
| 760 | else { |
| 761 | SkASSERT(width <= desc.fWidth); |
| 762 | } |
| 763 | #endif |
| 764 | |
| 765 | if (-1 == height) { |
| 766 | height = desc.fHeight; |
| 767 | } |
| 768 | #ifdef SK_DEBUG |
| 769 | else { |
| 770 | SkASSERT(height <= desc.fHeight); |
| 771 | } |
| 772 | #endif |
| 773 | |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 774 | // Make sure that the width and height that we pass to OpenGL |
| 775 | // is a multiple of the block size. |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 776 | size_t dataSize = GrCompressedFormatDataSize(desc.fConfig, width, height); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 777 | |
| 778 | // We only need the internal format for compressed 2D textures. |
| 779 | GrGLenum internalFormat = 0; |
| 780 | if (!this->configToGLFormats(desc.fConfig, false, &internalFormat, NULL, NULL)) { |
| 781 | return false; |
| 782 | } |
| 783 | |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 784 | if (isNewTexture) { |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 785 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 786 | GL_ALLOC_CALL(this->glInterface(), |
| 787 | CompressedTexImage2D(GR_GL_TEXTURE_2D, |
| 788 | 0, // level |
| 789 | internalFormat, |
| 790 | width, height, |
| 791 | 0, // border |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 792 | SkToInt(dataSize), |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 793 | data)); |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 794 | GrGLenum error = check_alloc_error(desc, this->glInterface()); |
| 795 | if (error != GR_GL_NO_ERROR) { |
| 796 | return false; |
| 797 | } |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 798 | } else { |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 799 | // Paletted textures can't be updated. |
| 800 | if (GR_GL_PALETTE8_RGBA8 == internalFormat) { |
| 801 | return false; |
| 802 | } |
| 803 | GL_CALL(CompressedTexSubImage2D(GR_GL_TEXTURE_2D, |
| 804 | 0, // level |
| 805 | left, top, |
| 806 | width, height, |
| 807 | internalFormat, |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 808 | SkToInt(dataSize), |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 809 | data)); |
krajcevski | 145d48c | 2014-06-11 16:07:50 -0700 | [diff] [blame] | 810 | } |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 811 | |
bsalomon | d4cb922 | 2014-08-11 14:19:09 -0700 | [diff] [blame] | 812 | return true; |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 813 | } |
| 814 | |
commit-bot@chromium.org | 040fd8f | 2013-09-06 20:00:41 +0000 | [diff] [blame] | 815 | static bool renderbuffer_storage_msaa(GrGLContext& ctx, |
| 816 | int sampleCount, |
| 817 | GrGLenum format, |
| 818 | int width, int height) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 819 | CLEAR_ERROR_BEFORE_ALLOC(ctx.interface()); |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 820 | SkASSERT(GrGLCaps::kNone_MSFBOType != ctx.caps()->msFBOType()); |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 821 | switch (ctx.caps()->msFBOType()) { |
commit-bot@chromium.org | 040fd8f | 2013-09-06 20:00:41 +0000 | [diff] [blame] | 822 | case GrGLCaps::kDesktop_ARB_MSFBOType: |
| 823 | case GrGLCaps::kDesktop_EXT_MSFBOType: |
| 824 | case GrGLCaps::kES_3_0_MSFBOType: |
| 825 | GL_ALLOC_CALL(ctx.interface(), |
| 826 | RenderbufferStorageMultisample(GR_GL_RENDERBUFFER, |
| 827 | sampleCount, |
| 828 | format, |
| 829 | width, height)); |
| 830 | break; |
| 831 | case GrGLCaps::kES_Apple_MSFBOType: |
| 832 | GL_ALLOC_CALL(ctx.interface(), |
| 833 | RenderbufferStorageMultisampleES2APPLE(GR_GL_RENDERBUFFER, |
| 834 | sampleCount, |
| 835 | format, |
| 836 | width, height)); |
| 837 | break; |
| 838 | case GrGLCaps::kES_EXT_MsToTexture_MSFBOType: |
| 839 | case GrGLCaps::kES_IMG_MsToTexture_MSFBOType: |
| 840 | GL_ALLOC_CALL(ctx.interface(), |
| 841 | RenderbufferStorageMultisampleES2EXT(GR_GL_RENDERBUFFER, |
| 842 | sampleCount, |
| 843 | format, |
| 844 | width, height)); |
| 845 | break; |
| 846 | case GrGLCaps::kNone_MSFBOType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 847 | SkFAIL("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] | 848 | break; |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 849 | } |
Brian Salomon | 9251d4e | 2015-03-17 16:03:19 -0400 | [diff] [blame] | 850 | return (GR_GL_NO_ERROR == CHECK_ALLOC_ERROR(ctx.interface())); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 851 | } |
| 852 | |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 853 | bool GrGLGpu::createRenderTargetObjects(const GrSurfaceDesc& desc, |
| 854 | GrGpuResource::LifeCycle lifeCycle, |
| 855 | GrGLuint texID, |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 856 | GrGLRenderTarget::IDDesc* idDesc) { |
| 857 | idDesc->fMSColorRenderbufferID = 0; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 858 | idDesc->fRTFBOID = 0; |
| 859 | idDesc->fTexFBOID = 0; |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 860 | idDesc->fLifeCycle = lifeCycle; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 861 | |
| 862 | GrGLenum status; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 863 | |
bsalomon@google.com | ab15d61 | 2011-08-09 12:57:56 +0000 | [diff] [blame] | 864 | GrGLenum msColorFormat = 0; // suppress warning |
| 865 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 866 | if (desc.fSampleCnt > 0 && GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType()) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 867 | goto FAILED; |
| 868 | } |
| 869 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 870 | GL_CALL(GenFramebuffers(1, &idDesc->fTexFBOID)); |
| 871 | if (!idDesc->fTexFBOID) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 872 | goto FAILED; |
| 873 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 874 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 875 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 876 | // If we are using multisampling we will create two FBOS. We render to one and then resolve to |
| 877 | // the texture bound to the other. The exception is the IMG multisample extension. With this |
| 878 | // extension the texture is multisampled when rendered to and then auto-resolves it when it is |
| 879 | // rendered from. |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 880 | if (desc.fSampleCnt > 0 && this->glCaps().usesMSAARenderBuffers()) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 881 | GL_CALL(GenFramebuffers(1, &idDesc->fRTFBOID)); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 882 | GL_CALL(GenRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 883 | if (!idDesc->fRTFBOID || |
| 884 | !idDesc->fMSColorRenderbufferID || |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 885 | !this->configToGLFormats(desc.fConfig, |
commit-bot@chromium.org | 8700295 | 2013-08-20 15:12:01 +0000 | [diff] [blame] | 886 | // ES2 and ES3 require sized internal formats for rb storage. |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 887 | kGLES_GrGLStandard == this->glStandard(), |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 888 | &msColorFormat, |
| 889 | NULL, |
| 890 | NULL)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 891 | goto FAILED; |
| 892 | } |
| 893 | } else { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 894 | idDesc->fRTFBOID = idDesc->fTexFBOID; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 895 | } |
| 896 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 897 | // below here we may bind the FBO |
| 898 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 899 | if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 900 | SkASSERT(desc.fSampleCnt > 0); |
| 901 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, idDesc->fMSColorRenderbufferID)); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 902 | if (!renderbuffer_storage_msaa(fGLContext, |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 903 | desc.fSampleCnt, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 904 | msColorFormat, |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 905 | desc.fWidth, desc.fHeight)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 906 | goto FAILED; |
| 907 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 908 | fStats.incRenderTargetBinds(); |
| 909 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fRTFBOID)); |
| 910 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 911 | GR_GL_COLOR_ATTACHMENT0, |
| 912 | GR_GL_RENDERBUFFER, |
| 913 | idDesc->fMSColorRenderbufferID)); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 914 | if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
| 915 | !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 916 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 917 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 918 | goto FAILED; |
| 919 | } |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 920 | fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 921 | } |
| 922 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 923 | fStats.incRenderTargetBinds(); |
| 924 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, idDesc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 925 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 926 | if (this->glCaps().usesImplicitMSAAResolve() && desc.fSampleCnt > 0) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 927 | GL_CALL(FramebufferTexture2DMultisample(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 928 | GR_GL_COLOR_ATTACHMENT0, |
| 929 | GR_GL_TEXTURE_2D, |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 930 | texID, 0, desc.fSampleCnt)); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 931 | } else { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 932 | GL_CALL(FramebufferTexture2D(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 933 | GR_GL_COLOR_ATTACHMENT0, |
| 934 | GR_GL_TEXTURE_2D, |
| 935 | texID, 0)); |
| 936 | } |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 937 | if ((desc.fFlags & kCheckAllocation_GrSurfaceFlag) || |
| 938 | !this->glCaps().isConfigVerifiedColorAttachment(desc.fConfig)) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 939 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 940 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 941 | goto FAILED; |
| 942 | } |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 943 | fGLContext.caps()->markConfigAsValidColorAttachment(desc.fConfig); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | return true; |
| 947 | |
| 948 | FAILED: |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 949 | if (idDesc->fMSColorRenderbufferID) { |
| 950 | GL_CALL(DeleteRenderbuffers(1, &idDesc->fMSColorRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 951 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 952 | if (idDesc->fRTFBOID != idDesc->fTexFBOID) { |
| 953 | GL_CALL(DeleteFramebuffers(1, &idDesc->fRTFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 954 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 955 | if (idDesc->fTexFBOID) { |
| 956 | GL_CALL(DeleteFramebuffers(1, &idDesc->fTexFBOID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 957 | } |
| 958 | return false; |
| 959 | } |
| 960 | |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 961 | // good to set a break-point here to know when createTexture fails |
| 962 | static GrTexture* return_null_texture() { |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 963 | // SkDEBUGFAIL("null texture"); |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 964 | return NULL; |
| 965 | } |
| 966 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 967 | #if 0 && defined(SK_DEBUG) |
bsalomon@google.com | 3f3ffd6 | 2011-01-18 17:14:52 +0000 | [diff] [blame] | 968 | static size_t as_size_t(int x) { |
| 969 | return x; |
| 970 | } |
| 971 | #endif |
| 972 | |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 973 | GrTexture* GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, |
| 974 | GrGpuResource::LifeCycle lifeCycle, |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 975 | const void* srcData, size_t rowBytes) { |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 976 | // We fail if the MSAA was requested and is not available. |
| 977 | if (GrGLCaps::kNone_MSFBOType == this->glCaps().msFBOType() && desc.fSampleCnt) { |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 978 | //SkDebugf("MSAA RT requested but not supported on this platform."); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 979 | return return_null_texture(); |
| 980 | } |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 981 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 982 | bool renderTarget = SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 983 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 984 | GrGLTexture::IDDesc idDesc; |
| 985 | GL_CALL(GenTextures(1, &idDesc.fTextureID)); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 986 | idDesc.fLifeCycle = lifeCycle; |
junov@chromium.org | 8b6b1c9 | 2013-08-29 16:22:09 +0000 | [diff] [blame] | 987 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 988 | if (!idDesc.fTextureID) { |
bsalomon@google.com | d9f826c | 2011-07-18 15:25:04 +0000 | [diff] [blame] | 989 | return return_null_texture(); |
| 990 | } |
| 991 | |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 992 | this->setScratchTextureUnit(); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 993 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID)); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 994 | |
junov@chromium.org | 8b6b1c9 | 2013-08-29 16:22:09 +0000 | [diff] [blame] | 995 | if (renderTarget && this->glCaps().textureUsageSupport()) { |
| 996 | // provides a hint about how this texture will be used |
| 997 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 998 | GR_GL_TEXTURE_USAGE, |
| 999 | GR_GL_FRAMEBUFFER_ATTACHMENT)); |
| 1000 | } |
| 1001 | |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1002 | // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1003 | // drivers have a bug where an FBO won't be complete if it includes a |
| 1004 | // texture that is not mipmap complete (considering the filter in use). |
| 1005 | GrGLTexture::TexParams initialTexParams; |
| 1006 | // we only set a subset here so invalidate first |
| 1007 | initialTexParams.invalidate(); |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 1008 | initialTexParams.fMinFilter = GR_GL_NEAREST; |
| 1009 | initialTexParams.fMagFilter = GR_GL_NEAREST; |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1010 | initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1011 | initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1012 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1013 | GR_GL_TEXTURE_MAG_FILTER, |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 1014 | initialTexParams.fMagFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1015 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1016 | GR_GL_TEXTURE_MIN_FILTER, |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 1017 | initialTexParams.fMinFilter)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1018 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1019 | GR_GL_TEXTURE_WRAP_S, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1020 | initialTexParams.fWrapS)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1021 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1022 | GR_GL_TEXTURE_WRAP_T, |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1023 | initialTexParams.fWrapT)); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1024 | if (!this->uploadTexData(desc, true, 0, 0, |
| 1025 | desc.fWidth, desc.fHeight, |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 1026 | desc.fConfig, srcData, rowBytes)) { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1027 | GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
bsalomon@google.com | b1d14fd | 2011-12-09 18:41:34 +0000 | [diff] [blame] | 1028 | return return_null_texture(); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1029 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1030 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1031 | GrGLTexture* tex; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1032 | if (renderTarget) { |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 1033 | // unbind the texture from the texture unit before binding it to the frame buffer |
| 1034 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, 0)); |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 1035 | GrGLRenderTarget::IDDesc rtIDDesc; |
robertphillips@google.com | ba0cc3e | 2012-03-26 17:58:35 +0000 | [diff] [blame] | 1036 | |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 1037 | if (!this->createRenderTargetObjects(desc, lifeCycle, idDesc.fTextureID, &rtIDDesc)) { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1038 | GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1039 | return return_null_texture(); |
| 1040 | } |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 1041 | tex = SkNEW_ARGS(GrGLTextureRenderTarget, (this, desc, idDesc, rtIDDesc)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1042 | } else { |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1043 | tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1044 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1045 | tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1046 | #ifdef TRACE_TEXTURE_CREATION |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 1047 | SkDebugf("--- new texture [%d] size=(%d %d) config=%d\n", |
bsalomon@google.com | 64c4fe4 | 2011-11-05 14:51:01 +0000 | [diff] [blame] | 1048 | glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1049 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1050 | return tex; |
| 1051 | } |
| 1052 | |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 1053 | GrTexture* GrGLGpu::onCreateCompressedTexture(const GrSurfaceDesc& desc, |
| 1054 | GrGpuResource::LifeCycle lifeCycle, |
bsalomon | 5236cf4 | 2015-01-14 10:42:08 -0800 | [diff] [blame] | 1055 | const void* srcData) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1056 | // Make sure that we're not flipping Y. |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 1057 | if (kBottomLeft_GrSurfaceOrigin == desc.fOrigin) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1058 | return return_null_texture(); |
| 1059 | } |
| 1060 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1061 | GrGLTexture::IDDesc idDesc; |
| 1062 | GL_CALL(GenTextures(1, &idDesc.fTextureID)); |
egdaniel | b0e1be2 | 2015-04-22 13:27:39 -0700 | [diff] [blame] | 1063 | idDesc.fLifeCycle = lifeCycle; |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1064 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1065 | if (!idDesc.fTextureID) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1066 | return return_null_texture(); |
| 1067 | } |
| 1068 | |
| 1069 | this->setScratchTextureUnit(); |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1070 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, idDesc.fTextureID)); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1071 | |
| 1072 | // Some drivers like to know filter/wrap before seeing glTexImage2D. Some |
| 1073 | // drivers have a bug where an FBO won't be complete if it includes a |
| 1074 | // texture that is not mipmap complete (considering the filter in use). |
| 1075 | GrGLTexture::TexParams initialTexParams; |
| 1076 | // we only set a subset here so invalidate first |
| 1077 | initialTexParams.invalidate(); |
| 1078 | initialTexParams.fMinFilter = GR_GL_NEAREST; |
| 1079 | initialTexParams.fMagFilter = GR_GL_NEAREST; |
| 1080 | initialTexParams.fWrapS = GR_GL_CLAMP_TO_EDGE; |
| 1081 | initialTexParams.fWrapT = GR_GL_CLAMP_TO_EDGE; |
| 1082 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1083 | GR_GL_TEXTURE_MAG_FILTER, |
| 1084 | initialTexParams.fMagFilter)); |
| 1085 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1086 | GR_GL_TEXTURE_MIN_FILTER, |
| 1087 | initialTexParams.fMinFilter)); |
| 1088 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1089 | GR_GL_TEXTURE_WRAP_S, |
| 1090 | initialTexParams.fWrapS)); |
| 1091 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 1092 | GR_GL_TEXTURE_WRAP_T, |
| 1093 | initialTexParams.fWrapT)); |
| 1094 | |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1095 | if (!this->uploadCompressedTexData(desc, srcData)) { |
| 1096 | GL_CALL(DeleteTextures(1, &idDesc.fTextureID)); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1097 | return return_null_texture(); |
| 1098 | } |
| 1099 | |
| 1100 | GrGLTexture* tex; |
bsalomon | b15b4c1 | 2014-10-29 12:41:57 -0700 | [diff] [blame] | 1101 | tex = SkNEW_ARGS(GrGLTexture, (this, desc, idDesc)); |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1102 | tex->setCachedTexParams(initialTexParams, this->getResetTimestamp()); |
| 1103 | #ifdef TRACE_TEXTURE_CREATION |
tfarina | 38406c8 | 2014-10-31 07:11:12 -0700 | [diff] [blame] | 1104 | SkDebugf("--- new compressed texture [%d] size=(%d %d) config=%d\n", |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 1105 | glTexDesc.fTextureID, desc.fWidth, desc.fHeight, desc.fConfig); |
| 1106 | #endif |
| 1107 | return tex; |
| 1108 | } |
| 1109 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1110 | namespace { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1111 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1112 | const GrGLuint kUnknownBitCount = GrGLStencilAttachment::kUnknownBitCount; |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1113 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1114 | void inline get_stencil_rb_sizes(const GrGLInterface* gl, |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1115 | GrGLStencilAttachment::Format* format) { |
sugoi@google.com | 6ba0b0f | 2013-05-03 13:52:32 +0000 | [diff] [blame] | 1116 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1117 | // we shouldn't ever know one size and not the other |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1118 | SkASSERT((kUnknownBitCount == format->fStencilBits) == |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1119 | (kUnknownBitCount == format->fTotalBits)); |
| 1120 | if (kUnknownBitCount == format->fStencilBits) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1121 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1122 | GR_GL_RENDERBUFFER_STENCIL_SIZE, |
| 1123 | (GrGLint*)&format->fStencilBits); |
| 1124 | if (format->fPacked) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1125 | GR_GL_GetRenderbufferParameteriv(gl, GR_GL_RENDERBUFFER, |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1126 | GR_GL_RENDERBUFFER_DEPTH_SIZE, |
| 1127 | (GrGLint*)&format->fTotalBits); |
| 1128 | format->fTotalBits += format->fStencilBits; |
| 1129 | } else { |
| 1130 | format->fTotalBits = format->fStencilBits; |
| 1131 | } |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1136 | bool GrGLGpu::createStencilAttachmentForRenderTarget(GrRenderTarget* rt, int width, int height) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1137 | // All internally created RTs are also textures. We don't create |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 1138 | // SBs for a client's standalone RT (that is a RT that isn't also a texture). |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1139 | SkASSERT(rt->asTexture()); |
| 1140 | SkASSERT(width >= rt->width()); |
| 1141 | SkASSERT(height >= rt->height()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1142 | |
| 1143 | int samples = rt->numSamples(); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1144 | GrGLStencilAttachment::IDDesc sbDesc; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1145 | |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1146 | int stencilFmtCnt = this->glCaps().stencilFormats().count(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1147 | for (int i = 0; i < stencilFmtCnt; ++i) { |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 1148 | if (!sbDesc.fRenderbufferID) { |
| 1149 | GL_CALL(GenRenderbuffers(1, &sbDesc.fRenderbufferID)); |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 1150 | } |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 1151 | if (!sbDesc.fRenderbufferID) { |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 1152 | return false; |
| 1153 | } |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 1154 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1155 | // we start with the last stencil format that succeeded in hopes |
| 1156 | // that we won't go through this loop more than once after the |
| 1157 | // first (painful) stencil creation. |
| 1158 | int sIdx = (i + fLastSuccessfulStencilFmtIdx) % stencilFmtCnt; |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 1159 | const GrGLCaps::StencilFormat& sFmt = this->glCaps().stencilFormats()[sIdx]; |
bsalomon@google.com | 4f3c253 | 2012-01-19 16:16:52 +0000 | [diff] [blame] | 1160 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1161 | // we do this "if" so that we don't call the multisample |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1162 | // version on a GL that doesn't have an MSAA extension. |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1163 | bool created; |
| 1164 | if (samples > 0) { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 1165 | created = renderbuffer_storage_msaa(fGLContext, |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1166 | samples, |
| 1167 | sFmt.fInternalFormat, |
| 1168 | width, height); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1169 | } else { |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 1170 | GL_ALLOC_CALL(this->glInterface(), RenderbufferStorage(GR_GL_RENDERBUFFER, |
| 1171 | sFmt.fInternalFormat, |
| 1172 | width, height)); |
| 1173 | created = (GR_GL_NO_ERROR == check_alloc_error(rt->desc(), this->glInterface())); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1174 | } |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1175 | if (created) { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1176 | fStats.incStencilAttachmentCreates(); |
bsalomon@google.com | c9668ec | 2012-04-11 18:16:41 +0000 | [diff] [blame] | 1177 | // After sized formats we attempt an unsized format and take |
| 1178 | // whatever sizes GL gives us. In that case we query for the size. |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1179 | GrGLStencilAttachment::Format format = sFmt; |
sugoi@google.com | 6ba0b0f | 2013-05-03 13:52:32 +0000 | [diff] [blame] | 1180 | get_stencil_rb_sizes(this->glInterface(), &format); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1181 | SkAutoTUnref<GrGLStencilAttachment> sb(SkNEW_ARGS(GrGLStencilAttachment, |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 1182 | (this, sbDesc, width, height, samples, format))); |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1183 | if (this->attachStencilAttachmentToRenderTarget(sb, rt)) { |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1184 | fLastSuccessfulStencilFmtIdx = sIdx; |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1185 | rt->renderTargetPriv().didAttachStencilAttachment(sb); |
egdaniel | df60355 | 2015-03-18 13:26:11 -0700 | [diff] [blame] | 1186 | // This work around is currently breaking on windows 7 hd2000 bot when we bind a color buffer |
| 1187 | #if 0 |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1188 | // Clear the stencil buffer. We use a special purpose FBO for this so that the |
| 1189 | // entire stencil buffer is cleared, even if it is attached to an FBO with a |
| 1190 | // smaller color target. |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1191 | if (0 == fStencilClearFBOID) { |
| 1192 | GL_CALL(GenFramebuffers(1, &fStencilClearFBOID)); |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1193 | } |
robertphillips | 73165bd | 2015-03-01 07:38:15 -0800 | [diff] [blame] | 1194 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1195 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fStencilClearFBOID)); |
| 1196 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1197 | fStats.incRenderTargetBinds(); |
| 1198 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1199 | GR_GL_STENCIL_ATTACHMENT, |
| 1200 | GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)); |
| 1201 | if (sFmt.fPacked) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1202 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1203 | GR_GL_DEPTH_ATTACHMENT, |
| 1204 | GR_GL_RENDERBUFFER, sbDesc.fRenderbufferID)); |
| 1205 | } |
| 1206 | |
| 1207 | GL_CALL(ClearStencil(0)); |
bsalomon | 9d2049d | 2015-03-17 12:06:19 -0700 | [diff] [blame] | 1208 | // Many GL implementations seem to have trouble with clearing an FBO with only |
| 1209 | // a stencil buffer. |
| 1210 | GrGLuint tempRB; |
| 1211 | GL_CALL(GenRenderbuffers(1, &tempRB)); |
| 1212 | GL_CALL(BindRenderbuffer(GR_GL_RENDERBUFFER, tempRB)); |
Brian Salomon | 9251d4e | 2015-03-17 16:03:19 -0400 | [diff] [blame] | 1213 | if (samples > 0) { |
| 1214 | renderbuffer_storage_msaa(fGLContext, samples, GR_GL_RGBA8, width, height); |
| 1215 | } else { |
| 1216 | GL_CALL(RenderbufferStorage(GR_GL_RENDERBUFFER, GR_GL_RGBA8, width, height)); |
| 1217 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1218 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | 9d2049d | 2015-03-17 12:06:19 -0700 | [diff] [blame] | 1219 | GR_GL_COLOR_ATTACHMENT0, |
| 1220 | GR_GL_RENDERBUFFER, tempRB)); |
| 1221 | |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1222 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
| 1223 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1224 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | 9d2049d | 2015-03-17 12:06:19 -0700 | [diff] [blame] | 1225 | GR_GL_COLOR_ATTACHMENT0, |
| 1226 | GR_GL_RENDERBUFFER, 0)); |
| 1227 | GL_CALL(DeleteRenderbuffers(1, &tempRB)); |
| 1228 | |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1229 | // Unbind the SB from the FBO so that we don't keep it alive. |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1230 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1231 | GR_GL_STENCIL_ATTACHMENT, |
| 1232 | GR_GL_RENDERBUFFER, 0)); |
| 1233 | if (sFmt.fPacked) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1234 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon | dd3143b | 2015-02-23 09:27:45 -0800 | [diff] [blame] | 1235 | GR_GL_DEPTH_ATTACHMENT, |
| 1236 | GR_GL_RENDERBUFFER, 0)); |
| 1237 | } |
egdaniel | df60355 | 2015-03-18 13:26:11 -0700 | [diff] [blame] | 1238 | #endif |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1239 | return true; |
bsalomon | 12299ab | 2014-11-14 13:33:09 -0800 | [diff] [blame] | 1240 | } |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1241 | // Remove the scratch key from this resource so we don't grab it from the cache ever |
| 1242 | // again. |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 1243 | sb->resourcePriv().removeScratchKey(); |
bsalomon | 10e23ca | 2014-11-25 05:52:06 -0800 | [diff] [blame] | 1244 | // Set this to 0 since we handed the valid ID off to the failed stencil buffer resource. |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 1245 | sbDesc.fRenderbufferID = 0; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1246 | } |
| 1247 | } |
kkinnunen | 36c57df | 2015-01-27 00:30:18 -0800 | [diff] [blame] | 1248 | GL_CALL(DeleteRenderbuffers(1, &sbDesc.fRenderbufferID)); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 1249 | return false; |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1250 | } |
| 1251 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1252 | bool GrGLGpu::attachStencilAttachmentToRenderTarget(GrStencilAttachment* sb, GrRenderTarget* rt) { |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 1253 | GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1254 | |
| 1255 | GrGLuint fbo = glrt->renderFBOID(); |
| 1256 | |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1257 | if (NULL == sb) { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1258 | if (rt->renderTargetPriv().getStencilAttachment()) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1259 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1260 | GR_GL_STENCIL_ATTACHMENT, |
| 1261 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1262 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1263 | GR_GL_DEPTH_ATTACHMENT, |
| 1264 | GR_GL_RENDERBUFFER, 0)); |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 1265 | #ifdef SK_DEBUG |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1266 | GrGLenum status; |
| 1267 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1268 | SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1269 | #endif |
| 1270 | } |
| 1271 | return true; |
| 1272 | } else { |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1273 | GrGLStencilAttachment* glsb = static_cast<GrGLStencilAttachment*>(sb); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1274 | GrGLuint rb = glsb->renderbufferID(); |
| 1275 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1276 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1277 | fStats.incRenderTargetBinds(); |
| 1278 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo)); |
| 1279 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1280 | GR_GL_STENCIL_ATTACHMENT, |
| 1281 | GR_GL_RENDERBUFFER, rb)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1282 | if (glsb->format().fPacked) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1283 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1284 | GR_GL_DEPTH_ATTACHMENT, |
| 1285 | GR_GL_RENDERBUFFER, rb)); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1286 | } else { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1287 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1288 | GR_GL_DEPTH_ATTACHMENT, |
| 1289 | GR_GL_RENDERBUFFER, 0)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1290 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1291 | |
bsalomon@google.com | 56bfc5a | 2011-09-01 13:28:16 +0000 | [diff] [blame] | 1292 | GrGLenum status; |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1293 | if (!this->glCaps().isColorConfigAndStencilFormatVerified(rt->config(), glsb->format())) { |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1294 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1295 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1296 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1297 | GR_GL_STENCIL_ATTACHMENT, |
| 1298 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1299 | if (glsb->format().fPacked) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1300 | GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 1301 | GR_GL_DEPTH_ATTACHMENT, |
| 1302 | GR_GL_RENDERBUFFER, 0)); |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1303 | } |
| 1304 | return false; |
| 1305 | } else { |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 1306 | fGLContext.caps()->markColorConfigAndStencilFormatAsVerified( |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1307 | rt->config(), |
| 1308 | glsb->format()); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1309 | } |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1310 | } |
bsalomon@google.com | 4bcb0c6 | 2012-02-07 16:06:47 +0000 | [diff] [blame] | 1311 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1312 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
bsalomon@google.com | 71f341a | 2011-08-01 13:36:00 +0000 | [diff] [blame] | 1315 | //////////////////////////////////////////////////////////////////////////////// |
| 1316 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1317 | GrVertexBuffer* GrGLGpu::onCreateVertexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1318 | GrGLVertexBuffer::Desc desc; |
| 1319 | desc.fDynamic = dynamic; |
| 1320 | desc.fSizeInBytes = size; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1321 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 1322 | if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1323 | desc.fID = 0; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1324 | GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1325 | return vertexBuffer; |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1326 | } else { |
| 1327 | GL_CALL(GenBuffers(1, &desc.fID)); |
| 1328 | if (desc.fID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1329 | fHWGeometryState.setVertexBufferID(this, desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1330 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1331 | // make sure driver can allocate memory for this buffer |
| 1332 | GL_ALLOC_CALL(this->glInterface(), |
| 1333 | BufferData(GR_GL_ARRAY_BUFFER, |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 1334 | (GrGLsizeiptr) desc.fSizeInBytes, |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1335 | NULL, // data ptr |
| 1336 | desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1337 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1338 | GL_CALL(DeleteBuffers(1, &desc.fID)); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1339 | this->notifyVertexBufferDelete(desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1340 | return NULL; |
| 1341 | } |
| 1342 | GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer, (this, desc)); |
| 1343 | return vertexBuffer; |
| 1344 | } |
| 1345 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1346 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1349 | GrIndexBuffer* GrGLGpu::onCreateIndexBuffer(size_t size, bool dynamic) { |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1350 | GrGLIndexBuffer::Desc desc; |
| 1351 | desc.fDynamic = dynamic; |
| 1352 | desc.fSizeInBytes = size; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1353 | |
bsalomon@google.com | 96966a5 | 2013-02-21 16:34:21 +0000 | [diff] [blame] | 1354 | if (this->glCaps().useNonVBOVertexAndIndexDynamicData() && desc.fDynamic) { |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1355 | desc.fID = 0; |
bsalomon@google.com | e49ad45 | 2013-02-20 19:33:20 +0000 | [diff] [blame] | 1356 | GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1357 | return indexBuffer; |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1358 | } else { |
| 1359 | GL_CALL(GenBuffers(1, &desc.fID)); |
| 1360 | if (desc.fID) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1361 | fHWGeometryState.setIndexBufferIDOnDefaultVertexArray(this, desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1362 | CLEAR_ERROR_BEFORE_ALLOC(this->glInterface()); |
| 1363 | // make sure driver can allocate memory for this buffer |
| 1364 | GL_ALLOC_CALL(this->glInterface(), |
| 1365 | BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 1366 | (GrGLsizeiptr) desc.fSizeInBytes, |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1367 | NULL, // data ptr |
| 1368 | desc.fDynamic ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW)); |
| 1369 | if (CHECK_ALLOC_ERROR(this->glInterface()) != GR_GL_NO_ERROR) { |
| 1370 | GL_CALL(DeleteBuffers(1, &desc.fID)); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 1371 | this->notifyIndexBufferDelete(desc.fID); |
bsalomon@google.com | ee3bc3b | 2013-02-21 14:33:46 +0000 | [diff] [blame] | 1372 | return NULL; |
| 1373 | } |
| 1374 | GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer, (this, desc)); |
| 1375 | return indexBuffer; |
| 1376 | } |
| 1377 | return NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1378 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1381 | void GrGLGpu::flushScissor(const GrScissorState& scissorState, |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 1382 | const GrGLIRect& rtViewport, |
| 1383 | GrSurfaceOrigin rtOrigin) { |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 1384 | if (scissorState.enabled()) { |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1385 | GrGLIRect scissor; |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1386 | scissor.setRelativeTo(rtViewport, |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 1387 | scissorState.rect().fLeft, |
| 1388 | scissorState.rect().fTop, |
| 1389 | scissorState.rect().width(), |
| 1390 | scissorState.rect().height(), |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1391 | rtOrigin); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1392 | // if the scissor fully contains the viewport then we fall through and |
| 1393 | // disable the scissor test. |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1394 | if (!scissor.contains(rtViewport)) { |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1395 | if (fHWScissorSettings.fRect != scissor) { |
| 1396 | scissor.pushToGLScissor(this->glInterface()); |
| 1397 | fHWScissorSettings.fRect = scissor; |
| 1398 | } |
| 1399 | if (kYes_TriState != fHWScissorSettings.fEnabled) { |
| 1400 | GL_CALL(Enable(GR_GL_SCISSOR_TEST)); |
| 1401 | fHWScissorSettings.fEnabled = kYes_TriState; |
| 1402 | } |
| 1403 | return; |
| 1404 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1405 | } |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 1406 | |
| 1407 | // See fall through note above |
| 1408 | this->disableScissor(); |
| 1409 | } |
| 1410 | |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 1411 | bool GrGLGpu::flushGLState(const DrawArgs& args) { |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 1412 | GrXferProcessor::BlendInfo blendInfo; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1413 | const GrPipeline& pipeline = *args.fPipeline; |
| 1414 | args.fPipeline->getXferProcessor()->getBlendInfo(&blendInfo); |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 1415 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1416 | this->flushDither(pipeline.isDitherState()); |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 1417 | this->flushColorWrite(blendInfo.fWriteColor); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1418 | this->flushDrawFace(pipeline.getDrawFace()); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1419 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 1420 | fCurrentProgram.reset(fProgramCache->getProgram(args)); |
| 1421 | if (NULL == fCurrentProgram.get()) { |
joshualitt | 6c89110 | 2015-05-13 08:51:49 -0700 | [diff] [blame] | 1422 | GrContextDebugf(this->getContext(), "Failed to create program!\n"); |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1423 | return false; |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1424 | } |
| 1425 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 1426 | fCurrentProgram.get()->ref(); |
| 1427 | |
| 1428 | GrGLuint programID = fCurrentProgram->programID(); |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1429 | if (fHWProgramID != programID) { |
| 1430 | GL_CALL(UseProgram(programID)); |
| 1431 | fHWProgramID = programID; |
| 1432 | } |
| 1433 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1434 | if (blendInfo.fWriteColor) { |
| 1435 | this->flushBlend(blendInfo); |
| 1436 | } |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1437 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 1438 | fCurrentProgram->setData(*args.fPrimitiveProcessor, pipeline, *args.fBatchTracker); |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1439 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1440 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(pipeline.getRenderTarget()); |
| 1441 | this->flushStencil(pipeline.getStencil()); |
| 1442 | this->flushScissor(pipeline.getScissorState(), glRT->getViewport(), glRT->origin()); |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 1443 | this->flushHWAAState(glRT, pipeline.isHWAntialiasState()); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1444 | |
| 1445 | // This must come after textures are flushed because a texture may need |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1446 | // to be msaa-resolved (which will modify bound FBO state). |
| 1447 | this->flushRenderTarget(glRT, NULL); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1448 | |
| 1449 | return true; |
| 1450 | } |
| 1451 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1452 | void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc, |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1453 | const GrNonInstancedVertices& vertices, |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1454 | size_t* indexOffsetInBytes) { |
| 1455 | GrGLVertexBuffer* vbuf; |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1456 | vbuf = (GrGLVertexBuffer*) vertices.vertexBuffer(); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1457 | |
| 1458 | SkASSERT(vbuf); |
| 1459 | SkASSERT(!vbuf->isMapped()); |
| 1460 | |
| 1461 | GrGLIndexBuffer* ibuf = NULL; |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1462 | if (vertices.isIndexed()) { |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1463 | SkASSERT(indexOffsetInBytes); |
| 1464 | |
| 1465 | *indexOffsetInBytes = 0; |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1466 | ibuf = (GrGLIndexBuffer*)vertices.indexBuffer(); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1467 | |
| 1468 | SkASSERT(ibuf); |
| 1469 | SkASSERT(!ibuf->isMapped()); |
| 1470 | *indexOffsetInBytes += ibuf->baseOffset(); |
| 1471 | } |
| 1472 | GrGLAttribArrayState* attribState = |
| 1473 | fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf); |
| 1474 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1475 | int vaCount = primProc.numAttribs(); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 1476 | if (vaCount > 0) { |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1477 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1478 | GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride()); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1479 | |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1480 | size_t vertexOffsetInBytes = stride * vertices.startVertex(); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1481 | |
| 1482 | vertexOffsetInBytes += vbuf->baseOffset(); |
| 1483 | |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1484 | uint32_t usedAttribArraysMask = 0; |
| 1485 | size_t offset = 0; |
| 1486 | |
| 1487 | for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1488 | const GrGeometryProcessor::Attribute& attrib = primProc.getAttrib(attribIndex); |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1489 | usedAttribArraysMask |= (1 << attribIndex); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 1490 | GrVertexAttribType attribType = attrib.fType; |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1491 | attribState->set(this, |
| 1492 | attribIndex, |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 1493 | vbuf, |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1494 | GrGLAttribTypeToLayout(attribType).fCount, |
| 1495 | GrGLAttribTypeToLayout(attribType).fType, |
| 1496 | GrGLAttribTypeToLayout(attribType).fNormalized, |
| 1497 | stride, |
| 1498 | reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + offset)); |
joshualitt | 71c9260 | 2015-01-14 08:12:47 -0800 | [diff] [blame] | 1499 | offset += attrib.fOffset; |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1500 | } |
| 1501 | attribState->disableUnusedArrays(this, usedAttribArraysMask); |
| 1502 | } |
| 1503 | } |
| 1504 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1505 | void GrGLGpu::buildProgramDesc(GrProgramDesc* desc, |
| 1506 | const GrPrimitiveProcessor& primProc, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1507 | const GrPipeline& pipeline, |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1508 | const GrBatchTracker& batchTracker) const { |
bsalomon | 50785a3 | 2015-02-06 07:02:37 -0800 | [diff] [blame] | 1509 | if (!GrGLProgramDescBuilder::Build(desc, primProc, pipeline, this, batchTracker)) { |
bsalomon | bc3d0de | 2014-12-15 13:45:03 -0800 | [diff] [blame] | 1510 | SkDEBUGFAIL("Failed to generate GL program descriptor"); |
| 1511 | } |
| 1512 | } |
| 1513 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1514 | void GrGLGpu::disableScissor() { |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1515 | if (kNo_TriState != fHWScissorSettings.fEnabled) { |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 1516 | GL_CALL(Disable(GR_GL_SCISSOR_TEST)); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1517 | fHWScissorSettings.fEnabled = kNo_TriState; |
| 1518 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1519 | } |
| 1520 | } |
| 1521 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1522 | void GrGLGpu::onClear(GrRenderTarget* target, const SkIRect* rect, GrColor color, |
joshualitt | 4b68ec0 | 2014-11-07 14:11:45 -0800 | [diff] [blame] | 1523 | bool canIgnoreRect) { |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1524 | // parent class should never let us get here with no RT |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1525 | SkASSERT(target); |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1526 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 0ba52fc | 2011-11-10 22:16:06 +0000 | [diff] [blame] | 1527 | |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 1528 | if (canIgnoreRect && this->glCaps().fullClearIsFree()) { |
| 1529 | rect = NULL; |
| 1530 | } |
| 1531 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 1532 | SkIRect clippedRect; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1533 | if (rect) { |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1534 | // flushScissor expects rect to be clipped to the target. |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1535 | clippedRect = *rect; |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1536 | SkIRect rtRect = SkIRect::MakeWH(target->width(), target->height()); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1537 | if (clippedRect.intersect(rtRect)) { |
| 1538 | rect = &clippedRect; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 1539 | } else { |
| 1540 | return; |
| 1541 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1542 | } |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 1543 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1544 | this->flushRenderTarget(glRT, rect); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1545 | GrScissorState scissorState; |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 1546 | if (rect) { |
| 1547 | scissorState.set(*rect); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1548 | } |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 1549 | this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1550 | |
| 1551 | GrGLfloat r, g, b, a; |
| 1552 | static const GrGLfloat scale255 = 1.f / 255.f; |
| 1553 | a = GrColorUnpackA(color) * scale255; |
| 1554 | GrGLfloat scaleRGB = scale255; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1555 | r = GrColorUnpackR(color) * scaleRGB; |
| 1556 | g = GrColorUnpackG(color) * scaleRGB; |
| 1557 | b = GrColorUnpackB(color) * scaleRGB; |
| 1558 | |
| 1559 | 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] | 1560 | fHWWriteToColor = kYes_TriState; |
bsalomon@google.com | 74b9871 | 2011-11-11 19:46:16 +0000 | [diff] [blame] | 1561 | GL_CALL(ClearColor(r, g, b, a)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1562 | GL_CALL(Clear(GR_GL_COLOR_BUFFER_BIT)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1565 | void GrGLGpu::discard(GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 1566 | SkASSERT(renderTarget); |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1567 | if (!this->caps()->discardRenderTargetSupport()) { |
| 1568 | return; |
| 1569 | } |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1570 | |
| 1571 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1572 | if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) { |
| 1573 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 1574 | fStats.incRenderTargetBinds(); |
| 1575 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID())); |
| 1576 | } |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1577 | switch (this->glCaps().invalidateFBType()) { |
joshualitt | 5816233 | 2014-08-01 06:44:53 -0700 | [diff] [blame] | 1578 | case GrGLCaps::kNone_InvalidateFBType: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 1579 | SkFAIL("Should never get here."); |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1580 | break; |
| 1581 | case GrGLCaps::kInvalidate_InvalidateFBType: |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1582 | if (0 == glRT->renderFBOID()) { |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1583 | // When rendering to the default framebuffer the legal values for attachments |
| 1584 | // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the various FBO attachment |
| 1585 | // types. |
| 1586 | static const GrGLenum attachments[] = { GR_GL_COLOR }; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1587 | GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments), |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1588 | attachments)); |
| 1589 | } else { |
| 1590 | static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 }; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1591 | GL_CALL(InvalidateFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments), |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1592 | attachments)); |
| 1593 | } |
| 1594 | break; |
| 1595 | case GrGLCaps::kDiscard_InvalidateFBType: { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1596 | if (0 == glRT->renderFBOID()) { |
commit-bot@chromium.org | 4453e8b | 2014-04-16 14:33:27 +0000 | [diff] [blame] | 1597 | // When rendering to the default framebuffer the legal values for attachments |
| 1598 | // are GL_COLOR, GL_DEPTH, GL_STENCIL, ... rather than the various FBO attachment |
| 1599 | // types. See glDiscardFramebuffer() spec. |
| 1600 | static const GrGLenum attachments[] = { GR_GL_COLOR }; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1601 | GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments), |
commit-bot@chromium.org | 4453e8b | 2014-04-16 14:33:27 +0000 | [diff] [blame] | 1602 | attachments)); |
| 1603 | } else { |
| 1604 | static const GrGLenum attachments[] = { GR_GL_COLOR_ATTACHMENT0 }; |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1605 | GL_CALL(DiscardFramebuffer(GR_GL_FRAMEBUFFER, SK_ARRAY_COUNT(attachments), |
commit-bot@chromium.org | 4453e8b | 2014-04-16 14:33:27 +0000 | [diff] [blame] | 1606 | attachments)); |
| 1607 | } |
commit-bot@chromium.org | 52ffbf6 | 2014-04-02 16:19:33 +0000 | [diff] [blame] | 1608 | break; |
| 1609 | } |
| 1610 | } |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1611 | renderTarget->flagAsResolved(); |
| 1612 | } |
| 1613 | |
| 1614 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1615 | void GrGLGpu::clearStencil(GrRenderTarget* target) { |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1616 | if (NULL == target) { |
bsalomon@google.com | 7d34d2e | 2011-01-24 17:41:47 +0000 | [diff] [blame] | 1617 | return; |
| 1618 | } |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1619 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1620 | this->flushRenderTarget(glRT, &SkIRect::EmptyIRect()); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1621 | |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 1622 | this->disableScissor(); |
robertphillips@google.com | 730ebe5 | 2012-04-16 16:33:13 +0000 | [diff] [blame] | 1623 | |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1624 | GL_CALL(StencilMask(0xffffffff)); |
| 1625 | GL_CALL(ClearStencil(0)); |
| 1626 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1627 | fHWStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1630 | void GrGLGpu::onClearStencilClip(GrRenderTarget* target, const SkIRect& rect, bool insideClip) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1631 | SkASSERT(target); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1632 | |
egdaniel | 8dc7c3a | 2015-04-16 11:22:42 -0700 | [diff] [blame] | 1633 | GrStencilAttachment* sb = target->renderTargetPriv().getStencilAttachment(); |
bsalomon@google.com | 81c3f8d | 2011-08-03 15:18:33 +0000 | [diff] [blame] | 1634 | // this should only be called internally when we know we have a |
| 1635 | // stencil buffer. |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 1636 | SkASSERT(sb); |
| 1637 | GrGLint stencilBitCount = sb->bits(); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1638 | #if 0 |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1639 | SkASSERT(stencilBitCount > 0); |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1640 | GrGLint clipStencilMask = (1 << (stencilBitCount - 1)); |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1641 | #else |
| 1642 | // 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] | 1643 | // ANGLE a partial stencil mask will cause clears to be |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1644 | // turned into draws. Our contract on GrDrawTarget says that |
| 1645 | // changing the clip between stencil passes may or may not |
| 1646 | // 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] | 1647 | static const GrGLint clipStencilMask = ~0; |
bsalomon@google.com | 5aaa69e | 2011-03-04 20:29:08 +0000 | [diff] [blame] | 1648 | #endif |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1649 | GrGLint value; |
| 1650 | if (insideClip) { |
| 1651 | value = (1 << (stencilBitCount - 1)); |
| 1652 | } else { |
| 1653 | value = 0; |
| 1654 | } |
bsalomon | b0bd4f6 | 2014-09-03 07:19:50 -0700 | [diff] [blame] | 1655 | GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(target); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1656 | this->flushRenderTarget(glRT, &SkIRect::EmptyIRect()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1657 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1658 | GrScissorState scissorState; |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 1659 | scissorState.set(rect); |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 1660 | this->flushScissor(scissorState, glRT->getViewport(), glRT->origin()); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 1661 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1662 | GL_CALL(StencilMask((uint32_t) clipStencilMask)); |
bsalomon@google.com | ab3dee5 | 2011-08-29 15:18:41 +0000 | [diff] [blame] | 1663 | GL_CALL(ClearStencil(value)); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1664 | GL_CALL(Clear(GR_GL_STENCIL_BUFFER_BIT)); |
bsalomon@google.com | 457b8a3 | 2012-05-21 21:19:58 +0000 | [diff] [blame] | 1665 | fHWStencilSettings.invalidate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1668 | bool GrGLGpu::readPixelsWillPayForYFlip(GrRenderTarget* renderTarget, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1669 | int left, int top, |
| 1670 | int width, int height, |
| 1671 | GrPixelConfig config, |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1672 | size_t rowBytes) const { |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1673 | // If this rendertarget is aready TopLeft, we don't need to flip. |
| 1674 | if (kTopLeft_GrSurfaceOrigin == renderTarget->origin()) { |
| 1675 | return false; |
| 1676 | } |
| 1677 | |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1678 | // if GL can do the flip then we'll never pay for it. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1679 | if (this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1680 | return false; |
| 1681 | } |
| 1682 | |
| 1683 | // If we have to do memcpy to handle non-trim rowBytes then we |
bsalomon@google.com | 7107fa7 | 2011-11-10 14:54:14 +0000 | [diff] [blame] | 1684 | // get the flip for free. Otherwise it costs. |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1685 | if (this->glCaps().packRowLengthSupport()) { |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1686 | return true; |
| 1687 | } |
| 1688 | // If we have to do memcpys to handle rowBytes then y-flip is free |
| 1689 | // Note the rowBytes might be tight to the passed in data, but if data |
| 1690 | // gets clipped in x to the target the rowBytes will no longer be tight. |
| 1691 | if (left >= 0 && (left + width) < renderTarget->width()) { |
| 1692 | return 0 == rowBytes || |
| 1693 | GrBytesPerPixel(config) * width == rowBytes; |
| 1694 | } else { |
| 1695 | return false; |
| 1696 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1699 | bool GrGLGpu::onReadPixels(GrRenderTarget* target, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1700 | int left, int top, |
| 1701 | int width, int height, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1702 | GrPixelConfig config, |
| 1703 | void* buffer, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1704 | size_t rowBytes) { |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 1705 | // We cannot read pixels into a compressed buffer |
| 1706 | if (GrPixelConfigIsCompressed(config)) { |
| 1707 | return false; |
| 1708 | } |
| 1709 | |
| 1710 | GrGLenum format = 0; |
| 1711 | GrGLenum type = 0; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1712 | bool flipY = kBottomLeft_GrSurfaceOrigin == target->origin(); |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 1713 | if (!this->configToGLFormats(config, false, NULL, &format, &type)) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1714 | return false; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1715 | } |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1716 | size_t bpp = GrBytesPerPixel(config); |
| 1717 | if (!adjust_pixel_ops_params(target->width(), target->height(), bpp, |
| 1718 | &left, &top, &width, &height, |
| 1719 | const_cast<const void**>(&buffer), |
| 1720 | &rowBytes)) { |
| 1721 | return false; |
| 1722 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1723 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1724 | // resolve the render target if necessary |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1725 | GrGLRenderTarget* tgt = static_cast<GrGLRenderTarget*>(target); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1726 | switch (tgt->getResolveType()) { |
| 1727 | case GrGLRenderTarget::kCantResolve_ResolveType: |
| 1728 | return false; |
| 1729 | case GrGLRenderTarget::kAutoResolves_ResolveType: |
| 1730 | this->flushRenderTarget(static_cast<GrGLRenderTarget*>(target), &SkIRect::EmptyIRect()); |
| 1731 | break; |
| 1732 | case GrGLRenderTarget::kCanResolve_ResolveType: |
| 1733 | this->onResolveRenderTarget(tgt); |
| 1734 | // we don't track the state of the READ FBO ID. |
| 1735 | fStats.incRenderTargetBinds(); |
| 1736 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, |
| 1737 | tgt->textureFBOID())); |
| 1738 | break; |
| 1739 | default: |
| 1740 | SkFAIL("Unknown resolve type"); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1743 | const GrGLIRect& glvp = tgt->getViewport(); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1744 | |
bsalomon@google.com | 8895a7a | 2011-02-18 16:09:55 +0000 | [diff] [blame] | 1745 | // the read rect is viewport-relative |
| 1746 | GrGLIRect readRect; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1747 | readRect.setRelativeTo(glvp, left, top, width, height, target->origin()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1748 | |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1749 | size_t tightRowBytes = bpp * width; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1750 | if (0 == rowBytes) { |
| 1751 | rowBytes = tightRowBytes; |
| 1752 | } |
| 1753 | size_t readDstRowBytes = tightRowBytes; |
| 1754 | void* readDst = buffer; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1755 | |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1756 | // determine if GL can read using the passed rowBytes or if we need |
| 1757 | // a scratch buffer. |
george | b62508b | 2014-08-12 18:00:47 -0700 | [diff] [blame] | 1758 | GrAutoMalloc<32 * sizeof(GrColor)> scratch; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1759 | if (rowBytes != tightRowBytes) { |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 1760 | if (this->glCaps().packRowLengthSupport()) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1761 | SkASSERT(!(rowBytes % sizeof(GrColor))); |
skia.committer@gmail.com | 4677acc | 2013-10-17 07:02:33 +0000 | [diff] [blame] | 1762 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 1763 | static_cast<GrGLint>(rowBytes / sizeof(GrColor)))); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1764 | readDstRowBytes = rowBytes; |
| 1765 | } else { |
| 1766 | scratch.reset(tightRowBytes * height); |
| 1767 | readDst = scratch.get(); |
| 1768 | } |
| 1769 | } |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1770 | if (flipY && this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1771 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 1)); |
| 1772 | } |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1773 | GL_CALL(ReadPixels(readRect.fLeft, readRect.fBottom, |
| 1774 | readRect.fWidth, readRect.fHeight, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1775 | format, type, readDst)); |
| 1776 | if (readDstRowBytes != tightRowBytes) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1777 | SkASSERT(this->glCaps().packRowLengthSupport()); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1778 | GL_CALL(PixelStorei(GR_GL_PACK_ROW_LENGTH, 0)); |
| 1779 | } |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1780 | if (flipY && this->glCaps().packFlipYSupport()) { |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1781 | GL_CALL(PixelStorei(GR_GL_PACK_REVERSE_ROW_ORDER, 0)); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1782 | flipY = false; |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1783 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1784 | |
| 1785 | // now reverse the order of the rows, since GL's are bottom-to-top, but our |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1786 | // API presents top-to-bottom. We must preserve the padding contents. Note |
| 1787 | // that the above readPixels did not overwrite the padding. |
| 1788 | if (readDst == buffer) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1789 | SkASSERT(rowBytes == readDstRowBytes); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1790 | if (flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1791 | scratch.reset(tightRowBytes); |
| 1792 | void* tmpRow = scratch.get(); |
| 1793 | // flip y in-place by rows |
| 1794 | const int halfY = height >> 1; |
| 1795 | char* top = reinterpret_cast<char*>(buffer); |
| 1796 | char* bottom = top + (height - 1) * rowBytes; |
| 1797 | for (int y = 0; y < halfY; y++) { |
| 1798 | memcpy(tmpRow, top, tightRowBytes); |
| 1799 | memcpy(top, bottom, tightRowBytes); |
| 1800 | memcpy(bottom, tmpRow, tightRowBytes); |
| 1801 | top += rowBytes; |
| 1802 | bottom -= rowBytes; |
| 1803 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1804 | } |
| 1805 | } else { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1806 | SkASSERT(readDst != buffer); SkASSERT(rowBytes != tightRowBytes); |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1807 | // copy from readDst to buffer while flipping y |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 1808 | // const int halfY = height >> 1; |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1809 | const char* src = reinterpret_cast<const char*>(readDst); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1810 | char* dst = reinterpret_cast<char*>(buffer); |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1811 | if (flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1812 | dst += (height-1) * rowBytes; |
| 1813 | } |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 1814 | for (int y = 0; y < height; y++) { |
| 1815 | memcpy(dst, src, tightRowBytes); |
| 1816 | src += readDstRowBytes; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1817 | if (!flipY) { |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1818 | dst += rowBytes; |
| 1819 | } else { |
| 1820 | dst -= rowBytes; |
| 1821 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1822 | } |
| 1823 | } |
| 1824 | return true; |
| 1825 | } |
| 1826 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1827 | void GrGLGpu::flushRenderTarget(GrGLRenderTarget* target, const SkIRect* bound) { |
bsalomon@google.com | 2e7b43d | 2011-01-18 20:57:22 +0000 | [diff] [blame] | 1828 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1829 | SkASSERT(target); |
bsalomon | 6ba6fa1 | 2015-03-04 11:57:37 -0800 | [diff] [blame] | 1830 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1831 | uint32_t rtID = target->getUniqueID(); |
| 1832 | if (fHWBoundRenderTargetUniqueID != rtID) { |
bsalomon | 1e0bf7e | 2015-03-14 12:08:51 -0700 | [diff] [blame] | 1833 | fStats.incRenderTargetBinds(); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1834 | GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID())); |
| 1835 | #ifdef SK_DEBUG |
| 1836 | // don't do this check in Chromium -- this is causing |
| 1837 | // lots of repeated command buffer flushes when the compositor is |
| 1838 | // rendering with Ganesh, which is really slow; even too slow for |
| 1839 | // Debug mode. |
| 1840 | if (!this->glContext().isChromium()) { |
| 1841 | GrGLenum status; |
| 1842 | GL_CALL_RET(status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 1843 | if (status != GR_GL_FRAMEBUFFER_COMPLETE) { |
| 1844 | SkDebugf("GrGLGpu::flushRenderTarget glCheckFramebufferStatus %x\n", status); |
| 1845 | } |
bsalomon | 160f24c | 2015-03-17 15:55:42 -0700 | [diff] [blame] | 1846 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1847 | #endif |
| 1848 | fHWBoundRenderTargetUniqueID = rtID; |
| 1849 | const GrGLIRect& vp = target->getViewport(); |
| 1850 | if (fHWViewport != vp) { |
| 1851 | vp.pushToGLViewport(this->glInterface()); |
| 1852 | fHWViewport = vp; |
bsalomon | 160f24c | 2015-03-17 15:55:42 -0700 | [diff] [blame] | 1853 | } |
bsalomon | 5cd020f | 2015-03-17 12:46:56 -0700 | [diff] [blame] | 1854 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1855 | if (NULL == bound || !bound->isEmpty()) { |
| 1856 | target->flagAsNeedingResolve(bound); |
| 1857 | } |
| 1858 | |
| 1859 | GrTexture *texture = target->asTexture(); |
| 1860 | if (texture) { |
| 1861 | texture->texturePriv().dirtyMipMaps(true); |
| 1862 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 1865 | GrGLenum gPrimitiveType2GLMode[] = { |
| 1866 | GR_GL_TRIANGLES, |
| 1867 | GR_GL_TRIANGLE_STRIP, |
| 1868 | GR_GL_TRIANGLE_FAN, |
| 1869 | GR_GL_POINTS, |
| 1870 | GR_GL_LINES, |
| 1871 | GR_GL_LINE_STRIP |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1872 | }; |
| 1873 | |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1874 | #define SWAP_PER_DRAW 0 |
| 1875 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1876 | #if SWAP_PER_DRAW |
commit-bot@chromium.org | 4382330 | 2013-09-25 20:57:51 +0000 | [diff] [blame] | 1877 | #if defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1878 | #include <AGL/agl.h> |
commit-bot@chromium.org | 4382330 | 2013-09-25 20:57:51 +0000 | [diff] [blame] | 1879 | #elif defined(SK_BUILD_FOR_WIN32) |
bsalomon@google.com | ce7357d | 2012-06-25 17:49:25 +0000 | [diff] [blame] | 1880 | #include <gl/GL.h> |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1881 | void SwapBuf() { |
| 1882 | DWORD procID = GetCurrentProcessId(); |
| 1883 | HWND hwnd = GetTopWindow(GetDesktopWindow()); |
| 1884 | while(hwnd) { |
| 1885 | DWORD wndProcID = 0; |
| 1886 | GetWindowThreadProcessId(hwnd, &wndProcID); |
| 1887 | if(wndProcID == procID) { |
| 1888 | SwapBuffers(GetDC(hwnd)); |
| 1889 | } |
| 1890 | hwnd = GetNextWindow(hwnd, GW_HWNDNEXT); |
| 1891 | } |
| 1892 | } |
| 1893 | #endif |
| 1894 | #endif |
| 1895 | |
bsalomon | e64eb57 | 2015-05-07 11:35:55 -0700 | [diff] [blame] | 1896 | void GrGLGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertices) { |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 1897 | if (!this->flushGLState(args)) { |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 1898 | return; |
| 1899 | } |
| 1900 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1901 | size_t indexOffsetInBytes = 0; |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1902 | this->setupGeometry(*args.fPrimitiveProcessor, vertices, &indexOffsetInBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1903 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1904 | SkASSERT((size_t)vertices.primitiveType() < SK_ARRAY_COUNT(gPrimitiveType2GLMode)); |
bsalomon@google.com | 1c13c96 | 2011-02-14 16:51:21 +0000 | [diff] [blame] | 1905 | |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1906 | if (vertices.isIndexed()) { |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 1907 | GrGLvoid* indices = |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1908 | reinterpret_cast<GrGLvoid*>(indexOffsetInBytes + sizeof(uint16_t) * |
| 1909 | vertices.startIndex()); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1910 | // info.startVertex() was accounted for by setupGeometry. |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1911 | GL_CALL(DrawElements(gPrimitiveType2GLMode[vertices.primitiveType()], |
| 1912 | vertices.indexCount(), |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1913 | GR_GL_UNSIGNED_SHORT, |
| 1914 | indices)); |
| 1915 | } else { |
| 1916 | // Pass 0 for parameter first. We have to adjust glVertexAttribPointer() to account for |
| 1917 | // startVertex in the DrawElements case. So we always rely on setupGeometry to have |
| 1918 | // accounted for startVertex. |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 1919 | GL_CALL(DrawArrays(gPrimitiveType2GLMode[vertices.primitiveType()], 0, |
| 1920 | vertices.vertexCount())); |
bsalomon@google.com | 74749cd | 2013-01-30 16:12:41 +0000 | [diff] [blame] | 1921 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1922 | #if SWAP_PER_DRAW |
| 1923 | glFlush(); |
commit-bot@chromium.org | 4382330 | 2013-09-25 20:57:51 +0000 | [diff] [blame] | 1924 | #if defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1925 | aglSwapBuffers(aglGetCurrentContext()); |
| 1926 | int set_a_break_pt_here = 9; |
| 1927 | aglSwapBuffers(aglGetCurrentContext()); |
commit-bot@chromium.org | 4382330 | 2013-09-25 20:57:51 +0000 | [diff] [blame] | 1928 | #elif defined(SK_BUILD_FOR_WIN32) |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 1929 | SwapBuf(); |
| 1930 | int set_a_break_pt_here = 9; |
| 1931 | SwapBuf(); |
| 1932 | #endif |
| 1933 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1936 | void GrGLGpu::onStencilPath(const GrPath* path, const StencilPathState& state) { |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 1937 | this->flushColorWrite(false); |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 1938 | this->flushDrawFace(GrPipelineBuilder::kBoth_DrawFace); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1939 | |
| 1940 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(state.fRenderTarget); |
bsalomon | 1f78c0a | 2014-12-17 09:43:13 -0800 | [diff] [blame] | 1941 | SkISize size = SkISize::Make(rt->width(), rt->height()); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1942 | this->glPathRendering()->setProjectionMatrix(*state.fViewMatrix, size, rt->origin()); |
| 1943 | this->flushScissor(*state.fScissor, rt->getViewport(), rt->origin()); |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 1944 | this->flushHWAAState(rt, state.fUseHWAA); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1945 | this->flushRenderTarget(rt, NULL); |
| 1946 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1947 | fPathRendering->stencilPath(path, *state.fStencil); |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 1948 | } |
| 1949 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1950 | void GrGLGpu::onDrawPath(const DrawArgs& args, const GrPath* path, |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 1951 | const GrStencilSettings& stencil) { |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 1952 | if (!this->flushGLState(args)) { |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 1953 | return; |
| 1954 | } |
| 1955 | fPathRendering->drawPath(path, stencil); |
| 1956 | } |
| 1957 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 1958 | void GrGLGpu::onDrawPaths(const DrawArgs& args, |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 1959 | const GrPathRange* pathRange, |
| 1960 | const void* indices, |
| 1961 | GrDrawTarget::PathIndexType indexType, |
| 1962 | const float transformValues[], |
| 1963 | GrDrawTarget::PathTransformType transformType, |
| 1964 | int count, |
| 1965 | const GrStencilSettings& stencil) { |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 1966 | if (!this->flushGLState(args)) { |
bsalomon | d95263c | 2014-12-16 13:05:12 -0800 | [diff] [blame] | 1967 | return; |
| 1968 | } |
| 1969 | fPathRendering->drawPaths(pathRange, indices, indexType, transformValues, |
| 1970 | transformType, count, stencil); |
| 1971 | } |
| 1972 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 1973 | void GrGLGpu::onResolveRenderTarget(GrRenderTarget* target) { |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1974 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(target); |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 1975 | if (rt->needsResolve()) { |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1976 | // Some extensions automatically resolves the texture when it is read. |
| 1977 | if (this->glCaps().usesMSAARenderBuffers()) { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 1978 | SkASSERT(rt->textureFBOID() != rt->renderFBOID()); |
| 1979 | fStats.incRenderTargetBinds(); |
| 1980 | fStats.incRenderTargetBinds(); |
| 1981 | GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID())); |
| 1982 | GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID())); |
| 1983 | // make sure we go through flushRenderTarget() since we've modified |
| 1984 | // the bound DRAW FBO ID. |
| 1985 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1986 | const GrGLIRect& vp = rt->getViewport(); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 1987 | const SkIRect dirtyRect = rt->getResolveRect(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1988 | |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 1989 | if (GrGLCaps::kES_Apple_MSFBOType == this->glCaps().msFBOType()) { |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1990 | // Apple's extension uses the scissor as the blit bounds. |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 1991 | GrScissorState scissorState; |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 1992 | scissorState.set(dirtyRect); |
| 1993 | this->flushScissor(scissorState, vp, rt->origin()); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 1994 | GL_CALL(ResolveMultisampleFramebuffer()); |
| 1995 | } else { |
robertphillips | e85a32d | 2015-02-10 08:16:55 -0800 | [diff] [blame] | 1996 | GrGLIRect r; |
| 1997 | r.setRelativeTo(vp, dirtyRect.fLeft, dirtyRect.fTop, |
| 1998 | dirtyRect.width(), dirtyRect.height(), target->origin()); |
| 1999 | |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 2000 | int right = r.fLeft + r.fWidth; |
| 2001 | int top = r.fBottom + r.fHeight; |
derekf | 8c8f71a | 2014-09-16 06:24:57 -0700 | [diff] [blame] | 2002 | |
| 2003 | // BlitFrameBuffer respects the scissor, so disable it. |
joshualitt | 77b1307 | 2014-10-27 14:51:01 -0700 | [diff] [blame] | 2004 | this->disableScissor(); |
bsalomon@google.com | f3a60c0 | 2013-03-19 19:06:09 +0000 | [diff] [blame] | 2005 | GL_CALL(BlitFramebuffer(r.fLeft, r.fBottom, right, top, |
| 2006 | r.fLeft, r.fBottom, right, top, |
| 2007 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
bsalomon@google.com | a9ecdad | 2011-03-23 13:50:34 +0000 | [diff] [blame] | 2008 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2009 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 2010 | rt->flagAsResolved(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2011 | } |
| 2012 | } |
| 2013 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2014 | namespace { |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2015 | |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2016 | |
| 2017 | GrGLenum gr_to_gl_stencil_op(GrStencilOp op) { |
| 2018 | static const GrGLenum gTable[] = { |
| 2019 | GR_GL_KEEP, // kKeep_StencilOp |
| 2020 | GR_GL_REPLACE, // kReplace_StencilOp |
| 2021 | GR_GL_INCR_WRAP, // kIncWrap_StencilOp |
| 2022 | GR_GL_INCR, // kIncClamp_StencilOp |
| 2023 | GR_GL_DECR_WRAP, // kDecWrap_StencilOp |
| 2024 | GR_GL_DECR, // kDecClamp_StencilOp |
| 2025 | GR_GL_ZERO, // kZero_StencilOp |
| 2026 | GR_GL_INVERT, // kInvert_StencilOp |
| 2027 | }; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 2028 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(gTable) == kStencilOpCount); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2029 | GR_STATIC_ASSERT(0 == kKeep_StencilOp); |
| 2030 | GR_STATIC_ASSERT(1 == kReplace_StencilOp); |
| 2031 | GR_STATIC_ASSERT(2 == kIncWrap_StencilOp); |
| 2032 | GR_STATIC_ASSERT(3 == kIncClamp_StencilOp); |
| 2033 | GR_STATIC_ASSERT(4 == kDecWrap_StencilOp); |
| 2034 | GR_STATIC_ASSERT(5 == kDecClamp_StencilOp); |
| 2035 | GR_STATIC_ASSERT(6 == kZero_StencilOp); |
| 2036 | GR_STATIC_ASSERT(7 == kInvert_StencilOp); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 2037 | SkASSERT((unsigned) op < kStencilOpCount); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2038 | return gTable[op]; |
| 2039 | } |
| 2040 | |
| 2041 | void set_gl_stencil(const GrGLInterface* gl, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2042 | const GrStencilSettings& settings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2043 | GrGLenum glFace, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2044 | GrStencilSettings::Face grFace) { |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 2045 | GrGLenum glFunc = GrToGLStencilFunc(settings.func(grFace)); |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2046 | GrGLenum glFailOp = gr_to_gl_stencil_op(settings.failOp(grFace)); |
| 2047 | GrGLenum glPassOp = gr_to_gl_stencil_op(settings.passOp(grFace)); |
| 2048 | |
| 2049 | GrGLint ref = settings.funcRef(grFace); |
| 2050 | GrGLint mask = settings.funcMask(grFace); |
| 2051 | GrGLint writeMask = settings.writeMask(grFace); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2052 | |
| 2053 | if (GR_GL_FRONT_AND_BACK == glFace) { |
| 2054 | // we call the combined func just in case separate stencil is not |
| 2055 | // supported. |
| 2056 | GR_GL_CALL(gl, StencilFunc(glFunc, ref, mask)); |
| 2057 | GR_GL_CALL(gl, StencilMask(writeMask)); |
| 2058 | GR_GL_CALL(gl, StencilOp(glFailOp, glPassOp, glPassOp)); |
| 2059 | } else { |
| 2060 | GR_GL_CALL(gl, StencilFuncSeparate(glFace, glFunc, ref, mask)); |
| 2061 | GR_GL_CALL(gl, StencilMaskSeparate(glFace, writeMask)); |
| 2062 | GR_GL_CALL(gl, StencilOpSeparate(glFace, glFailOp, glPassOp, glPassOp)); |
| 2063 | } |
| 2064 | } |
| 2065 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2066 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 2067 | void GrGLGpu::flushStencil(const GrStencilSettings& stencilSettings) { |
| 2068 | if (fHWStencilSettings != stencilSettings) { |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 2069 | if (stencilSettings.isDisabled()) { |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 2070 | if (kNo_TriState != fHWStencilTestEnabled) { |
| 2071 | GL_CALL(Disable(GR_GL_STENCIL_TEST)); |
| 2072 | fHWStencilTestEnabled = kNo_TriState; |
| 2073 | } |
| 2074 | } else { |
| 2075 | if (kYes_TriState != fHWStencilTestEnabled) { |
| 2076 | GL_CALL(Enable(GR_GL_STENCIL_TEST)); |
| 2077 | fHWStencilTestEnabled = kYes_TriState; |
| 2078 | } |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2079 | } |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 2080 | if (!stencilSettings.isDisabled()) { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 2081 | if (this->caps()->twoSidedStencilSupport()) { |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2082 | set_gl_stencil(this->glInterface(), |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 2083 | stencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2084 | GR_GL_FRONT, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2085 | GrStencilSettings::kFront_Face); |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2086 | set_gl_stencil(this->glInterface(), |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 2087 | stencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2088 | GR_GL_BACK, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2089 | GrStencilSettings::kBack_Face); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2090 | } else { |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2091 | set_gl_stencil(this->glInterface(), |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 2092 | stencilSettings, |
bsalomon@google.com | 411dad0 | 2012-06-05 20:24:20 +0000 | [diff] [blame] | 2093 | GR_GL_FRONT_AND_BACK, |
bsalomon@google.com | a320194 | 2012-06-21 19:58:20 +0000 | [diff] [blame] | 2094 | GrStencilSettings::kFront_Face); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2095 | } |
| 2096 | } |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 2097 | fHWStencilSettings = stencilSettings; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2098 | } |
| 2099 | } |
| 2100 | |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 2101 | void GrGLGpu::flushHWAAState(GrRenderTarget* rt, bool useHWAA) { |
| 2102 | SkASSERT(!useHWAA || rt->isMultisampled()); |
bsalomon@google.com | 202d139 | 2013-03-19 18:58:08 +0000 | [diff] [blame] | 2103 | |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 2104 | if (kGL_GrGLStandard == this->glStandard()) { |
cdalton | d0a840d | 2015-03-16 17:19:58 -0700 | [diff] [blame] | 2105 | if (useHWAA) { |
| 2106 | if (kYes_TriState != fMSAAEnabled) { |
| 2107 | GL_CALL(Enable(GR_GL_MULTISAMPLE)); |
| 2108 | fMSAAEnabled = kYes_TriState; |
| 2109 | } |
| 2110 | } else { |
| 2111 | if (kNo_TriState != fMSAAEnabled) { |
| 2112 | GL_CALL(Disable(GR_GL_MULTISAMPLE)); |
| 2113 | fMSAAEnabled = kNo_TriState; |
bsalomon@google.com | f954d8d | 2011-04-06 17:50:02 +0000 | [diff] [blame] | 2114 | } |
| 2115 | } |
| 2116 | } |
| 2117 | } |
| 2118 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 2119 | void GrGLGpu::flushBlend(const GrXferProcessor::BlendInfo& blendInfo) { |
egdaniel | b414f25 | 2014-07-29 13:15:47 -0700 | [diff] [blame] | 2120 | // Any optimization to disable blending should have already been applied and |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2121 | // tweaked the equation to "add" or "subtract", and the coeffs to (1, 0). |
bsalomon | f7cc877 | 2015-05-11 11:21:14 -0700 | [diff] [blame] | 2122 | |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2123 | GrBlendEquation equation = blendInfo.fEquation; |
egdaniel | c230414 | 2014-12-11 13:15:13 -0800 | [diff] [blame] | 2124 | GrBlendCoeff srcCoeff = blendInfo.fSrcBlend; |
| 2125 | GrBlendCoeff dstCoeff = blendInfo.fDstBlend; |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2126 | bool blendOff = (kAdd_GrBlendEquation == equation || kSubtract_GrBlendEquation == equation) && |
| 2127 | kOne_GrBlendCoeff == srcCoeff && kZero_GrBlendCoeff == dstCoeff; |
egdaniel | b414f25 | 2014-07-29 13:15:47 -0700 | [diff] [blame] | 2128 | if (blendOff) { |
| 2129 | if (kNo_TriState != fHWBlendState.fEnabled) { |
| 2130 | GL_CALL(Disable(GR_GL_BLEND)); |
| 2131 | fHWBlendState.fEnabled = kNo_TriState; |
| 2132 | } |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | if (kYes_TriState != fHWBlendState.fEnabled) { |
| 2137 | GL_CALL(Enable(GR_GL_BLEND)); |
| 2138 | fHWBlendState.fEnabled = kYes_TriState; |
| 2139 | } |
| 2140 | |
| 2141 | if (fHWBlendState.fEquation != equation) { |
| 2142 | GL_CALL(BlendEquation(gXfermodeEquation2Blend[equation])); |
| 2143 | fHWBlendState.fEquation = equation; |
| 2144 | } |
| 2145 | |
| 2146 | if (GrBlendEquationIsAdvanced(equation)) { |
| 2147 | SkASSERT(this->caps()->advancedBlendEquationSupport()); |
| 2148 | // Advanced equations have no other blend state. |
| 2149 | return; |
| 2150 | } |
| 2151 | |
| 2152 | if (fHWBlendState.fSrcCoeff != srcCoeff || |
| 2153 | fHWBlendState.fDstCoeff != dstCoeff) { |
| 2154 | GL_CALL(BlendFunc(gXfermodeCoeff2Blend[srcCoeff], |
| 2155 | gXfermodeCoeff2Blend[dstCoeff])); |
| 2156 | fHWBlendState.fSrcCoeff = srcCoeff; |
| 2157 | fHWBlendState.fDstCoeff = dstCoeff; |
| 2158 | } |
| 2159 | |
| 2160 | GrColor blendConst = blendInfo.fBlendConstant; |
| 2161 | if ((BlendCoeffReferencesConstant(srcCoeff) || |
| 2162 | BlendCoeffReferencesConstant(dstCoeff)) && |
| 2163 | (!fHWBlendState.fConstColorValid || |
| 2164 | fHWBlendState.fConstColor != blendConst)) { |
| 2165 | GrGLfloat c[4]; |
| 2166 | GrColorToRGBAFloat(blendConst, c); |
| 2167 | GL_CALL(BlendColor(c[0], c[1], c[2], c[3])); |
| 2168 | fHWBlendState.fConstColor = blendConst; |
| 2169 | fHWBlendState.fConstColorValid = true; |
bsalomon@google.com | 0650e81 | 2011-04-08 18:07:53 +0000 | [diff] [blame] | 2170 | } |
| 2171 | } |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 2172 | |
commit-bot@chromium.org | 6364b5e | 2013-08-20 20:22:52 +0000 | [diff] [blame] | 2173 | static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2174 | static const GrGLenum gWrapModes[] = { |
| 2175 | GR_GL_CLAMP_TO_EDGE, |
| 2176 | GR_GL_REPEAT, |
| 2177 | GR_GL_MIRRORED_REPEAT |
| 2178 | }; |
commit-bot@chromium.org | 5d7ca95 | 2013-04-22 20:26:44 +0000 | [diff] [blame] | 2179 | GR_STATIC_ASSERT(SkShader::kTileModeCount == SK_ARRAY_COUNT(gWrapModes)); |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2180 | GR_STATIC_ASSERT(0 == SkShader::kClamp_TileMode); |
| 2181 | GR_STATIC_ASSERT(1 == SkShader::kRepeat_TileMode); |
| 2182 | GR_STATIC_ASSERT(2 == SkShader::kMirror_TileMode); |
| 2183 | return gWrapModes[tm]; |
| 2184 | } |
| 2185 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2186 | void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2187 | SkASSERT(texture); |
tomhudson@google.com | d0c1a06 | 2012-07-12 17:23:52 +0000 | [diff] [blame] | 2188 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2189 | // If we created a rt/tex and rendered to it without using a texture and now we're texturing |
| 2190 | // from the rt it will still be the last bound texture, but it needs resolving. So keep this |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2191 | // out of the "last != next" check. |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 2192 | GrGLRenderTarget* texRT = static_cast<GrGLRenderTarget*>(texture->asRenderTarget()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2193 | if (texRT) { |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2194 | this->onResolveRenderTarget(texRT); |
| 2195 | } |
| 2196 | |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 2197 | uint32_t textureID = texture->getUniqueID(); |
| 2198 | if (fHWBoundTextureUniqueIDs[unitIdx] != textureID) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2199 | this->setTextureUnit(unitIdx); |
| 2200 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, texture->textureID())); |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 2201 | fHWBoundTextureUniqueIDs[unitIdx] = textureID; |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2202 | } |
| 2203 | |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2204 | ResetTimestamp timestamp; |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2205 | const GrGLTexture::TexParams& oldTexParams = texture->getCachedTexParams(×tamp); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2206 | bool setAll = timestamp < this->getResetTimestamp(); |
| 2207 | GrGLTexture::TexParams newTexParams; |
| 2208 | |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 2209 | static GrGLenum glMinFilterModes[] = { |
commit-bot@chromium.org | cffff79 | 2013-07-26 16:36:04 +0000 | [diff] [blame] | 2210 | GR_GL_NEAREST, |
| 2211 | GR_GL_LINEAR, |
| 2212 | GR_GL_LINEAR_MIPMAP_LINEAR |
| 2213 | }; |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 2214 | static GrGLenum glMagFilterModes[] = { |
| 2215 | GR_GL_NEAREST, |
| 2216 | GR_GL_LINEAR, |
| 2217 | GR_GL_LINEAR |
| 2218 | }; |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 2219 | GrTextureParams::FilterMode filterMode = params.filterMode(); |
bsalomon | efd7d45 | 2014-10-23 14:17:46 -0700 | [diff] [blame] | 2220 | |
| 2221 | if (GrTextureParams::kMipMap_FilterMode == filterMode) { |
| 2222 | if (!this->caps()->mipMapSupport() || GrPixelConfigIsCompressed(texture->config())) { |
| 2223 | filterMode = GrTextureParams::kBilerp_FilterMode; |
| 2224 | } |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 2225 | } |
bsalomon | efd7d45 | 2014-10-23 14:17:46 -0700 | [diff] [blame] | 2226 | |
commit-bot@chromium.org | 4744231 | 2013-12-19 16:18:01 +0000 | [diff] [blame] | 2227 | newTexParams.fMinFilter = glMinFilterModes[filterMode]; |
| 2228 | newTexParams.fMagFilter = glMagFilterModes[filterMode]; |
skia.committer@gmail.com | aeefb2a | 2013-07-27 07:01:06 +0000 | [diff] [blame] | 2229 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 2230 | if (GrTextureParams::kMipMap_FilterMode == filterMode && |
bsalomon | efd7d45 | 2014-10-23 14:17:46 -0700 | [diff] [blame] | 2231 | texture->texturePriv().mipMapsAreDirty()) { |
commit-bot@chromium.org | cffff79 | 2013-07-26 16:36:04 +0000 | [diff] [blame] | 2232 | GL_CALL(GenerateMipmap(GR_GL_TEXTURE_2D)); |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 2233 | texture->texturePriv().dirtyMipMaps(false); |
commit-bot@chromium.org | cffff79 | 2013-07-26 16:36:04 +0000 | [diff] [blame] | 2234 | } |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2235 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 2236 | newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); |
| 2237 | newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2238 | memcpy(newTexParams.fSwizzleRGBA, |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2239 | GrGLShaderBuilder::GetTexParamSwizzle(texture->config(), this->glCaps()), |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2240 | sizeof(newTexParams.fSwizzleRGBA)); |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 2241 | if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2242 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2243 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2244 | GR_GL_TEXTURE_MAG_FILTER, |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 2245 | newTexParams.fMagFilter)); |
| 2246 | } |
| 2247 | if (setAll || newTexParams.fMinFilter != oldTexParams.fMinFilter) { |
| 2248 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2249 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2250 | GR_GL_TEXTURE_MIN_FILTER, |
commit-bot@chromium.org | 149f4f5 | 2013-07-26 20:40:06 +0000 | [diff] [blame] | 2251 | newTexParams.fMinFilter)); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2252 | } |
| 2253 | if (setAll || newTexParams.fWrapS != oldTexParams.fWrapS) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2254 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2255 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2256 | GR_GL_TEXTURE_WRAP_S, |
| 2257 | newTexParams.fWrapS)); |
| 2258 | } |
| 2259 | if (setAll || newTexParams.fWrapT != oldTexParams.fWrapT) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2260 | this->setTextureUnit(unitIdx); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2261 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, |
| 2262 | GR_GL_TEXTURE_WRAP_T, |
| 2263 | newTexParams.fWrapT)); |
| 2264 | } |
| 2265 | if (this->glCaps().textureSwizzleSupport() && |
| 2266 | (setAll || memcmp(newTexParams.fSwizzleRGBA, |
| 2267 | oldTexParams.fSwizzleRGBA, |
| 2268 | sizeof(newTexParams.fSwizzleRGBA)))) { |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2269 | this->setTextureUnit(unitIdx); |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 2270 | if (this->glStandard() == kGLES_GrGLStandard) { |
commit-bot@chromium.org | 6364b5e | 2013-08-20 20:22:52 +0000 | [diff] [blame] | 2271 | // ES3 added swizzle support but not GL_TEXTURE_SWIZZLE_RGBA. |
| 2272 | const GrGLenum* swizzle = newTexParams.fSwizzleRGBA; |
| 2273 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_R, swizzle[0])); |
| 2274 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_G, swizzle[1])); |
| 2275 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_B, swizzle[2])); |
| 2276 | GL_CALL(TexParameteri(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_A, swizzle[3])); |
| 2277 | } else { |
| 2278 | GR_STATIC_ASSERT(sizeof(newTexParams.fSwizzleRGBA[0]) == sizeof(GrGLint)); |
| 2279 | const GrGLint* swizzle = reinterpret_cast<const GrGLint*>(newTexParams.fSwizzleRGBA); |
| 2280 | GL_CALL(TexParameteriv(GR_GL_TEXTURE_2D, GR_GL_TEXTURE_SWIZZLE_RGBA, swizzle)); |
| 2281 | } |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2282 | } |
bsalomon@google.com | 34cccde | 2013-01-04 18:34:30 +0000 | [diff] [blame] | 2283 | texture->setCachedTexParams(newTexParams, this->getResetTimestamp()); |
bsalomon@google.com | 4c88378 | 2012-06-04 19:05:11 +0000 | [diff] [blame] | 2284 | } |
| 2285 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 2286 | void GrGLGpu::flushDither(bool dither) { |
| 2287 | if (dither) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2288 | if (kYes_TriState != fHWDitherEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2289 | GL_CALL(Enable(GR_GL_DITHER)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2290 | fHWDitherEnabled = kYes_TriState; |
| 2291 | } |
| 2292 | } else { |
| 2293 | if (kNo_TriState != fHWDitherEnabled) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2294 | GL_CALL(Disable(GR_GL_DITHER)); |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2295 | fHWDitherEnabled = kNo_TriState; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2296 | } |
| 2297 | } |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 2298 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2299 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 2300 | void GrGLGpu::flushColorWrite(bool writeColor) { |
| 2301 | if (!writeColor) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2302 | if (kNo_TriState != fHWWriteToColor) { |
| 2303 | GL_CALL(ColorMask(GR_GL_FALSE, GR_GL_FALSE, |
| 2304 | GR_GL_FALSE, GR_GL_FALSE)); |
| 2305 | fHWWriteToColor = kNo_TriState; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2306 | } |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 2307 | } else { |
| 2308 | if (kYes_TriState != fHWWriteToColor) { |
| 2309 | GL_CALL(ColorMask(GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE, GR_GL_TRUE)); |
| 2310 | fHWWriteToColor = kYes_TriState; |
| 2311 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2312 | } |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 2313 | } |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2314 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2315 | void GrGLGpu::flushDrawFace(GrPipelineBuilder::DrawFace face) { |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 2316 | if (fHWDrawFace != face) { |
| 2317 | switch (face) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2318 | case GrPipelineBuilder::kCCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2319 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2320 | GL_CALL(CullFace(GR_GL_BACK)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2321 | break; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2322 | case GrPipelineBuilder::kCW_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2323 | GL_CALL(Enable(GR_GL_CULL_FACE)); |
| 2324 | GL_CALL(CullFace(GR_GL_FRONT)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2325 | break; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2326 | case GrPipelineBuilder::kBoth_DrawFace: |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2327 | GL_CALL(Disable(GR_GL_CULL_FACE)); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2328 | break; |
| 2329 | default: |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 2330 | SkFAIL("Unknown draw face."); |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2331 | } |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 2332 | fHWDrawFace = face; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 2333 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2336 | bool GrGLGpu::configToGLFormats(GrPixelConfig config, |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2337 | bool getSizedInternalFormat, |
| 2338 | GrGLenum* internalFormat, |
| 2339 | GrGLenum* externalFormat, |
| 2340 | GrGLenum* externalType) { |
| 2341 | GrGLenum dontCare; |
| 2342 | if (NULL == internalFormat) { |
| 2343 | internalFormat = &dontCare; |
| 2344 | } |
| 2345 | if (NULL == externalFormat) { |
| 2346 | externalFormat = &dontCare; |
| 2347 | } |
| 2348 | if (NULL == externalType) { |
| 2349 | externalType = &dontCare; |
| 2350 | } |
| 2351 | |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 2352 | if(!this->glCaps().isConfigTexturable(config)) { |
| 2353 | return false; |
| 2354 | } |
| 2355 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2356 | switch (config) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 2357 | case kRGBA_8888_GrPixelConfig: |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2358 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2359 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2360 | if (getSizedInternalFormat) { |
| 2361 | *internalFormat = GR_GL_RGBA8; |
| 2362 | } else { |
| 2363 | *internalFormat = GR_GL_RGBA; |
| 2364 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2365 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 2366 | break; |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 2367 | case kBGRA_8888_GrPixelConfig: |
bsalomon@google.com | f7fa806 | 2012-02-14 14:09:57 +0000 | [diff] [blame] | 2368 | if (this->glCaps().bgraIsInternalFormat()) { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2369 | if (getSizedInternalFormat) { |
| 2370 | *internalFormat = GR_GL_BGRA8; |
| 2371 | } else { |
| 2372 | *internalFormat = GR_GL_BGRA; |
| 2373 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2374 | } else { |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2375 | if (getSizedInternalFormat) { |
| 2376 | *internalFormat = GR_GL_RGBA8; |
| 2377 | } else { |
| 2378 | *internalFormat = GR_GL_RGBA; |
| 2379 | } |
twiz@google.com | b65e0cb | 2011-03-18 20:41:44 +0000 | [diff] [blame] | 2380 | } |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2381 | *externalFormat = GR_GL_BGRA; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2382 | *externalType = GR_GL_UNSIGNED_BYTE; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2383 | break; |
jvanverth | fa1e8a7 | 2014-12-22 08:31:49 -0800 | [diff] [blame] | 2384 | case kSRGBA_8888_GrPixelConfig: |
| 2385 | *internalFormat = GR_GL_SRGB_ALPHA; |
| 2386 | *externalFormat = GR_GL_SRGB_ALPHA; |
| 2387 | if (getSizedInternalFormat) { |
| 2388 | *internalFormat = GR_GL_SRGB8_ALPHA8; |
| 2389 | } else { |
| 2390 | *internalFormat = GR_GL_SRGB_ALPHA; |
| 2391 | } |
| 2392 | *externalType = GR_GL_UNSIGNED_BYTE; |
| 2393 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2394 | case kRGB_565_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2395 | *internalFormat = GR_GL_RGB; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2396 | *externalFormat = GR_GL_RGB; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2397 | if (getSizedInternalFormat) { |
jvanverth | 3f801cb | 2014-12-16 09:49:38 -0800 | [diff] [blame] | 2398 | if (!this->glCaps().ES2CompatibilitySupport()) { |
| 2399 | *internalFormat = GR_GL_RGB5; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2400 | } else { |
| 2401 | *internalFormat = GR_GL_RGB565; |
| 2402 | } |
| 2403 | } else { |
| 2404 | *internalFormat = GR_GL_RGB; |
| 2405 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2406 | *externalType = GR_GL_UNSIGNED_SHORT_5_6_5; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2407 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2408 | case kRGBA_4444_GrPixelConfig: |
twiz@google.com | 0f31ca7 | 2011-03-18 17:38:11 +0000 | [diff] [blame] | 2409 | *internalFormat = GR_GL_RGBA; |
bsalomon@google.com | 32e4d2a | 2011-12-09 16:14:25 +0000 | [diff] [blame] | 2410 | *externalFormat = GR_GL_RGBA; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2411 | if (getSizedInternalFormat) { |
| 2412 | *internalFormat = GR_GL_RGBA4; |
| 2413 | } else { |
| 2414 | *internalFormat = GR_GL_RGBA; |
| 2415 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 2416 | *externalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2417 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2418 | case kIndex_8_GrPixelConfig: |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 2419 | // no sized/unsized internal format distinction here |
| 2420 | *internalFormat = GR_GL_PALETTE8_RGBA8; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2421 | break; |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 2422 | case kAlpha_8_GrPixelConfig: |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 2423 | if (this->glCaps().textureRedSupport()) { |
| 2424 | *internalFormat = GR_GL_RED; |
| 2425 | *externalFormat = GR_GL_RED; |
| 2426 | if (getSizedInternalFormat) { |
| 2427 | *internalFormat = GR_GL_R8; |
| 2428 | } else { |
| 2429 | *internalFormat = GR_GL_RED; |
| 2430 | } |
| 2431 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2432 | } else { |
| 2433 | *internalFormat = GR_GL_ALPHA; |
robertphillips@google.com | 443e5a5 | 2012-04-30 20:01:21 +0000 | [diff] [blame] | 2434 | *externalFormat = GR_GL_ALPHA; |
| 2435 | if (getSizedInternalFormat) { |
| 2436 | *internalFormat = GR_GL_ALPHA8; |
| 2437 | } else { |
| 2438 | *internalFormat = GR_GL_ALPHA; |
| 2439 | } |
| 2440 | *externalType = GR_GL_UNSIGNED_BYTE; |
bsalomon@google.com | 280e99f | 2012-01-05 16:17:38 +0000 | [diff] [blame] | 2441 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2442 | break; |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 2443 | case kETC1_GrPixelConfig: |
egdaniel | d588c01 | 2015-03-27 12:22:10 -0700 | [diff] [blame] | 2444 | *internalFormat = GR_GL_COMPRESSED_ETC1_RGB8; |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 2445 | break; |
| 2446 | case kLATC_GrPixelConfig: |
| 2447 | switch(this->glCaps().latcAlias()) { |
| 2448 | case GrGLCaps::kLATC_LATCAlias: |
| 2449 | *internalFormat = GR_GL_COMPRESSED_LUMINANCE_LATC1; |
| 2450 | break; |
| 2451 | case GrGLCaps::kRGTC_LATCAlias: |
| 2452 | *internalFormat = GR_GL_COMPRESSED_RED_RGTC1; |
| 2453 | break; |
| 2454 | case GrGLCaps::k3DC_LATCAlias: |
| 2455 | *internalFormat = GR_GL_COMPRESSED_3DC_X; |
| 2456 | break; |
| 2457 | } |
| 2458 | break; |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 2459 | case kR11_EAC_GrPixelConfig: |
egdaniel | d588c01 | 2015-03-27 12:22:10 -0700 | [diff] [blame] | 2460 | *internalFormat = GR_GL_COMPRESSED_R11_EAC; |
krajcevski | 238b456 | 2014-06-30 09:09:22 -0700 | [diff] [blame] | 2461 | break; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 2462 | |
| 2463 | case kASTC_12x12_GrPixelConfig: |
egdaniel | d588c01 | 2015-03-27 12:22:10 -0700 | [diff] [blame] | 2464 | *internalFormat = GR_GL_COMPRESSED_RGBA_ASTC_12x12_KHR; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 2465 | break; |
| 2466 | |
joshualitt | ee5da55 | 2014-07-16 13:32:56 -0700 | [diff] [blame] | 2467 | case kRGBA_float_GrPixelConfig: |
| 2468 | *internalFormat = GR_GL_RGBA32F; |
| 2469 | *externalFormat = GR_GL_RGBA; |
| 2470 | *externalType = GR_GL_FLOAT; |
| 2471 | break; |
krajcevski | 7ef2162 | 2014-07-16 15:21:13 -0700 | [diff] [blame] | 2472 | |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 2473 | case kAlpha_half_GrPixelConfig: |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 2474 | if (this->glCaps().textureRedSupport()) { |
| 2475 | if (getSizedInternalFormat) { |
| 2476 | *internalFormat = GR_GL_R16F; |
| 2477 | } else { |
| 2478 | *internalFormat = GR_GL_RED; |
| 2479 | } |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 2480 | *externalFormat = GR_GL_RED; |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 2481 | } else { |
| 2482 | if (getSizedInternalFormat) { |
| 2483 | *internalFormat = GR_GL_ALPHA16F; |
| 2484 | } else { |
| 2485 | *internalFormat = GR_GL_ALPHA; |
| 2486 | } |
| 2487 | *externalFormat = GR_GL_ALPHA; |
| 2488 | } |
| 2489 | if (kGL_GrGLStandard == this->glStandard() || this->glVersion() >= GR_GL_VER(3, 0)) { |
jvanverth | a60b2ea | 2014-12-12 05:58:06 -0800 | [diff] [blame] | 2490 | *externalType = GR_GL_HALF_FLOAT; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 2491 | } else { |
jvanverth | 1334c21 | 2014-12-18 05:44:55 -0800 | [diff] [blame] | 2492 | *externalType = GR_GL_HALF_FLOAT_OES; |
jvanverth | 28f9c60 | 2014-12-05 13:06:35 -0800 | [diff] [blame] | 2493 | } |
| 2494 | break; |
| 2495 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2496 | default: |
| 2497 | return false; |
| 2498 | } |
| 2499 | return true; |
| 2500 | } |
| 2501 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2502 | void GrGLGpu::setTextureUnit(int unit) { |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 2503 | SkASSERT(unit >= 0 && unit < fHWBoundTextureUniqueIDs.count()); |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2504 | if (unit != fHWActiveTextureUnitIdx) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 2505 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + unit)); |
bsalomon@google.com | 4920939 | 2012-06-05 15:13:46 +0000 | [diff] [blame] | 2506 | fHWActiveTextureUnitIdx = unit; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2507 | } |
| 2508 | } |
bsalomon@google.com | 316f9923 | 2011-01-13 21:28:12 +0000 | [diff] [blame] | 2509 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2510 | void GrGLGpu::setScratchTextureUnit() { |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2511 | // Bind the last texture unit since it is the least likely to be used by GrGLProgram. |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 2512 | int lastUnitIdx = fHWBoundTextureUniqueIDs.count() - 1; |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2513 | if (lastUnitIdx != fHWActiveTextureUnitIdx) { |
| 2514 | GL_CALL(ActiveTexture(GR_GL_TEXTURE0 + lastUnitIdx)); |
| 2515 | fHWActiveTextureUnitIdx = lastUnitIdx; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2516 | } |
commit-bot@chromium.org | a15f7e5 | 2013-06-05 23:29:25 +0000 | [diff] [blame] | 2517 | // clear out the this field so that if a program does use this unit it will rebind the correct |
| 2518 | // texture. |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 2519 | fHWBoundTextureUniqueIDs[lastUnitIdx] = SK_InvalidUniqueID; |
bsalomon@google.com | 8531c1c | 2011-01-13 19:52:45 +0000 | [diff] [blame] | 2520 | } |
| 2521 | |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2522 | namespace { |
| 2523 | // Determines whether glBlitFramebuffer could be used between src and dst. |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2524 | inline bool can_blit_framebuffer(const GrSurface* dst, |
| 2525 | const GrSurface* src, |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2526 | const GrGLGpu* gpu) { |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 2527 | if (gpu->glCaps().isConfigRenderable(dst->config(), dst->desc().fSampleCnt > 0) && |
| 2528 | gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) && |
bsalomon@google.com | 347c382 | 2013-05-01 20:10:01 +0000 | [diff] [blame] | 2529 | gpu->glCaps().usesMSAARenderBuffers()) { |
commit-bot@chromium.org | a8e5a06 | 2013-09-05 23:44:09 +0000 | [diff] [blame] | 2530 | // ES3 doesn't allow framebuffer blits when the src has MSAA and the configs don't match |
| 2531 | // or the rects are not the same (not just the same size but have the same edges). |
| 2532 | if (GrGLCaps::kES_3_0_MSFBOType == gpu->glCaps().msFBOType() && |
| 2533 | (src->desc().fSampleCnt > 0 || src->config() != dst->config())) { |
| 2534 | return false; |
| 2535 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2536 | return true; |
| 2537 | } else { |
| 2538 | return false; |
| 2539 | } |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2540 | } |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2541 | |
| 2542 | inline bool can_copy_texsubimage(const GrSurface* dst, |
| 2543 | const GrSurface* src, |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2544 | const GrGLGpu* gpu) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2545 | // Table 3.9 of the ES2 spec indicates the supported formats with CopyTexSubImage |
| 2546 | // and BGRA isn't in the spec. There doesn't appear to be any extension that adds it. Perhaps |
| 2547 | // many drivers would allow it to work, but ANGLE does not. |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 2548 | if (kGLES_GrGLStandard == gpu->glStandard() && gpu->glCaps().bgraIsInternalFormat() && |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2549 | (kBGRA_8888_GrPixelConfig == dst->config() || kBGRA_8888_GrPixelConfig == src->config())) { |
| 2550 | return false; |
| 2551 | } |
| 2552 | const GrGLRenderTarget* dstRT = static_cast<const GrGLRenderTarget*>(dst->asRenderTarget()); |
| 2553 | // If dst is multisampled (and uses an extension where there is a separate MSAA renderbuffer) |
| 2554 | // then we don't want to copy to the texture but to the MSAA buffer. |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2555 | if (dstRT && dstRT->renderFBOID() != dstRT->textureFBOID()) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2556 | return false; |
| 2557 | } |
bsalomon@google.com | a271985 | 2013-04-17 14:25:27 +0000 | [diff] [blame] | 2558 | const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->asRenderTarget()); |
| 2559 | // If the src is multisampled (and uses an extension where there is a separate MSAA |
| 2560 | // renderbuffer) then it is an invalid operation to call CopyTexSubImage |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2561 | if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
bsalomon@google.com | a271985 | 2013-04-17 14:25:27 +0000 | [diff] [blame] | 2562 | return false; |
| 2563 | } |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 2564 | if (gpu->glCaps().isConfigRenderable(src->config(), src->desc().fSampleCnt > 0) && |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2565 | dst->asTexture() && |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 2566 | dst->origin() == src->origin() && |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 2567 | !GrPixelConfigIsCompressed(src->config())) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2568 | return true; |
| 2569 | } else { |
| 2570 | return false; |
| 2571 | } |
| 2572 | } |
| 2573 | |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2576 | // If a temporary FBO was created, its non-zero ID is returned. The viewport that the copy rect is |
| 2577 | // relative to is output. |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2578 | GrGLuint GrGLGpu::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport, |
| 2579 | TempFBOTarget tempFBOTarget) { |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2580 | GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarget()); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2581 | if (NULL == rt) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2582 | SkASSERT(surface->asTexture()); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2583 | GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textureID(); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2584 | GrGLuint* tempFBOID; |
| 2585 | tempFBOID = kSrc_TempFBOTarget == tempFBOTarget ? &fTempSrcFBOID : &fTempDstFBOID; |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2586 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2587 | if (0 == *tempFBOID) { |
| 2588 | GR_GL_CALL(this->glInterface(), GenFramebuffers(1, tempFBOID)); |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2589 | } |
| 2590 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2591 | fStats.incRenderTargetBinds(); |
| 2592 | GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, *tempFBOID)); |
| 2593 | GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 2594 | GR_GL_COLOR_ATTACHMENT0, |
| 2595 | GR_GL_TEXTURE_2D, |
| 2596 | texID, |
| 2597 | 0)); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2598 | viewport->fLeft = 0; |
| 2599 | viewport->fBottom = 0; |
| 2600 | viewport->fWidth = surface->width(); |
| 2601 | viewport->fHeight = surface->height(); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2602 | return *tempFBOID; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2603 | } else { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2604 | GrGLuint tempFBOID = 0; |
| 2605 | fStats.incRenderTargetBinds(); |
| 2606 | GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBOID())); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2607 | *viewport = rt->getViewport(); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2608 | return tempFBOID; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2609 | } |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2610 | } |
| 2611 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2612 | void GrGLGpu::unbindTextureFromFBO(GrGLenum fboTarget) { |
| 2613 | GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget, |
egdaniel | 0f5f967 | 2015-02-03 11:10:51 -0800 | [diff] [blame] | 2614 | GR_GL_COLOR_ATTACHMENT0, |
| 2615 | GR_GL_TEXTURE_2D, |
| 2616 | 0, |
| 2617 | 0)); |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2620 | bool GrGLGpu::initCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) { |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2621 | // In here we look for opportunities to use CopyTexSubImage, or fbo blit. If neither are |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 2622 | // possible and we return false to fallback to creating a render target dst for render-to- |
| 2623 | // texture. This code prefers CopyTexSubImage to fbo blit and avoids triggering temporary fbo |
| 2624 | // creation. It isn't clear that avoiding temporary fbo creation is actually optimal. |
| 2625 | |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2626 | // Check for format issues with glCopyTexSubImage2D |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 2627 | if (kGLES_GrGLStandard == this->glStandard() && this->glCaps().bgraIsInternalFormat() && |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2628 | kBGRA_8888_GrPixelConfig == src->config()) { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 2629 | // glCopyTexSubImage2D doesn't work with this config. If the bgra can be used with fbo blit |
| 2630 | // then we set up for that, otherwise fail. |
| 2631 | if (this->caps()->isConfigRenderable(kBGRA_8888_GrPixelConfig, false)) { |
| 2632 | desc->fOrigin = kDefault_GrSurfaceOrigin; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 2633 | desc->fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 2634 | desc->fConfig = kBGRA_8888_GrPixelConfig; |
| 2635 | return true; |
| 2636 | } |
| 2637 | return false; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2638 | } else if (NULL == src->asRenderTarget()) { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 2639 | // CopyTexSubImage2D or fbo blit would require creating a temp fbo for the src. |
| 2640 | return false; |
bsalomon@google.com | a271985 | 2013-04-17 14:25:27 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | const GrGLRenderTarget* srcRT = static_cast<const GrGLRenderTarget*>(src->asRenderTarget()); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 2644 | if (srcRT && srcRT->renderFBOID() != srcRT->textureFBOID()) { |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 2645 | // It's illegal to call CopyTexSubImage2D on a MSAA renderbuffer. Set up for FBO blit or |
| 2646 | // fail. |
| 2647 | if (this->caps()->isConfigRenderable(src->config(), false)) { |
| 2648 | desc->fOrigin = kDefault_GrSurfaceOrigin; |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 2649 | desc->fFlags = kRenderTarget_GrSurfaceFlag; |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 2650 | desc->fConfig = src->config(); |
| 2651 | return true; |
| 2652 | } |
| 2653 | return false; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 2654 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 2655 | |
| 2656 | // We'll do a CopyTexSubImage. Make the dst a plain old texture. |
| 2657 | desc->fConfig = src->config(); |
| 2658 | desc->fOrigin = src->origin(); |
| 2659 | desc->fFlags = kNone_GrSurfaceFlags; |
| 2660 | return true; |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2661 | } |
| 2662 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2663 | bool GrGLGpu::copySurface(GrSurface* dst, |
joshualitt | a702415 | 2014-11-03 14:16:35 -0800 | [diff] [blame] | 2664 | GrSurface* src, |
| 2665 | const SkIRect& srcRect, |
| 2666 | const SkIPoint& dstPoint) { |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2667 | bool copied = false; |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2668 | if (can_copy_texsubimage(dst, src, this)) { |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2669 | GrGLuint srcFBO; |
| 2670 | GrGLIRect srcVP; |
| 2671 | srcFBO = this->bindSurfaceAsFBO(src, GR_GL_FRAMEBUFFER, &srcVP, kSrc_TempFBOTarget); |
| 2672 | GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture()); |
| 2673 | SkASSERT(dstTex); |
| 2674 | // We modified the bound FBO |
| 2675 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 2676 | GrGLIRect srcGLRect; |
| 2677 | srcGLRect.setRelativeTo(srcVP, |
| 2678 | srcRect.fLeft, |
| 2679 | srcRect.fTop, |
| 2680 | srcRect.width(), |
| 2681 | srcRect.height(), |
| 2682 | src->origin()); |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2683 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2684 | this->setScratchTextureUnit(); |
| 2685 | GL_CALL(BindTexture(GR_GL_TEXTURE_2D, dstTex->textureID())); |
| 2686 | GrGLint dstY; |
| 2687 | if (kBottomLeft_GrSurfaceOrigin == dst->origin()) { |
| 2688 | dstY = dst->height() - (dstPoint.fY + srcGLRect.fHeight); |
| 2689 | } else { |
| 2690 | dstY = dstPoint.fY; |
| 2691 | } |
| 2692 | GL_CALL(CopyTexSubImage2D(GR_GL_TEXTURE_2D, 0, |
| 2693 | dstPoint.fX, dstY, |
| 2694 | srcGLRect.fLeft, srcGLRect.fBottom, |
| 2695 | srcGLRect.fWidth, srcGLRect.fHeight)); |
| 2696 | copied = true; |
| 2697 | if (srcFBO) { |
| 2698 | this->unbindTextureFromFBO(GR_GL_FRAMEBUFFER); |
| 2699 | } |
| 2700 | } else if (can_blit_framebuffer(dst, src, this)) { |
| 2701 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 2702 | srcRect.width(), srcRect.height()); |
| 2703 | bool selfOverlap = false; |
| 2704 | if (dst == src) { |
| 2705 | selfOverlap = SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect); |
| 2706 | } |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2707 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2708 | if (!selfOverlap) { |
| 2709 | GrGLuint dstFBO; |
| 2710 | GrGLuint srcFBO; |
| 2711 | GrGLIRect dstVP; |
| 2712 | GrGLIRect srcVP; |
| 2713 | dstFBO = this->bindSurfaceAsFBO(dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP, |
| 2714 | kDst_TempFBOTarget); |
| 2715 | srcFBO = this->bindSurfaceAsFBO(src, GR_GL_READ_FRAMEBUFFER, &srcVP, |
| 2716 | kSrc_TempFBOTarget); |
| 2717 | // We modified the bound FBO |
| 2718 | fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID; |
| 2719 | GrGLIRect srcGLRect; |
| 2720 | GrGLIRect dstGLRect; |
| 2721 | srcGLRect.setRelativeTo(srcVP, |
| 2722 | srcRect.fLeft, |
| 2723 | srcRect.fTop, |
| 2724 | srcRect.width(), |
| 2725 | srcRect.height(), |
| 2726 | src->origin()); |
| 2727 | dstGLRect.setRelativeTo(dstVP, |
| 2728 | dstRect.fLeft, |
| 2729 | dstRect.fTop, |
| 2730 | dstRect.width(), |
| 2731 | dstRect.height(), |
| 2732 | dst->origin()); |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2733 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2734 | // BlitFrameBuffer respects the scissor, so disable it. |
| 2735 | this->disableScissor(); |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2736 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2737 | GrGLint srcY0; |
| 2738 | GrGLint srcY1; |
| 2739 | // Does the blit need to y-mirror or not? |
| 2740 | if (src->origin() == dst->origin()) { |
| 2741 | srcY0 = srcGLRect.fBottom; |
| 2742 | srcY1 = srcGLRect.fBottom + srcGLRect.fHeight; |
| 2743 | } else { |
| 2744 | srcY0 = srcGLRect.fBottom + srcGLRect.fHeight; |
| 2745 | srcY1 = srcGLRect.fBottom; |
| 2746 | } |
| 2747 | GL_CALL(BlitFramebuffer(srcGLRect.fLeft, |
| 2748 | srcY0, |
| 2749 | srcGLRect.fLeft + srcGLRect.fWidth, |
| 2750 | srcY1, |
| 2751 | dstGLRect.fLeft, |
| 2752 | dstGLRect.fBottom, |
| 2753 | dstGLRect.fLeft + dstGLRect.fWidth, |
| 2754 | dstGLRect.fBottom + dstGLRect.fHeight, |
| 2755 | GR_GL_COLOR_BUFFER_BIT, GR_GL_NEAREST)); |
| 2756 | if (dstFBO) { |
| 2757 | this->unbindTextureFromFBO(GR_GL_DRAW_FRAMEBUFFER); |
| 2758 | } |
| 2759 | if (srcFBO) { |
| 2760 | this->unbindTextureFromFBO(GR_GL_READ_FRAMEBUFFER); |
| 2761 | } |
| 2762 | copied = true; |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2763 | } |
| 2764 | } |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2765 | return copied; |
| 2766 | } |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2767 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2768 | bool GrGLGpu::canCopySurface(const GrSurface* dst, |
| 2769 | const GrSurface* src, |
| 2770 | const SkIRect& srcRect, |
| 2771 | const SkIPoint& dstPoint) { |
| 2772 | // This mirrors the logic in onCopySurface. |
| 2773 | if (can_copy_texsubimage(dst, src, this)) { |
| 2774 | return true; |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2775 | } |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2776 | if (can_blit_framebuffer(dst, src, this)) { |
| 2777 | if (dst == src) { |
| 2778 | SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY, |
| 2779 | srcRect.width(), srcRect.height()); |
| 2780 | if(!SkIRect::IntersectsNoEmptyCheck(dstRect, srcRect)) { |
| 2781 | return true; |
| 2782 | } |
| 2783 | } else { |
| 2784 | return true; |
| 2785 | } |
bsalomon | 5df6fee | 2015-05-18 06:26:15 -0700 | [diff] [blame] | 2786 | } |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2787 | return false; |
commit-bot@chromium.org | 63150af | 2013-04-11 22:00:22 +0000 | [diff] [blame] | 2788 | } |
| 2789 | |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 2790 | void GrGLGpu::xferBarrier(GrRenderTarget* rt, GrXferBarrierType type) { |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 2791 | switch (type) { |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 2792 | case kTexture_GrXferBarrierType: { |
| 2793 | GrGLRenderTarget* glrt = static_cast<GrGLRenderTarget*>(rt); |
| 2794 | if (glrt->textureFBOID() != glrt->renderFBOID()) { |
| 2795 | // The render target uses separate storage so no need for glTextureBarrier. |
| 2796 | // FIXME: The render target will resolve automatically when its texture is bound, |
| 2797 | // but we could resolve only the bounds that will be read if we do it here instead. |
| 2798 | return; |
| 2799 | } |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 2800 | SkASSERT(this->caps()->textureBarrierSupport()); |
| 2801 | GL_CALL(TextureBarrier()); |
| 2802 | return; |
cdalton | 231c5fd | 2015-05-13 12:35:36 -0700 | [diff] [blame] | 2803 | } |
cdalton | 8917d62 | 2015-05-06 13:40:21 -0700 | [diff] [blame] | 2804 | case kBlend_GrXferBarrierType: |
| 2805 | SkASSERT(GrDrawTargetCaps::kAdvanced_BlendEquationSupport == |
| 2806 | this->caps()->blendEquationSupport()); |
| 2807 | GL_CALL(BlendBarrier()); |
| 2808 | return; |
cdalton | 9954bc3 | 2015-04-29 14:17:00 -0700 | [diff] [blame] | 2809 | } |
| 2810 | } |
| 2811 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2812 | void GrGLGpu::didAddGpuTraceMarker() { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 2813 | if (this->caps()->gpuTracingSupport()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 2814 | const GrTraceMarkerSet& markerArray = this->getActiveTraceMarkers(); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 2815 | SkString markerString = markerArray.toStringLast(); |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 2816 | #if GR_FORCE_GPU_TRACE_DEBUGGING |
| 2817 | SkDebugf("%s\n", markerString.c_str()); |
| 2818 | #else |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 2819 | GL_CALL(PushGroupMarker(0, markerString.c_str())); |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 2820 | #endif |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 2821 | } |
| 2822 | } |
| 2823 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2824 | void GrGLGpu::didRemoveGpuTraceMarker() { |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 2825 | if (this->caps()->gpuTracingSupport()) { |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 2826 | #if GR_FORCE_GPU_TRACE_DEBUGGING |
| 2827 | SkDebugf("Pop trace marker.\n"); |
| 2828 | #else |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 2829 | GL_CALL(PopGroupMarker()); |
egdaniel | bdad9c3 | 2015-03-05 12:19:17 -0800 | [diff] [blame] | 2830 | #endif |
commit-bot@chromium.org | a3baf3b | 2014-02-21 18:45:30 +0000 | [diff] [blame] | 2831 | } |
| 2832 | } |
joshualitt | 79f8fae | 2014-10-28 17:59:26 -0700 | [diff] [blame] | 2833 | |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2834 | /////////////////////////////////////////////////////////////////////////////// |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2835 | |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 2836 | GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw( |
| 2837 | GrGLGpu* gpu, |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2838 | const GrGLVertexBuffer* vbuffer, |
| 2839 | const GrGLIndexBuffer* ibuffer) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 2840 | SkASSERT(vbuffer); |
robertphillips@google.com | 4f65a27 | 2013-03-26 19:40:46 +0000 | [diff] [blame] | 2841 | GrGLAttribArrayState* attribState; |
| 2842 | |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2843 | // We use a vertex array if we're on a core profile and the verts are in a VBO. |
| 2844 | if (gpu->glCaps().isCoreProfile() && !vbuffer->isCPUBacked()) { |
bsalomon | 8780bc6 | 2015-05-13 09:56:37 -0700 | [diff] [blame] | 2845 | if (!fVBOVertexArray) { |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2846 | GrGLuint arrayID; |
| 2847 | GR_GL_CALL(gpu->glInterface(), GenVertexArrays(1, &arrayID)); |
| 2848 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
bsalomon | 8780bc6 | 2015-05-13 09:56:37 -0700 | [diff] [blame] | 2849 | fVBOVertexArray = SkNEW_ARGS(GrGLVertexArray, (arrayID, attrCount)); |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2850 | } |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2851 | attribState = fVBOVertexArray->bindWithIndexBuffer(gpu, ibuffer); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2852 | } else { |
mtklein | 404b3b2 | 2015-05-18 09:29:10 -0700 | [diff] [blame^] | 2853 | if (ibuffer) { |
| 2854 | this->setIndexBufferIDOnDefaultVertexArray(gpu, ibuffer->bufferID()); |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2855 | } else { |
| 2856 | this->setVertexArrayID(gpu, 0); |
| 2857 | } |
| 2858 | int attrCount = gpu->glCaps().maxVertexAttributes(); |
| 2859 | if (fDefaultVertexArrayAttribState.count() != attrCount) { |
| 2860 | fDefaultVertexArrayAttribState.resize(attrCount); |
| 2861 | } |
| 2862 | attribState = &fDefaultVertexArrayAttribState; |
bsalomon@google.com | 880b8fc | 2013-02-19 20:17:28 +0000 | [diff] [blame] | 2863 | } |
bsalomon@google.com | 6918d48 | 2013-03-07 19:09:11 +0000 | [diff] [blame] | 2864 | return attribState; |
bsalomon@google.com | 7acdb8e | 2011-02-11 14:07:02 +0000 | [diff] [blame] | 2865 | } |