aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLGpu.cpp
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2015-11-04 04:23:53 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-04 04:23:53 -0800
commitb7e7d5748d74c7482436b33733d7770484bb62e3 (patch)
tree29849ef2c2004f4215882b1f1987a4e4445b2d80 /src/gpu/gl/GrGLGpu.cpp
parentdf85a7254798f44e1d5b532fd4cbe58826b8d160 (diff)
Create swizzle table inside of glsl caps
Diffstat (limited to 'src/gpu/gl/GrGLGpu.cpp')
-rw-r--r--src/gpu/gl/GrGLGpu.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 0e9aa0d917..4dde4afd63 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -2404,19 +2404,30 @@ static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) {
return gWrapModes[tm];
}
-const GrGLenum* GrGLGpu::GetTexParamSwizzle(GrPixelConfig config, const GrGLCaps& caps) {
- if (caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(config)) {
- if (caps.textureRedSupport()) {
- static const GrGLenum gRedSmear[] = { GR_GL_RED, GR_GL_RED, GR_GL_RED, GR_GL_RED };
- return gRedSmear;
- } else {
- static const GrGLenum gAlphaSmear[] = { GR_GL_ALPHA, GR_GL_ALPHA,
- GR_GL_ALPHA, GR_GL_ALPHA };
- return gAlphaSmear;
- }
- } else {
- static const GrGLenum gStraight[] = { GR_GL_RED, GR_GL_GREEN, GR_GL_BLUE, GR_GL_ALPHA };
- return gStraight;
+static GrGLenum get_component_enum_from_char(char component) {
+ switch (component) {
+ case 'r':
+ return GR_GL_RED;
+ case 'g':
+ return GR_GL_GREEN;
+ case 'b':
+ return GR_GL_BLUE;
+ case 'a':
+ return GR_GL_ALPHA;
+ default:
+ SkFAIL("Unsupported component");
+ return 0;
+ }
+}
+
+/** If texture swizzling is available using tex parameters then it is preferred over mangling
+ the generated shader code. This potentially allows greater reuse of cached shaders. */
+static void get_tex_param_swizzle(GrPixelConfig config,
+ const GrGLSLCaps& caps,
+ GrGLenum* glSwizzle) {
+ const char* swizzle = caps.getSwizzleMap(config);
+ for (int i = 0; i < 4; ++i) {
+ glSwizzle[i] = get_component_enum_from_char(swizzle[i]);
}
}
@@ -2485,9 +2496,7 @@ void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX());
newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY());
- memcpy(newTexParams.fSwizzleRGBA,
- GetTexParamSwizzle(texture->config(), this->glCaps()),
- sizeof(newTexParams.fSwizzleRGBA));
+ get_tex_param_swizzle(texture->config(), *this->glCaps().glslCaps(), newTexParams.fSwizzleRGBA);
if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) {
this->setTextureUnit(unitIdx);
GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMagFilter));
@@ -2504,7 +2513,7 @@ void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur
this->setTextureUnit(unitIdx);
GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT));
}
- if (this->glCaps().textureSwizzleSupport() &&
+ if (!this->glCaps().glslCaps()->mustSwizzleInShader() &&
(setAll || memcmp(newTexParams.fSwizzleRGBA,
oldTexParams.fSwizzleRGBA,
sizeof(newTexParams.fSwizzleRGBA)))) {