| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 void SkColorCubeFilter::toString(SkString* str) const { | 153 void SkColorCubeFilter::toString(SkString* str) const { |
| 154 str->append("SkColorCubeFilter "); | 154 str->append("SkColorCubeFilter "); |
| 155 } | 155 } |
| 156 #endif | 156 #endif |
| 157 | 157 |
| 158 /////////////////////////////////////////////////////////////////////////////// | 158 /////////////////////////////////////////////////////////////////////////////// |
| 159 #if SK_SUPPORT_GPU | 159 #if SK_SUPPORT_GPU |
| 160 | 160 |
| 161 class GrColorCubeEffect : public GrFragmentProcessor { | 161 class GrColorCubeEffect : public GrFragmentProcessor { |
| 162 public: | 162 public: |
| 163 static GrFragmentProcessor* Create(GrTexture* colorCube) { | 163 static const GrFragmentProcessor* Create(GrTexture* colorCube) { |
| 164 return (nullptr != colorCube) ? new GrColorCubeEffect(colorCube) : nullp
tr; | 164 return (nullptr != colorCube) ? new GrColorCubeEffect(colorCube) : nullp
tr; |
| 165 } | 165 } |
| 166 | 166 |
| 167 virtual ~GrColorCubeEffect(); | 167 virtual ~GrColorCubeEffect(); |
| 168 | 168 |
| 169 const char* name() const override { return "ColorCube"; } | 169 const char* name() const override { return "ColorCube"; } |
| 170 | 170 |
| 171 int colorCubeSize() const { return fColorCubeAccess.getTexture()->width(); } | 171 int colorCubeSize() const { return fColorCubeAccess.getTexture()->width(); } |
| 172 | 172 |
| 173 | 173 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); | 296 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); |
| 297 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); | 297 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); |
| 298 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); | 298 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); |
| 299 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); | 299 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void GrColorCubeEffect::GLProcessor::GenKey(const GrProcessor& proc, | 302 void GrColorCubeEffect::GLProcessor::GenKey(const GrProcessor& proc, |
| 303 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { | 303 const GrGLSLCaps&, GrProcessorKeyBui
lder* b) { |
| 304 } | 304 } |
| 305 | 305 |
| 306 bool SkColorCubeFilter::asFragmentProcessors(GrContext* context, GrProcessorData
Manager*, | 306 const GrFragmentProcessor* SkColorCubeFilter::asFragmentProcessor(GrContext* con
text, |
| 307 SkTDArray<const GrFragmentProcessor
*>* array) const { | 307 GrProcessorDat
aManager*) const { |
| 308 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 308 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 309 GrUniqueKey key; | 309 GrUniqueKey key; |
| 310 GrUniqueKey::Builder builder(&key, kDomain, 2); | 310 GrUniqueKey::Builder builder(&key, kDomain, 2); |
| 311 builder[0] = fUniqueID; | 311 builder[0] = fUniqueID; |
| 312 builder[1] = fCache.cubeDimension(); | 312 builder[1] = fCache.cubeDimension(); |
| 313 builder.finish(); | 313 builder.finish(); |
| 314 | 314 |
| 315 GrSurfaceDesc desc; | 315 GrSurfaceDesc desc; |
| 316 desc.fWidth = fCache.cubeDimension(); | 316 desc.fWidth = fCache.cubeDimension(); |
| 317 desc.fHeight = fCache.cubeDimension() * fCache.cubeDimension(); | 317 desc.fHeight = fCache.cubeDimension() * fCache.cubeDimension(); |
| 318 desc.fConfig = kRGBA_8888_GrPixelConfig; | 318 desc.fConfig = kRGBA_8888_GrPixelConfig; |
| 319 | 319 |
| 320 SkAutoTUnref<GrTexture> textureCube( | 320 SkAutoTUnref<GrTexture> textureCube( |
| 321 context->textureProvider()->findAndRefTextureByUniqueKey(key)); | 321 context->textureProvider()->findAndRefTextureByUniqueKey(key)); |
| 322 if (!textureCube) { | 322 if (!textureCube) { |
| 323 textureCube.reset(context->textureProvider()->createTexture( | 323 textureCube.reset(context->textureProvider()->createTexture( |
| 324 desc, true, fCubeData->data(), 0)); | 324 desc, true, fCubeData->data(), 0)); |
| 325 if (textureCube) { | 325 if (textureCube) { |
| 326 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); | 326 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); |
| 327 } else { |
| 328 return nullptr; |
| 327 } | 329 } |
| 328 } | 330 } |
| 329 | 331 |
| 330 GrFragmentProcessor* frag = textureCube ? GrColorCubeEffect::Create(textureC
ube) : nullptr; | 332 return GrColorCubeEffect::Create(textureCube); |
| 331 if (frag) { | |
| 332 if (array) { | |
| 333 *array->append() = frag; | |
| 334 } else { | |
| 335 frag->unref(); | |
| 336 SkDEBUGCODE(frag = nullptr;) | |
| 337 } | |
| 338 return true; | |
| 339 } | |
| 340 return false; | |
| 341 } | 333 } |
| 342 #endif | 334 #endif |
| OLD | NEW |