OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
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 "SkMorphologyImageFilter.h" | 8 #include "SkMorphologyImageFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 }; | 309 }; |
310 | 310 |
311 /////////////////////////////////////////////////////////////////////////////// | 311 /////////////////////////////////////////////////////////////////////////////// |
312 | 312 |
313 class GrGLMorphologyEffect : public GrGLEffect { | 313 class GrGLMorphologyEffect : public GrGLEffect { |
314 public: | 314 public: |
315 GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrDrawEffect&); | 315 GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrDrawEffect&); |
316 | 316 |
317 virtual void emitCode(GrGLShaderBuilder*, | 317 virtual void emitCode(GrGLShaderBuilder*, |
318 const GrDrawEffect&, | 318 const GrDrawEffect&, |
319 EffectKey, | 319 const GrEffectKey&, |
320 const char* outputColor, | 320 const char* outputColor, |
321 const char* inputColor, | 321 const char* inputColor, |
322 const TransformedCoordsArray&, | 322 const TransformedCoordsArray&, |
323 const TextureSamplerArray&) SK_OVERRIDE; | 323 const TextureSamplerArray&) SK_OVERRIDE; |
324 | 324 |
325 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 325 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder* b); |
326 | 326 |
327 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 327 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
328 | 328 |
329 private: | 329 private: |
330 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 330 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
331 | 331 |
332 int fRadius; | 332 int fRadius; |
333 GrMorphologyEffect::MorphologyType fType; | 333 GrMorphologyEffect::MorphologyType fType; |
334 GrGLUniformManager::UniformHandle fImageIncrementUni; | 334 GrGLUniformManager::UniformHandle fImageIncrementUni; |
335 | 335 |
336 typedef GrGLEffect INHERITED; | 336 typedef GrGLEffect INHERITED; |
337 }; | 337 }; |
338 | 338 |
339 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory
, | 339 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory
, |
340 const GrDrawEffect& drawEffect) | 340 const GrDrawEffect& drawEffect) |
341 : INHERITED(factory) { | 341 : INHERITED(factory) { |
342 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); | 342 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); |
343 fRadius = m.radius(); | 343 fRadius = m.radius(); |
344 fType = m.type(); | 344 fType = m.type(); |
345 } | 345 } |
346 | 346 |
347 void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder, | 347 void GrGLMorphologyEffect::emitCode(GrGLShaderBuilder* builder, |
348 const GrDrawEffect&, | 348 const GrDrawEffect&, |
349 EffectKey key, | 349 const GrEffectKey& key, |
350 const char* outputColor, | 350 const char* outputColor, |
351 const char* inputColor, | 351 const char* inputColor, |
352 const TransformedCoordsArray& coords, | 352 const TransformedCoordsArray& coords, |
353 const TextureSamplerArray& samplers) { | 353 const TextureSamplerArray& samplers) { |
354 SkString coords2D = builder->ensureFSCoords2D(coords, 0); | 354 SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
355 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, | 355 fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibi
lity, |
356 kVec2f_GrSLType, "ImageIncrement"); | 356 kVec2f_GrSLType, "ImageIncrement"); |
357 | 357 |
358 const char* func; | 358 const char* func; |
359 switch (fType) { | 359 switch (fType) { |
(...skipping 17 matching lines...) Expand all Loading... |
377 builder->fsCodeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor)
; | 377 builder->fsCodeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor)
; |
378 builder->fsAppendTextureLookup(samplers[0], "coord"); | 378 builder->fsAppendTextureLookup(samplers[0], "coord"); |
379 builder->fsCodeAppend(");\n"); | 379 builder->fsCodeAppend(");\n"); |
380 builder->fsCodeAppendf("\t\t\tcoord += %s;\n", imgInc); | 380 builder->fsCodeAppendf("\t\t\tcoord += %s;\n", imgInc); |
381 builder->fsCodeAppend("\t\t}\n"); | 381 builder->fsCodeAppend("\t\t}\n"); |
382 SkString modulate; | 382 SkString modulate; |
383 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); | 383 GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor); |
384 builder->fsCodeAppend(modulate.c_str()); | 384 builder->fsCodeAppend(modulate.c_str()); |
385 } | 385 } |
386 | 386 |
387 GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrDrawEffect& drawEffec
t, | 387 void GrGLMorphologyEffect::GenKey(const GrDrawEffect& drawEffect, |
388 const GrGLCaps&) { | 388 const GrGLCaps&, GrEffectKeyBuilder* b) { |
389 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); | 389 const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>(); |
390 EffectKey key = static_cast<EffectKey>(m.radius()); | 390 uint32_t key = static_cast<uint32_t>(m.radius()); |
391 key |= (m.type() << 8); | 391 key |= (m.type() << 8); |
392 return key; | 392 b->add32(key); |
393 } | 393 } |
394 | 394 |
395 void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman, | 395 void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman, |
396 const GrDrawEffect& drawEffect) { | 396 const GrDrawEffect& drawEffect) { |
397 const Gr1DKernelEffect& kern = drawEffect.castEffect<Gr1DKernelEffect>(); | 397 const Gr1DKernelEffect& kern = drawEffect.castEffect<Gr1DKernelEffect>(); |
398 GrTexture& texture = *kern.texture(0); | 398 GrTexture& texture = *kern.texture(0); |
399 // the code we generated was for a specific kernel radius | 399 // the code we generated was for a specific kernel radius |
400 SkASSERT(kern.radius() == fRadius); | 400 SkASSERT(kern.radius() == fRadius); |
401 float imageIncrement[2] = { 0 }; | 401 float imageIncrement[2] = { 0 }; |
402 switch (kern.direction()) { | 402 switch (kern.direction()) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 SkBitmap* result, SkIPoint* offset) con
st { | 578 SkBitmap* result, SkIPoint* offset) con
st { |
579 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 579 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
580 } | 580 } |
581 | 581 |
582 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 582 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
583 SkBitmap* result, SkIPoint* offset) cons
t { | 583 SkBitmap* result, SkIPoint* offset) cons
t { |
584 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 584 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
585 } | 585 } |
586 | 586 |
587 #endif | 587 #endif |
OLD | NEW |