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