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