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