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 "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 #include "SkMorphology_opts.h" | 14 #include "SkMorphology_opts.h" |
15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
16 #include "GrContext.h" | 16 #include "GrContext.h" |
17 #include "GrInvariantOutput.h" | 17 #include "GrInvariantOutput.h" |
18 #include "GrTexture.h" | 18 #include "GrTexture.h" |
19 #include "GrTBackendProcessorFactory.h" | 19 #include "effects/Gr1DKernelEffect.h" |
20 #include "gl/GrGLProcessor.h" | 20 #include "gl/GrGLProcessor.h" |
21 #include "gl/builders/GrGLProgramBuilder.h" | 21 #include "gl/builders/GrGLProgramBuilder.h" |
22 #include "effects/Gr1DKernelEffect.h" | |
23 #endif | 22 #endif |
24 | 23 |
25 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, | 24 SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, |
26 int radiusY, | 25 int radiusY, |
27 SkImageFilter* input, | 26 SkImageFilter* input, |
28 const CropRect* cropRect, | 27 const CropRect* cropRect, |
29 uint32_t uniqueID) | 28 uint32_t uniqueID) |
30 : INHERITED(1, &input, cropRect, uniqueID), fRadius(SkISize::Make(radiusX, r
adiusY)) { | 29 : INHERITED(1, &input, cropRect, uniqueID), fRadius(SkISize::Make(radiusX, r
adiusY)) { |
31 } | 30 } |
32 | 31 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 SkFlattenable* SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) { | 260 SkFlattenable* SkDilateImageFilter::CreateProc(SkReadBuffer& buffer) { |
262 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 261 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
263 const int width = buffer.readInt(); | 262 const int width = buffer.readInt(); |
264 const int height = buffer.readInt(); | 263 const int height = buffer.readInt(); |
265 return Create(width, height, common.getInput(0), &common.cropRect(), common.
uniqueID()); | 264 return Create(width, height, common.getInput(0), &common.cropRect(), common.
uniqueID()); |
266 } | 265 } |
267 | 266 |
268 #if SK_SUPPORT_GPU | 267 #if SK_SUPPORT_GPU |
269 | 268 |
270 /////////////////////////////////////////////////////////////////////////////// | 269 /////////////////////////////////////////////////////////////////////////////// |
271 | |
272 class GrGLMorphologyEffect; | |
273 | |
274 /** | 270 /** |
275 * Morphology effects. Depending upon the type of morphology, either the | 271 * Morphology effects. Depending upon the type of morphology, either the |
276 * component-wise min (Erode_Type) or max (Dilate_Type) of all pixels in the | 272 * component-wise min (Erode_Type) or max (Dilate_Type) of all pixels in the |
277 * kernel is selected as the new color. The new color is modulated by the input | 273 * kernel is selected as the new color. The new color is modulated by the input |
278 * color. | 274 * color. |
279 */ | 275 */ |
280 class GrMorphologyEffect : public Gr1DKernelEffect { | 276 class GrMorphologyEffect : public Gr1DKernelEffect { |
281 | 277 |
282 public: | 278 public: |
283 | 279 |
284 enum MorphologyType { | 280 enum MorphologyType { |
285 kErode_MorphologyType, | 281 kErode_MorphologyType, |
286 kDilate_MorphologyType, | 282 kDilate_MorphologyType, |
287 }; | 283 }; |
288 | 284 |
289 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius
, | 285 static GrFragmentProcessor* Create(GrTexture* tex, Direction dir, int radius
, |
290 MorphologyType type) { | 286 MorphologyType type) { |
291 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type)); | 287 return SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type)); |
292 } | 288 } |
293 | 289 |
294 virtual ~GrMorphologyEffect(); | 290 virtual ~GrMorphologyEffect(); |
295 | 291 |
296 MorphologyType type() const { return fType; } | 292 MorphologyType type() const { return fType; } |
297 | 293 |
298 static const char* Name() { return "Morphology"; } | 294 virtual const char* name() const SK_OVERRIDE { return "Morphology"; } |
299 | 295 |
300 typedef GrGLMorphologyEffect GLProcessor; | 296 virtual void getGLProcessorKey(const GrGLCaps&, GrProcessorKeyBuilder*) cons
t SK_OVERRIDE; |
301 | 297 |
302 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; | 298 virtual GrGLFragmentProcessor* createGLInstance() const SK_OVERRIDE; |
| 299 |
| 300 virtual uint32_t classID() const { |
| 301 static uint32_t id = GenClassID(); |
| 302 return id; |
| 303 } |
303 | 304 |
304 protected: | 305 protected: |
305 | 306 |
306 MorphologyType fType; | 307 MorphologyType fType; |
307 | 308 |
308 private: | 309 private: |
309 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 310 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
310 | 311 |
311 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; | 312 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; |
312 | 313 |
313 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); | 314 GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); |
314 | 315 |
315 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 316 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
316 | 317 |
317 typedef Gr1DKernelEffect INHERITED; | 318 typedef Gr1DKernelEffect INHERITED; |
318 }; | 319 }; |
319 | 320 |
320 /////////////////////////////////////////////////////////////////////////////// | 321 /////////////////////////////////////////////////////////////////////////////// |
321 | 322 |
322 class GrGLMorphologyEffect : public GrGLFragmentProcessor { | 323 class GrGLMorphologyEffect : public GrGLFragmentProcessor { |
323 public: | 324 public: |
324 GrGLMorphologyEffect (const GrBackendProcessorFactory&, const GrProcessor&); | 325 GrGLMorphologyEffect(const GrProcessor&); |
325 | 326 |
326 virtual void emitCode(GrGLFPBuilder*, | 327 virtual void emitCode(GrGLFPBuilder*, |
327 const GrFragmentProcessor&, | 328 const GrFragmentProcessor&, |
328 const char* outputColor, | 329 const char* outputColor, |
329 const char* inputColor, | 330 const char* inputColor, |
330 const TransformedCoordsArray&, | 331 const TransformedCoordsArray&, |
331 const TextureSamplerArray&) SK_OVERRIDE; | 332 const TextureSamplerArray&) SK_OVERRIDE; |
332 | 333 |
333 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); | 334 static inline void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKe
yBuilder* b); |
334 | 335 |
335 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; | 336 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
336 | 337 |
337 private: | 338 private: |
338 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } | 339 int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } |
339 | 340 |
340 int fRadius; | 341 int fRadius; |
341 GrMorphologyEffect::MorphologyType fType; | 342 GrMorphologyEffect::MorphologyType fType; |
342 GrGLProgramDataManager::UniformHandle fImageIncrementUni; | 343 GrGLProgramDataManager::UniformHandle fImageIncrementUni; |
343 | 344 |
344 typedef GrGLFragmentProcessor INHERITED; | 345 typedef GrGLFragmentProcessor INHERITED; |
345 }; | 346 }; |
346 | 347 |
347 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendProcessorFactory& fact
ory, | 348 GrGLMorphologyEffect::GrGLMorphologyEffect(const GrProcessor& proc) { |
348 const GrProcessor& proc) | |
349 : INHERITED(factory) { | |
350 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); | 349 const GrMorphologyEffect& m = proc.cast<GrMorphologyEffect>(); |
351 fRadius = m.radius(); | 350 fRadius = m.radius(); |
352 fType = m.type(); | 351 fType = m.type(); |
353 } | 352 } |
354 | 353 |
355 void GrGLMorphologyEffect::emitCode(GrGLFPBuilder* builder, | 354 void GrGLMorphologyEffect::emitCode(GrGLFPBuilder* builder, |
356 const GrFragmentProcessor&, | 355 const GrFragmentProcessor&, |
357 const char* outputColor, | 356 const char* outputColor, |
358 const char* inputColor, | 357 const char* inputColor, |
359 const TransformedCoordsArray& coords, | 358 const TransformedCoordsArray& coords, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 Direction direction, | 425 Direction direction, |
427 int radius, | 426 int radius, |
428 MorphologyType type) | 427 MorphologyType type) |
429 : Gr1DKernelEffect(texture, direction, radius) | 428 : Gr1DKernelEffect(texture, direction, radius) |
430 , fType(type) { | 429 , fType(type) { |
431 } | 430 } |
432 | 431 |
433 GrMorphologyEffect::~GrMorphologyEffect() { | 432 GrMorphologyEffect::~GrMorphologyEffect() { |
434 } | 433 } |
435 | 434 |
436 const GrBackendFragmentProcessorFactory& GrMorphologyEffect::getFactory() const
{ | 435 void GrMorphologyEffect::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyB
uilder* b) const { |
437 return GrTBackendFragmentProcessorFactory<GrMorphologyEffect>::getInstance()
; | 436 GrGLMorphologyEffect::GenKey(*this, caps, b); |
438 } | 437 } |
439 | 438 |
| 439 GrGLFragmentProcessor* GrMorphologyEffect::createGLInstance() const { |
| 440 return SkNEW_ARGS(GrGLMorphologyEffect, (*this)); |
| 441 } |
440 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { | 442 bool GrMorphologyEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
441 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); | 443 const GrMorphologyEffect& s = sBase.cast<GrMorphologyEffect>(); |
442 return (this->radius() == s.radius() && | 444 return (this->radius() == s.radius() && |
443 this->direction() == s.direction() && | 445 this->direction() == s.direction() && |
444 this->type() == s.type()); | 446 this->type() == s.type()); |
445 } | 447 } |
446 | 448 |
447 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { | 449 void GrMorphologyEffect::onComputeInvariantOutput(GrInvariantOutput* inout) cons
t { |
448 // This is valid because the color components of the result of the kernel al
l come | 450 // This is valid because the color components of the result of the kernel al
l come |
449 // exactly from existing values in the source texture. | 451 // exactly from existing values in the source texture. |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 SkBitmap* result, SkIPoint* offset) con
st { | 592 SkBitmap* result, SkIPoint* offset) con
st { |
591 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); | 593 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset); |
592 } | 594 } |
593 | 595 |
594 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, | 596 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
595 SkBitmap* result, SkIPoint* offset) cons
t { | 597 SkBitmap* result, SkIPoint* offset) cons
t { |
596 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); | 598 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset); |
597 } | 599 } |
598 | 600 |
599 #endif | 601 #endif |
OLD | NEW |