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 "SkFlattenableBuffers.h" | 10 #include "SkReadBuffer.h" |
| 11 #include "SkWriteBuffer.h" |
11 #include "SkRegion.h" | 12 #include "SkRegion.h" |
12 | 13 |
13 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { | 14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { |
14 public: | 15 public: |
15 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
SkScalar outerThreshold); | 16 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold,
SkScalar outerThreshold); |
16 | 17 |
17 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) | 18 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkAlphaThresholdFilterIm
pl) |
18 | 19 |
19 protected: | 20 protected: |
20 explicit SkAlphaThresholdFilterImpl(SkFlattenableReadBuffer& buffer); | 21 explicit SkAlphaThresholdFilterImpl(SkReadBuffer& buffer); |
21 virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; | 22 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
22 | 23 |
23 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 24 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
24 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 25 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
25 #if SK_SUPPORT_GPU | 26 #if SK_SUPPORT_GPU |
26 virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, | 27 virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, |
27 const SkMatrix& matrix, const SkIRect& bounds) cons
t SK_OVERRIDE; | 28 const SkMatrix& matrix, const SkIRect& bounds) cons
t SK_OVERRIDE; |
28 #endif | 29 #endif |
29 | 30 |
30 private: | 31 private: |
31 SkRegion fRegion; | 32 SkRegion fRegion; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && | 224 if ((*validFlags & kA_GrColorComponentFlag) && 0xFF == GrColorUnpackA(*color
) && |
224 GrPixelConfigIsOpaque(this->texture(0)->config())) { | 225 GrPixelConfigIsOpaque(this->texture(0)->config())) { |
225 *validFlags = kA_GrColorComponentFlag; | 226 *validFlags = kA_GrColorComponentFlag; |
226 } else { | 227 } else { |
227 *validFlags = 0; | 228 *validFlags = 0; |
228 } | 229 } |
229 } | 230 } |
230 | 231 |
231 #endif | 232 #endif |
232 | 233 |
233 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkFlattenableReadBuffer&
buffer) | 234 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(SkReadBuffer& buffer) |
234 : INHERITED(1, buffer) { | 235 : INHERITED(1, buffer) { |
235 fInnerThreshold = buffer.readScalar(); | 236 fInnerThreshold = buffer.readScalar(); |
236 fOuterThreshold = buffer.readScalar(); | 237 fOuterThreshold = buffer.readScalar(); |
237 buffer.readRegion(&fRegion); | 238 buffer.readRegion(&fRegion); |
238 } | 239 } |
239 | 240 |
240 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region, | 241 SkAlphaThresholdFilterImpl::SkAlphaThresholdFilterImpl(const SkRegion& region, |
241 SkScalar innerThreshold, | 242 SkScalar innerThreshold, |
242 SkScalar outerThreshold) | 243 SkScalar outerThreshold) |
243 : INHERITED(0) | 244 : INHERITED(0) |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 289 |
289 *effect = AlphaThresholdEffect::Create(texture, | 290 *effect = AlphaThresholdEffect::Create(texture, |
290 maskTexture, | 291 maskTexture, |
291 fInnerThreshold, | 292 fInnerThreshold, |
292 fOuterThreshold); | 293 fOuterThreshold); |
293 } | 294 } |
294 return true; | 295 return true; |
295 } | 296 } |
296 #endif | 297 #endif |
297 | 298 |
298 void SkAlphaThresholdFilterImpl::flatten(SkFlattenableWriteBuffer& buffer) const
{ | 299 void SkAlphaThresholdFilterImpl::flatten(SkWriteBuffer& buffer) const { |
299 this->INHERITED::flatten(buffer); | 300 this->INHERITED::flatten(buffer); |
300 buffer.writeScalar(fInnerThreshold); | 301 buffer.writeScalar(fInnerThreshold); |
301 buffer.writeScalar(fOuterThreshold); | 302 buffer.writeScalar(fOuterThreshold); |
302 buffer.writeRegion(fRegion); | 303 buffer.writeRegion(fRegion); |
303 } | 304 } |
304 | 305 |
305 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src, | 306 bool SkAlphaThresholdFilterImpl::onFilterImage(Proxy*, const SkBitmap& src, |
306 const SkMatrix& matrix, SkBitmap*
dst, | 307 const SkMatrix& matrix, SkBitmap*
dst, |
307 SkIPoint* offset) { | 308 SkIPoint* offset) { |
308 SkASSERT(src.config() == SkBitmap::kARGB_8888_Config); | 309 SkASSERT(src.config() == SkBitmap::kARGB_8888_Config); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 (U8CPU)(SkColorGetG(source) *
scale), | 358 (U8CPU)(SkColorGetG(source) *
scale), |
358 (U8CPU)(SkColorGetB(source) *
scale)); | 359 (U8CPU)(SkColorGetB(source) *
scale)); |
359 } | 360 } |
360 } | 361 } |
361 dptr[y * dst->width() + x] = output_color; | 362 dptr[y * dst->width() + x] = output_color; |
362 } | 363 } |
363 } | 364 } |
364 | 365 |
365 return true; | 366 return true; |
366 } | 367 } |
OLD | NEW |