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