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