| 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 GrColorCubeEffect(GrTexture* colorCube); | 205 GrColorCubeEffect(GrTexture* colorCube); |
| 206 | 206 |
| 207 GrTextureAccess fColorCubeAccess; | 207 GrTextureAccess fColorCubeAccess; |
| 208 | 208 |
| 209 typedef GrFragmentProcessor INHERITED; | 209 typedef GrFragmentProcessor INHERITED; |
| 210 }; | 210 }; |
| 211 | 211 |
| 212 /////////////////////////////////////////////////////////////////////////////// | 212 /////////////////////////////////////////////////////////////////////////////// |
| 213 | 213 |
| 214 GrColorCubeEffect::GrColorCubeEffect(GrTexture* colorCube) | 214 GrColorCubeEffect::GrColorCubeEffect(GrTexture* colorCube) |
| 215 : fColorCubeAccess(colorCube, "bgra", GrTextureParams::kBilerp_FilterMode) { | 215 : fColorCubeAccess(colorCube, GrTextureParams::kBilerp_FilterMode) { |
| 216 this->initClassID<GrColorCubeEffect>(); | 216 this->initClassID<GrColorCubeEffect>(); |
| 217 this->addTextureAccess(&fColorCubeAccess); | 217 this->addTextureAccess(&fColorCubeAccess); |
| 218 } | 218 } |
| 219 | 219 |
| 220 GrColorCubeEffect::~GrColorCubeEffect() { | 220 GrColorCubeEffect::~GrColorCubeEffect() { |
| 221 } | 221 } |
| 222 | 222 |
| 223 void GrColorCubeEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, | 223 void GrColorCubeEffect::onGetGLSLProcessorKey(const GrGLSLCaps& caps, |
| 224 GrProcessorKeyBuilder* b) const { | 224 GrProcessorKeyBuilder* b) const { |
| 225 GLSLProcessor::GenKey(*this, caps, b); | 225 GLSLProcessor::GenKey(*this, caps, b); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 | 280 |
| 281 // Compute y coord for for texture fetches. | 281 // Compute y coord for for texture fetches. |
| 282 fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (floor(%s.b) + %s.g) * %s);\n
", | 282 fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (floor(%s.b) + %s.g) * %s);\n
", |
| 283 cCoords1, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSi
zeUni); | 283 cCoords1, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSi
zeUni); |
| 284 fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (ceil(%s.b) + %s.g) * %s);\n"
, | 284 fragBuilder->codeAppendf("vec2 %s = vec2(%s.r, (ceil(%s.b) + %s.g) * %s);\n"
, |
| 285 cCoords2, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSi
zeUni); | 285 cCoords2, cubeIdx, cubeIdx, cubeIdx, colorCubeInvSi
zeUni); |
| 286 | 286 |
| 287 // Apply the cube. | 287 // Apply the cube. |
| 288 fragBuilder->codeAppendf("%s = vec4(mix(", args.fOutputColor); | 288 fragBuilder->codeAppendf("%s = vec4(mix(", args.fOutputColor); |
| 289 fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords1); | 289 fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords1); |
| 290 fragBuilder->codeAppend(".rgb, "); | 290 fragBuilder->codeAppend(".bgr, "); |
| 291 fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords2); | 291 fragBuilder->appendTextureLookup(args.fSamplers[0], cCoords2); |
| 292 | 292 |
| 293 // Premultiply color by alpha. Note that the input alpha is not modified by
this shader. | 293 // Premultiply color by alpha. Note that the input alpha is not modified by
this shader. |
| 294 fragBuilder->codeAppendf(".rgb, fract(%s.b)) * vec3(%s), %s.a);\n", | 294 fragBuilder->codeAppendf(".bgr, fract(%s.b)) * vec3(%s), %s.a);\n", |
| 295 cubeIdx, nonZeroAlpha, args.fInputColor); | 295 cubeIdx, nonZeroAlpha, args.fInputColor); |
| 296 } | 296 } |
| 297 | 297 |
| 298 void GrColorCubeEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, | 298 void GrColorCubeEffect::GLSLProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, |
| 299 const GrProcessor& proc) { | 299 const GrProcessor& proc) { |
| 300 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); | 300 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); |
| 301 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); | 301 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); |
| 302 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); | 302 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); |
| 303 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); | 303 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); |
| 304 } | 304 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 328 if (textureCube) { | 328 if (textureCube) { |
| 329 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); | 329 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); |
| 330 } else { | 330 } else { |
| 331 return nullptr; | 331 return nullptr; |
| 332 } | 332 } |
| 333 } | 333 } |
| 334 | 334 |
| 335 return GrColorCubeEffect::Create(textureCube); | 335 return GrColorCubeEffect::Create(textureCube); |
| 336 } | 336 } |
| 337 #endif | 337 #endif |
| OLD | NEW |