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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 void SkColorCubeFilter::toString(SkString* str) const { | 154 void SkColorCubeFilter::toString(SkString* str) const { |
155 str->append("SkColorCubeFilter "); | 155 str->append("SkColorCubeFilter "); |
156 } | 156 } |
157 #endif | 157 #endif |
158 | 158 |
159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
160 #if SK_SUPPORT_GPU | 160 #if SK_SUPPORT_GPU |
161 | 161 |
162 class GrColorCubeEffect : public GrFragmentProcessor { | 162 class GrColorCubeEffect : public GrFragmentProcessor { |
163 public: | 163 public: |
164 static const GrFragmentProcessor* Create(GrTexture* colorCube) { | 164 static sk_sp<GrFragmentProcessor> Make(GrTexture* colorCube) { |
165 return (nullptr != colorCube) ? new GrColorCubeEffect(colorCube) : nullp
tr; | 165 return (nullptr != colorCube) ? sk_sp<GrFragmentProcessor>(new GrColorCu
beEffect(colorCube)) |
| 166 : nullptr; |
166 } | 167 } |
167 | 168 |
168 virtual ~GrColorCubeEffect(); | 169 virtual ~GrColorCubeEffect(); |
169 | 170 |
170 const char* name() const override { return "ColorCube"; } | 171 const char* name() const override { return "ColorCube"; } |
171 | 172 |
172 int colorCubeSize() const { return fColorCubeAccess.getTexture()->width(); } | 173 int colorCubeSize() const { return fColorCubeAccess.getTexture()->width(); } |
173 | 174 |
174 | 175 |
175 void onComputeInvariantOutput(GrInvariantOutput*) const override; | 176 void onComputeInvariantOutput(GrInvariantOutput*) const override; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); | 291 const GrColorCubeEffect& colorCube = proc.cast<GrColorCubeEffect>(); |
291 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); | 292 SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); |
292 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); | 293 pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); |
293 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); | 294 pdman.set1f(fColorCubeInvSizeUni, SkScalarToFloat(SkScalarInvert(size))); |
294 } | 295 } |
295 | 296 |
296 void GrColorCubeEffect::GLSLProcessor::GenKey(const GrProcessor& proc, | 297 void GrColorCubeEffect::GLSLProcessor::GenKey(const GrProcessor& proc, |
297 const GrGLSLCaps&, GrProcessorKeyB
uilder* b) { | 298 const GrGLSLCaps&, GrProcessorKeyB
uilder* b) { |
298 } | 299 } |
299 | 300 |
300 const GrFragmentProcessor* SkColorCubeFilter::asFragmentProcessor(GrContext* con
text) const { | 301 sk_sp<GrFragmentProcessor> SkColorCubeFilter::asFragmentProcessor(GrContext* con
text) const { |
301 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 302 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
302 GrUniqueKey key; | 303 GrUniqueKey key; |
303 GrUniqueKey::Builder builder(&key, kDomain, 2); | 304 GrUniqueKey::Builder builder(&key, kDomain, 2); |
304 builder[0] = fUniqueID; | 305 builder[0] = fUniqueID; |
305 builder[1] = fCache.cubeDimension(); | 306 builder[1] = fCache.cubeDimension(); |
306 builder.finish(); | 307 builder.finish(); |
307 | 308 |
308 GrSurfaceDesc desc; | 309 GrSurfaceDesc desc; |
309 desc.fWidth = fCache.cubeDimension(); | 310 desc.fWidth = fCache.cubeDimension(); |
310 desc.fHeight = fCache.cubeDimension() * fCache.cubeDimension(); | 311 desc.fHeight = fCache.cubeDimension() * fCache.cubeDimension(); |
311 desc.fConfig = kRGBA_8888_GrPixelConfig; | 312 desc.fConfig = kRGBA_8888_GrPixelConfig; |
312 desc.fIsMipMapped = false; | 313 desc.fIsMipMapped = false; |
313 | 314 |
314 SkAutoTUnref<GrTexture> textureCube( | 315 SkAutoTUnref<GrTexture> textureCube( |
315 context->textureProvider()->findAndRefTextureByUniqueKey(key)); | 316 context->textureProvider()->findAndRefTextureByUniqueKey(key)); |
316 if (!textureCube) { | 317 if (!textureCube) { |
317 textureCube.reset(context->textureProvider()->createTexture( | 318 textureCube.reset(context->textureProvider()->createTexture( |
318 desc, SkBudgeted::kYes, fCubeData->data(), 0)); | 319 desc, SkBudgeted::kYes, fCubeData->data(), 0)); |
319 if (textureCube) { | 320 if (textureCube) { |
320 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); | 321 context->textureProvider()->assignUniqueKeyToTexture(key, textureCub
e); |
321 } else { | 322 } else { |
322 return nullptr; | 323 return nullptr; |
323 } | 324 } |
324 } | 325 } |
325 | 326 |
326 return GrColorCubeEffect::Create(textureCube); | 327 return sk_sp<GrFragmentProcessor>(GrColorCubeEffect::Make(textureCube)); |
327 } | 328 } |
328 #endif | 329 #endif |
OLD | NEW |