| 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" |
| 11 #include "SkDevice.h" | 11 #include "SkDevice.h" |
| 12 #include "SkOpts.h" | 12 #include "SkOpts.h" |
| 13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
| 14 #include "SkRect.h" | 14 #include "SkRect.h" |
| 15 #include "SkWriteBuffer.h" | 15 #include "SkWriteBuffer.h" |
| 16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
| 17 #include "GrContext.h" | 17 #include "GrContext.h" |
| 18 #include "GrDrawContext.h" | 18 #include "GrDrawContext.h" |
| 19 #include "GrInvariantOutput.h" | 19 #include "GrInvariantOutput.h" |
| 20 #include "GrTexture.h" | 20 #include "GrTexture.h" |
| 21 #include "effects/Gr1DKernelEffect.h" | 21 #include "effects/Gr1DKernelEffect.h" |
| 22 #include "gl/GrGLFragmentProcessor.h" | 22 #include "gl/GrGLFragmentProcessor.h" |
| 23 #include "gl/builders/GrGLProgramBuilder.h" | 23 #include "gl/builders/GrGLProgramBuilder.h" |
| 24 #include "glsl/GrGLSLProgramDataManager.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, | 27 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, |
| 27 int radiusY, | 28 int radiusY, |
| 28 SkImageFilter* input, | 29 SkImageFilter* input, |
| 29 const CropRect* cropRect) | 30 const CropRect* cropRect) |
| 30 : INHERITED(1, &input, cropRect), fRadius(SkISize::Make(radiusX, radiusY)) { | 31 : INHERITED(1, &input, cropRect), fRadius(SkISize::Make(radiusX, radiusY)) { |
| 31 } | 32 } |
| 32 | 33 |
| 33 void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const { | 34 void SkMorphologyImageFilter::flatten(SkWriteBuffer& buffer) const { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 256 |
| 256 class GrGLMorphologyEffect : public GrGLFragmentProcessor { | 257 class GrGLMorphologyEffect : public GrGLFragmentProcessor { |
| 257 public: | 258 public: |
| 258 GrGLMorphologyEffect(const GrProcessor&); | 259 GrGLMorphologyEffect(const GrProcessor&); |
| 259 | 260 |
| 260 virtual void emitCode(EmitArgs&) override; | 261 virtual void emitCode(EmitArgs&) override; |
| 261 | 262 |
| 262 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 263 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
| 263 | 264 |
| 264 protected: | 265 protected: |
| 265 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 266 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
| 266 | 267 |
| 267 private: | 268 private: |
| 268 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 269 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
| 269 | 270 |
| 270 int fRadius; | 271 int fRadius; |
| 271 Gr1DKernelEffect::Direction fDirection; | 272 Gr1DKernelEffect::Direction fDirection; |
| 272 bool fUseRange; | 273 bool fUseRange; |
| 273 GrMorphologyEffect::MorphologyType fType; | 274 GrMorphologyEffect::MorphologyType fType; |
| 274 GrGLProgramDataManager::UniformHandle fPixelSizeUni; | 275 GrGLSLProgramDataManager::UniformHandle fPixelSizeUni; |
| 275 GrGLProgramDataManager::UniformHandle fRangeUni; | 276 GrGLSLProgramDataManager::UniformHandle fRangeUni; |
| 276 | 277 |
| 277 typedef GrGLFragmentProcessor INHERITED; | 278 typedef GrGLFragmentProcessor INHERITED; |
| 278 }; | 279 }; |
| 279 | 280 |
| 280 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) { | 281 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) { |
| 281 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 282 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
| 282 fRadius = m.radius(); | 283 fRadius = m.radius(); |
| 283 fDirection = m.direction(); | 284 fDirection = m.direction(); |
| 284 fUseRange = m.useRange(); | 285 fUseRange = m.useRange(); |
| 285 fType = m.type(); | 286 fType = m.type(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, | 357 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, |
| 357 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { | 358 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { |
| 358 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 359 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
| 359 uint32_t key = static_cast<uint32_t>(m.radius()); | 360 uint32_t key = static_cast<uint32_t>(m.radius()); |
| 360 key |= (m.type() << 8); | 361 key |= (m.type() << 8); |
| 361 key |= (m.direction() << 9); | 362 key |= (m.direction() << 9); |
| 362 if (m.useRange()) key |= 1 << 10; | 363 if (m.useRange()) key |= 1 << 10; |
| 363 b->add32(key); | 364 b->add32(key); |
| 364 } | 365 } |
| 365 | 366 |
| 366 void GrGLMorphologyEffect::onSetData(const GrGLProgramDataManager& pdman, | 367 void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 367 const GrProcessor& proc) { | 368 const GrProcessor& proc) { |
| 368 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 369 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
| 369 GrTexture& texture = *m.texture(0); | 370 GrTexture& texture = *m.texture(0); |
| 370 // the code we generated was for a specific kernel radius, direction and bou
nd usage | 371 // the code we generated was for a specific kernel radius, direction and bou
nd usage |
| 371 SkASSERT(m.radius() == fRadius); | 372 SkASSERT(m.radius() == fRadius); |
| 372 SkASSERT(m.direction() == fDirection); | 373 SkASSERT(m.direction() == fDirection); |
| 373 SkASSERT(m.useRange() == fUseRange); | 374 SkASSERT(m.useRange() == fUseRange); |
| 374 | 375 |
| 375 float pixelSize = 0.0f; | 376 float pixelSize = 0.0f; |
| 376 switch (fDirection) { | 377 switch (fDirection) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 SkBitmap* result, SkIPoint* offset) con
st { | 669 SkBitmap* result, SkIPoint* offset) con
st { |
| 669 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 670 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
| 670 } | 671 } |
| 671 | 672 |
| 672 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 673 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
| 673 SkBitmap* result, SkIPoint* offset) cons
t { | 674 SkBitmap* result, SkIPoint* offset) cons
t { |
| 674 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 675 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
| 675 } | 676 } |
| 676 | 677 |
| 677 #endif | 678 #endif |
| OLD | NEW |