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