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" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 205 |
206 static const char* Name() { return "ColorProfile"; } | 206 static const char* Name() { return "ColorProfile"; } |
207 | 207 |
208 virtual void onComputeInvariantOutput(GrProcessor::InvariantOutput*) const S
K_OVERRIDE; | 208 virtual void onComputeInvariantOutput(GrProcessor::InvariantOutput*) const S
K_OVERRIDE; |
209 | 209 |
210 class GLProcessor : public GrGLFragmentProcessor { | 210 class GLProcessor : public GrGLFragmentProcessor { |
211 public: | 211 public: |
212 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
); | 212 GLProcessor(const GrBackendProcessorFactory& factory, const GrProcessor&
); |
213 virtual ~GLProcessor(); | 213 virtual ~GLProcessor(); |
214 | 214 |
215 virtual void emitCode(GrGLProgramBuilder*, | 215 virtual void emitCode(GrGLFPBuilder*, |
216 const GrFragmentProcessor&, | 216 const GrFragmentProcessor&, |
217 const GrProcessorKey&, | 217 const GrProcessorKey&, |
218 const char* outputColor, | 218 const char* outputColor, |
219 const char* inputColor, | 219 const char* inputColor, |
220 const TransformedCoordsArray&, | 220 const TransformedCoordsArray&, |
221 const TextureSamplerArray&) SK_OVERRIDE; | 221 const TextureSamplerArray&) SK_OVERRIDE; |
222 | 222 |
223 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcess
orKeyBuilder*); | 223 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcess
orKeyBuilder*); |
224 | 224 |
225 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&)
SK_OVERRIDE; | 225 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&)
SK_OVERRIDE; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 /////////////////////////////////////////////////////////////////////////////// | 271 /////////////////////////////////////////////////////////////////////////////// |
272 | 272 |
273 GrColorProfileEffect::GLProcessor::GLProcessor(const GrBackendProcessorFactory&
factory, | 273 GrColorProfileEffect::GLProcessor::GLProcessor(const GrBackendProcessorFactory&
factory, |
274 const GrProcessor&) | 274 const GrProcessor&) |
275 : INHERITED(factory) { | 275 : INHERITED(factory) { |
276 } | 276 } |
277 | 277 |
278 GrColorProfileEffect::GLProcessor::~GLProcessor() { | 278 GrColorProfileEffect::GLProcessor::~GLProcessor() { |
279 } | 279 } |
280 | 280 |
281 void GrColorProfileEffect::GLProcessor::emitCode(GrGLProgramBuilder* builder, | 281 void GrColorProfileEffect::GLProcessor::emitCode(GrGLFPBuilder* builder, |
282 const GrFragmentProcessor&, | 282 const GrFragmentProcessor&, |
283 const GrProcessorKey&, | 283 const GrProcessorKey&, |
284 const char* outputColor, | 284 const char* outputColor, |
285 const char* inputColor, | 285 const char* inputColor, |
286 const TransformedCoordsArray& c
oords, | 286 const TransformedCoordsArray& c
oords, |
287 const TextureSamplerArray& samp
lers) { | 287 const TextureSamplerArray& samp
lers) { |
288 if (NULL == inputColor) { | 288 if (NULL == inputColor) { |
289 inputColor = "vec4(1)"; | 289 inputColor = "vec4(1)"; |
290 } | 290 } |
291 | 291 |
292 fColorCubeSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, | 292 fColorCubeSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibi
lity, |
293 kFloat_GrSLType, "Size"); | 293 kFloat_GrSLType, "Size"); |
294 const char* colorCubeSizeUni = builder->getUniformCStr(fColorCubeSizeUni); | 294 const char* colorCubeSizeUni = builder->getUniformCStr(fColorCubeSizeUni); |
295 fColorCubeInvSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 295 fColorCubeInvSizeUni = builder->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, |
296 kFloat_GrSLType, "InvSize"); | 296 kFloat_GrSLType, "InvSize"); |
297 const char* colorCubeInvSizeUni = builder->getUniformCStr(fColorCubeInvSizeU
ni); | 297 const char* colorCubeInvSizeUni = builder->getUniformCStr(fColorCubeInvSizeU
ni); |
298 | 298 |
299 const char* nonZeroAlpha = "nonZeroAlpha"; | 299 const char* nonZeroAlpha = "nonZeroAlpha"; |
300 const char* unPMColor = "unPMColor"; | 300 const char* unPMColor = "unPMColor"; |
301 const char* cubeIdx = "cubeIdx"; | 301 const char* cubeIdx = "cubeIdx"; |
302 const char* cCoords1 = "cCoords1"; | 302 const char* cCoords1 = "cCoords1"; |
303 const char* cCoords2 = "cCoords2"; | 303 const char* cCoords2 = "cCoords2"; |
304 | 304 |
305 // Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.
0, | 305 // Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.
0, |
306 // the shader might need "#extension GL_OES_texture_3D : enable". | 306 // the shader might need "#extension GL_OES_texture_3D : enable". |
307 | 307 |
308 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 308 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
309 | 309 |
310 // Unpremultiply color | 310 // Unpremultiply color |
311 fsBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, i
nputColor); | 311 fsBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, i
nputColor); |
312 fsBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n", | 312 fsBuilder->codeAppendf("\tvec4 %s = vec4(%s.rgb / %s, %s);\n", |
313 unPMColor, inputColor, nonZeroAlpha, nonZeroAlpha); | 313 unPMColor, inputColor, nonZeroAlpha, nonZeroAlpha); |
314 | 314 |
315 // Fit input color into the cube. | 315 // Fit input color into the cube. |
316 fsBuilder->codeAppendf( | 316 fsBuilder->codeAppendf( |
317 "vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (
%s - 1.0));\n", | 317 "vec3 %s = vec3(%s.rg * vec2((%s - 1.0) * %s) + vec2(0.5 * %s), %s.b * (
%s - 1.0));\n", |
318 cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvS
izeUni, | 318 cubeIdx, unPMColor, colorCubeSizeUni, colorCubeInvSizeUni, colorCubeInvS
izeUni, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 static_cast<GrTexture*>(context->findAndRefCachedResource( | 366 static_cast<GrTexture*>(context->findAndRefCachedResource( |
367 GrTexturePriv::ComputeKey(context->getGpu(), NULL, desc, cacheID))))
; | 367 GrTexturePriv::ComputeKey(context->getGpu(), NULL, desc, cacheID))))
; |
368 | 368 |
369 if (!textureCube) { | 369 if (!textureCube) { |
370 textureCube.reset(context->createTexture(NULL, desc, cacheID, fCubeData-
>data(), 0)); | 370 textureCube.reset(context->createTexture(NULL, desc, cacheID, fCubeData-
>data(), 0)); |
371 } | 371 } |
372 | 372 |
373 return textureCube ? GrColorProfileEffect::Create(textureCube) : NULL; | 373 return textureCube ? GrColorProfileEffect::Create(textureCube) : NULL; |
374 } | 374 } |
375 #endif | 375 #endif |
OLD | NEW |