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