OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "SkAlphaThresholdFilter.h" | 8 #include "SkAlphaThresholdFilter.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
12 #include "SkRegion.h" | 12 #include "SkRegion.h" |
13 | 13 |
14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { | 14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { |
15 public: | 15 public: |
16 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
SkScalar outerThreshold); | 16 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, |
| 17 SkScalar outerThreshold, SkImageFilter* input); |
17 | 18 |
18 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) | 19 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) |
19 | 20 |
20 protected: | 21 protected: |
21 explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer); | 22 explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer); |
22 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 23 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
23 | 24 |
24 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 25 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
25 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 26 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
26 #if SK_SUPPORT_GPU | 27 #if SK_SUPPORT_GPU |
27 virtual bool asNewEffect(GrEffect** effect, GrTexture* texture, | 28 virtual bool asNewEffect(GrEffect** effect, GrTexture* texture, |
28 const SkMatrix& matrix, const SkIRect& bounds) cons
t SK_OVERRIDE; | 29 const SkMatrix& matrix, const SkIRect& bounds) cons
t SK_OVERRIDE; |
29 #endif | 30 #endif |
30 | 31 |
31 private: | 32 private: |
32 SkRegion fRegion; | 33 SkRegion fRegion; |
33 SkScalar fInnerThreshold; | 34 SkScalar fInnerThreshold; |
34 SkScalar fOuterThreshold; | 35 SkScalar fOuterThreshold; |
35 typedef SkImageFilter INHERITED; | 36 typedef SkImageFilter INHERITED; |
36 }; | 37 }; |
37 | 38 |
38 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, | 39 SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, |
39 SkScalar innerThreshold, | 40 SkScalar innerThreshold, |
40 SkScalar outerThreshold) { | 41 SkScalar outerThreshold, |
41 return SkNEW_ARGS(SkAlphaThresholdFilterImpl, (region, innerThreshold, outer
Threshold)); | 42 SkImageFilter* input) { |
| 43 return SkNEW_ARGS(SkAlphaThresholdFilterImpl, (region, innerThreshold, outer
Threshold, input)); |
42 } | 44 } |
43 | 45 |
44 #if SK_SUPPORT_GPU | 46 #if SK_SUPPORT_GPU |
45 #include "GrContext.h" | 47 #include "GrContext.h" |
46 #include "GrCoordTransform.h" | 48 #include "GrCoordTransform.h" |
47 #include "GrEffect.h" | 49 #include "GrEffect.h" |
48 #include "gl/GrGLEffect.h" | 50 #include "gl/GrGLEffect.h" |
49 #include "GrTBackendEffectFactory.h" | 51 #include "GrTBackendEffectFactory.h" |
50 #include "GrTextureAccess.h" | 52 #include "GrTextureAccess.h" |
51 | 53 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 235 |
234 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkReadBuffer& buffer) | 236 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkReadBuffer& buffer) |
235 : INHERITED(1, buffer) { | 237 : INHERITED(1, buffer) { |
236 fInnerThreshold = buffer.readScalar(); | 238 fInnerThreshold = buffer.readScalar(); |
237 fOuterThreshold = buffer.readScalar(); | 239 fOuterThreshold = buffer.readScalar(); |
238 buffer.readRegion(&fRegion); | 240 buffer.readRegion(&fRegion); |
239 } | 241 } |
240 | 242 |
241 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region, | 243 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region, |
242 SkScalar innerThreshold, | 244 SkScalar innerThreshold, |
243 SkScalar outerThreshold) | 245 SkScalar outerThreshold, |
244 : INHERITED(0) | 246 SkImageFilter* input) |
| 247 : INHERITED(1, &input) |
245 , fRegion(region) | 248 , fRegion(region) |
246 , fInnerThreshold(innerThreshold) | 249 , fInnerThreshold(innerThreshold) |
247 , fOuterThreshold(outerThreshold) { | 250 , fOuterThreshold(outerThreshold) { |
248 } | 251 } |
249 | 252 |
250 #if SK_SUPPORT_GPU | 253 #if SK_SUPPORT_GPU |
251 bool SkAlphaThresholdFilterImpl::asNewEffect(GrEffect** effect, GrTexture* textu
re, | 254 bool SkAlphaThresholdFilterImpl::asNewEffect(GrEffect** effect, GrTexture* textu
re, |
252 const SkMatrix& in_matrix, const Sk
IRect&) const { | 255 const SkMatrix& in_matrix, const Sk
IRect&) const { |
253 if (effect) { | 256 if (effect) { |
254 GrContext* context = texture->getContext(); | 257 GrContext* context = texture->getContext(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 (U8CPU)(SkColorGetG(source) *
scale), | 360 (U8CPU)(SkColorGetG(source) *
scale), |
358 (U8CPU)(SkColorGetB(source) *
scale)); | 361 (U8CPU)(SkColorGetB(source) *
scale)); |
359 } | 362 } |
360 } | 363 } |
361 dptr[y * dst->width() + x] = output_color; | 364 dptr[y * dst->width() + x] = output_color; |
362 } | 365 } |
363 } | 366 } |
364 | 367 |
365 return true; | 368 return true; |
366 } | 369 } |
OLD | NEW |