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