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