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 "GrDrawContext.h" |
8 #include "SkAlphaThresholdFilter.h" | 9 #include "SkAlphaThresholdFilter.h" |
9 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
10 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
11 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
12 #include "SkRegion.h" | 13 #include "SkRegion.h" |
13 | 14 |
14 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { | 15 class SK_API SkAlphaThresholdFilterImpl : public SkImageFilter { |
15 public: | 16 public: |
16 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, | 17 SkAlphaThresholdFilterImpl(const SkRegion& region, SkScalar innerThreshold, |
17 SkScalar outerThreshold, SkImageFilter* input); | 18 SkScalar outerThreshold, SkImageFilter* input); |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // Add one pixel of border to ensure that clamp mode will be all zeros | 278 // Add one pixel of border to ensure that clamp mode will be all zeros |
278 // the outside. | 279 // the outside. |
279 maskDesc.fWidth = texture->width(); | 280 maskDesc.fWidth = texture->width(); |
280 maskDesc.fHeight = texture->height(); | 281 maskDesc.fHeight = texture->height(); |
281 SkAutoTUnref<GrTexture> maskTexture(context->textureProvider()->refScrat
chTexture( | 282 SkAutoTUnref<GrTexture> maskTexture(context->textureProvider()->refScrat
chTexture( |
282 maskDesc, GrTextureProvider::kApprox_ScratchTexMatch)); | 283 maskDesc, GrTextureProvider::kApprox_ScratchTexMatch)); |
283 if (!maskTexture) { | 284 if (!maskTexture) { |
284 return false; | 285 return false; |
285 } | 286 } |
286 | 287 |
287 { | 288 GrDrawContext* drawContext = context->drawContext(); |
| 289 if (drawContext) { |
288 GrPaint grPaint; | 290 GrPaint grPaint; |
289 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 291 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
290 SkRegion::Iterator iter(fRegion); | 292 SkRegion::Iterator iter(fRegion); |
291 context->clear(NULL, 0x0, true, maskTexture->asRenderTarget()); | 293 drawContext->clear(maskTexture->asRenderTarget(), NULL, 0x0, true); |
292 | 294 |
293 while (!iter.done()) { | 295 while (!iter.done()) { |
294 SkRect rect = SkRect::Make(iter.rect()); | 296 SkRect rect = SkRect::Make(iter.rect()); |
295 context->drawRect(maskTexture->asRenderTarget(), GrClip::WideOpe
n(), grPaint, | 297 drawContext->drawRect(maskTexture->asRenderTarget(), GrClip::Wid
eOpen(), grPaint, |
296 in_matrix, rect); | 298 in_matrix, rect); |
297 iter.next(); | 299 iter.next(); |
298 } | 300 } |
299 } | 301 } |
300 | 302 |
301 *fp = AlphaThresholdEffect::Create(texture, | 303 *fp = AlphaThresholdEffect::Create(texture, |
302 maskTexture, | 304 maskTexture, |
303 fInnerThreshold, | 305 fInnerThreshold, |
304 fOuterThreshold); | 306 fOuterThreshold); |
305 } | 307 } |
306 return true; | 308 return true; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 } | 379 } |
378 | 380 |
379 #ifndef SK_IGNORE_TO_STRING | 381 #ifndef SK_IGNORE_TO_STRING |
380 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 382 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
381 str->appendf("SkAlphaThresholdImageFilter: ("); | 383 str->appendf("SkAlphaThresholdImageFilter: ("); |
382 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 384 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
383 str->append(")"); | 385 str->append(")"); |
384 } | 386 } |
385 #endif | 387 #endif |
386 | 388 |
OLD | NEW |