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