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