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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 217 } |
218 | 218 |
219 virtual ~GrMorphologyEffect(); | 219 virtual ~GrMorphologyEffect(); |
220 | 220 |
221 MorphologyType type() const { return fType; } | 221 MorphologyType type() const { return fType; } |
222 bool useRange() const { return fUseRange; } | 222 bool useRange() const { return fUseRange; } |
223 const float* range() const { return fRange; } | 223 const float* range() const { return fRange; } |
224 | 224 |
225 const char* name() const override { return "Morphology"; } | 225 const char* name() const override { return "Morphology"; } |
226 | 226 |
227 GrGLFragmentProcessor* createGLInstance() const override; | |
228 | |
229 protected: | 227 protected: |
230 | 228 |
231 MorphologyType fType; | 229 MorphologyType fType; |
232 bool fUseRange; | 230 bool fUseRange; |
233 float fRange[2]; | 231 float fRange[2]; |
234 | 232 |
235 private: | 233 private: |
| 234 GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 235 |
236 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 236 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
237 | 237 |
238 bool onIsEqual(const GrFragmentProcessor&) const override; | 238 bool onIsEqual(const GrFragmentProcessor&) const override; |
239 | 239 |
240 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 240 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
241 | 241 |
242 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType); | 242 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType); |
243 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType, | 243 GrMorphologyEffect(GrProcessorDataManager*, GrTexture*, Direction, int radiu
s, MorphologyType, |
244 float bounds[2]); | 244 float bounds[2]); |
245 | 245 |
246 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 246 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
247 | 247 |
248 typedef Gr1DKernelEffect INHERITED; | 248 typedef Gr1DKernelEffect INHERITED; |
249 }; | 249 }; |
250 | 250 |
251 /////////////////////////////////////////////////////////////////////////////// | 251 /////////////////////////////////////////////////////////////////////////////// |
252 | 252 |
253 class GrGLMorphologyEffect : public GrGLFragmentProcessor { | 253 class GrGLMorphologyEffect : public GrGLFragmentProcessor { |
254 public: | 254 public: |
255 GrGLMorphologyEffect(const GrProcessor&); | 255 GrGLMorphologyEffect(const GrProcessor&); |
256 | 256 |
257 virtual void emitCode(EmitArgs&) override; | 257 virtual void emitCode(EmitArgs&) override; |
258 | 258 |
259 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); | 259 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessor
KeyBuilder* b); |
260 | 260 |
261 void setData(const GrGLProgramDataManager&, const GrProcessor&) override; | 261 protected: |
| 262 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; |
262 | 263 |
263 private: | 264 private: |
264 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 265 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
265 | 266 |
266 int fRadius; | 267 int fRadius; |
267 Gr1DKernelEffect::Direction fDirection; | 268 Gr1DKernelEffect::Direction fDirection; |
268 bool fUseRange; | 269 bool fUseRange; |
269 GrMorphologyEffect::MorphologyType fType; | 270 GrMorphologyEffect::MorphologyType fType; |
270 GrGLProgramDataManager::UniformHandle fPixelSizeUni; | 271 GrGLProgramDataManager::UniformHandle fPixelSizeUni; |
271 GrGLProgramDataManager::UniformHandle fRangeUni; | 272 GrGLProgramDataManager::UniformHandle fRangeUni; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, | 353 void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, |
353 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { | 354 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { |
354 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 355 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
355 uint32_t key = static_cast<uint32_t>(m.radius()); | 356 uint32_t key = static_cast<uint32_t>(m.radius()); |
356 key |= (m.type() << 8); | 357 key |= (m.type() << 8); |
357 key |= (m.direction() << 9); | 358 key |= (m.direction() << 9); |
358 if (m.useRange()) key |= 1 << 10; | 359 if (m.useRange()) key |= 1 << 10; |
359 b->add32(key); | 360 b->add32(key); |
360 } | 361 } |
361 | 362 |
362 void GrGLMorphologyEffect::setData(const GrGLProgramDataManager& pdman, | 363 void GrGLMorphologyEffect::onSetData(const GrGLProgramDataManager& pdman, |
363 const GrProcessor& proc) { | 364 const GrProcessor& proc) { |
364 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 365 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
365 GrTexture& texture = *m.texture(0); | 366 GrTexture& texture = *m.texture(0); |
366 // the code we generated was for a specific kernel radius, direction and bou
nd usage | 367 // the code we generated was for a specific kernel radius, direction and bou
nd usage |
367 SkASSERT(m.radius() == fRadius); | 368 SkASSERT(m.radius() == fRadius); |
368 SkASSERT(m.direction() == fDirection); | 369 SkASSERT(m.direction() == fDirection); |
369 SkASSERT(m.useRange() == fUseRange); | 370 SkASSERT(m.useRange() == fUseRange); |
370 | 371 |
371 float pixelSize = 0.0f; | 372 float pixelSize = 0.0f; |
372 switch (fDirection) { | 373 switch (fDirection) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 fRange[1] = range[1]; | 417 fRange[1] = range[1]; |
417 } | 418 } |
418 | 419 |
419 GrMorphologyEffect::~GrMorphologyEffect() { | 420 GrMorphologyEffect::~GrMorphologyEffect() { |
420 } | 421 } |
421 | 422 |
422 void GrMorphologyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessor
KeyBuilder* b) const { | 423 void GrMorphologyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessor
KeyBuilder* b) const { |
423 GrGLMorphologyEffect::GenKey(*this, caps, b); | 424 GrGLMorphologyEffect::GenKey(*this, caps, b); |
424 } | 425 } |
425 | 426 |
426 GrGLFragmentProcessor* GrMorphologyEffect::createGLInstance() const { | 427 GrGLFragmentProcessor* GrMorphologyEffect::onCreateGLInstance() const { |
427 return SkNEW_ARGS(GrGLMorphologyEffect, (*this)); | 428 return SkNEW_ARGS(GrGLMorphologyEffect, (*this)); |
428 } | 429 } |
429 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 430 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
430 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); | 431 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); |
431 return (this->radius() == s.radius() && | 432 return (this->radius() == s.radius() && |
432 this->direction() == s.direction() && | 433 this->direction() == s.direction() && |
433 this->useRange() == s.useRange() && | 434 this->useRange() == s.useRange() && |
434 this->type() == s.type()); | 435 this->type() == s.type()); |
435 } | 436 } |
436 | 437 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 SkBitmap* result, SkIPoint* offset) con
st { | 662 SkBitmap* result, SkIPoint* offset) con
st { |
662 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 663 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
663 } | 664 } |
664 | 665 |
665 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 666 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
666 SkBitmap* result, SkIPoint* offset) cons
t { | 667 SkBitmap* result, SkIPoint* offset) cons
t { |
667 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 668 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
668 } | 669 } |
669 | 670 |
670 #endif | 671 #endif |
OLD | NEW |