| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkColorCubeFilter.h" | 8 #include "SkColorCubeFilter.h" |
| 9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
| 10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
| 11 #include "SkOpts.h" | 11 #include "SkOpts.h" |
| 12 #include "SkReadBuffer.h" | 12 #include "SkReadBuffer.h" |
| 13 #include "SkUnPreMultiply.h" | 13 #include "SkUnPreMultiply.h" |
| 14 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
| 15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
| 16 #include "GrContext.h" | 16 #include "GrContext.h" |
| 17 #include "GrCoordTransform.h" | 17 #include "GrCoordTransform.h" |
| 18 #include "GrInvariantOutput.h" | 18 #include "GrInvariantOutput.h" |
| 19 #include "GrTexturePriv.h" | 19 #include "GrTexturePriv.h" |
| 20 #include "SkGr.h" | 20 #include "SkGr.h" |
| 21 #include "gl/GrGLFragmentProcessor.h" | 21 #include "gl/GrGLFragmentProcessor.h" |
| 22 #include "gl/builders/GrGLProgramBuilder.h" | 22 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 23 #include "glsl/GrGLSLProgramBuilder.h" |
| 23 #include "glsl/GrGLSLProgramDataManager.h" | 24 #include "glsl/GrGLSLProgramDataManager.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 /////////////////////////////////////////////////////////////////////////////// | 27 /////////////////////////////////////////////////////////////////////////////// |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 int32_t SkNextColorCubeUniqueID() { | 30 int32_t SkNextColorCubeUniqueID() { |
| 30 static int32_t gColorCubeUniqueID; | 31 static int32_t gColorCubeUniqueID; |
| 31 // do a loop in case our global wraps around, as we never want to return a 0 | 32 // do a loop in case our global wraps around, as we never want to return a 0 |
| 32 int32_t genID; | 33 int32_t genID; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 } | 238 } |
| 238 | 239 |
| 239 GrColorCubeEffect::GLProcessor::~GLProcessor() { | 240 GrColorCubeEffect::GLProcessor::~GLProcessor() { |
| 240 } | 241 } |
| 241 | 242 |
| 242 void GrColorCubeEffect::GLProcessor::emitCode(EmitArgs& args) { | 243 void GrColorCubeEffect::GLProcessor::emitCode(EmitArgs& args) { |
| 243 if (nullptr == args.fInputColor) { | 244 if (nullptr == args.fInputColor) { |
| 244 args.fInputColor = "vec4(1)"; | 245 args.fInputColor = "vec4(1)"; |
| 245 } | 246 } |
| 246 | 247 |
| 247 fColorCubeSizeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_
Visibility, | 248 fColorCubeSizeUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragmen
t_Visibility, |
| 248 kFloat_GrSLType, kDefault_GrSLPrecis
ion, | 249 kFloat_GrSLType, kDefault_GrSLPrecis
ion, |
| 249 "Size"); | 250 "Size"); |
| 250 const char* colorCubeSizeUni = args.fBuilder->getUniformCStr(fColorCubeSizeU
ni); | 251 const char* colorCubeSizeUni = args.fBuilder->getUniformCStr(fColorCubeSizeU
ni); |
| 251 fColorCubeInvSizeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragme
nt_Visibility, | 252 fColorCubeInvSizeUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFrag
ment_Visibility, |
| 252 kFloat_GrSLType, kDefault_GrSLPre
cision, | 253 kFloat_GrSLType, kDefault_GrSLPre
cision, |
| 253 "InvSize"); | 254 "InvSize"); |
| 254 const char* colorCubeInvSizeUni = args.fBuilder->getUniformCStr(fColorCubeIn
vSizeUni); | 255 const char* colorCubeInvSizeUni = args.fBuilder->getUniformCStr(fColorCubeIn
vSizeUni); |
| 255 | 256 |
| 256 const char* nonZeroAlpha = "nonZeroAlpha"; | 257 const char* nonZeroAlpha = "nonZeroAlpha"; |
| 257 const char* unPMColor = "unPMColor"; | 258 const char* unPMColor = "unPMColor"; |
| 258 const char* cubeIdx = "cubeIdx"; | 259 const char* cubeIdx = "cubeIdx"; |
| 259 const char* cCoords1 = "cCoords1"; | 260 const char* cCoords1 = "cCoords1"; |
| 260 const char* cCoords2 = "cCoords2"; | 261 const char* cCoords2 = "cCoords2"; |
| 261 | 262 |
| 262 // Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.
0, | 263 // Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.
0, |
| 263 // the shader might need "#extension GL_OES_texture_3D : enable". | 264 // the shader might need "#extension GL_OES_texture_3D : enable". |
| 264 | 265 |
| 265 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 266 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
| 266 | 267 |
| 267 // Unpremultiply color | 268 // Unpremultiply color |
| 268 fsBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, a
rgs.fInputColor); | 269 fsBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, a
rgs.fInputColor); |
| 269 fsBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n", | 270 fsBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n", |
| 270 unPMColor, args.fInputColor, nonZeroAlpha, nonZeroAlp
ha); | 271 unPMColor, args.fInputColor, nonZeroAlpha, nonZeroAlp
ha); |
| 271 | 272 |
| 272 // Fit input color into the cube. | 273 // Fit input color into the cube. |
| 273 fsBuilder->codeAppendf( | 274 fsBuilder->codeAppendf( |
| 274 "vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (
%s - 1.0));\n", | 275 "vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (
%s - 1.0));\n", |
| 275 cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvS
izeUni, | 276 cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvS
izeUni, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 if (textureCube) { | 326 if (textureCube) { |
| 326 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); | 327 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); |
| 327 } else { | 328 } else { |
| 328 return nullptr; | 329 return nullptr; |
| 329 } | 330 } |
| 330 } | 331 } |
| 331 | 332 |
| 332 return GrColorCubeEffect::Create(textureCube); | 333 return GrColorCubeEffect::Create(textureCube); |
| 333 } | 334 } |
| 334 #endif | 335 #endif |
| OLD | NEW |