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" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 SkImageFilter* input) | 244 SkImageFilter* input) |
245 : INHERITED(1, &input) | 245 : INHERITED(1, &input) |
246 , fRegion(region) | 246 , fRegion(region) |
247 , fInnerThreshold(innerThreshold) | 247 , fInnerThreshold(innerThreshold) |
248 , fOuterThreshold(outerThreshold) { | 248 , fOuterThreshold(outerThreshold) { |
249 } | 249 } |
250 | 250 |
251 #if SK_SUPPORT_GPU | 251 #if SK_SUPPORT_GPU |
252 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, | 252 bool SkAlphaThresholdFilterImpl::asFragmentProcessor(GrFragmentProcessor** fp, |
253 GrTexture* texture, | 253 GrTexture* texture, |
254 const SkMatrix& in_matrix, | 254 const SkMatrix& inMatrix, |
255 const SkIRect&) const { | 255 const SkIRect&) const { |
256 if (fp) { | 256 if (fp) { |
257 GrContext* context = texture->getContext(); | 257 GrContext* context = texture->getContext(); |
258 GrSurfaceDesc maskDesc; | 258 GrSurfaceDesc maskDesc; |
259 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false))
{ | 259 if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false))
{ |
260 maskDesc.fConfig = kAlpha_8_GrPixelConfig; | 260 maskDesc.fConfig = kAlpha_8_GrPixelConfig; |
261 } else { | 261 } else { |
262 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; | 262 maskDesc.fConfig = kRGBA_8888_GrPixelConfig; |
263 } | 263 } |
264 maskDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 264 maskDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
265 // Add one pixel of border to ensure that clamp mode will be all zeros | 265 // Add one pixel of border to ensure that clamp mode will be all zeros |
266 // the outside. | 266 // the outside. |
267 maskDesc.fWidth = texture->width(); | 267 maskDesc.fWidth = texture->width(); |
268 maskDesc.fHeight = texture->height(); | 268 maskDesc.fHeight = texture->height(); |
269 SkAutoTUnref<GrTexture> maskTexture( | 269 SkAutoTUnref<GrTexture> maskTexture( |
270 context->textureProvider()->createApproxTexture(maskDesc)); | 270 context->textureProvider()->createApproxTexture(maskDesc)); |
271 if (!maskTexture) { | 271 if (!maskTexture) { |
272 return false; | 272 return false; |
273 } | 273 } |
274 | 274 |
275 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext()); | 275 SkAutoTUnref<GrDrawContext> drawContext( |
| 276 context->drawContext(maskTexture->as
RenderTarget())); |
276 if (drawContext) { | 277 if (drawContext) { |
277 GrPaint grPaint; | 278 GrPaint grPaint; |
278 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 279 grPaint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
279 SkRegion::Iterator iter(fRegion); | 280 SkRegion::Iterator iter(fRegion); |
280 drawContext->clear(maskTexture->asRenderTarget(), nullptr, 0x0, true
); | 281 drawContext->clear(nullptr, 0x0, true); |
281 | 282 |
282 while (!iter.done()) { | 283 while (!iter.done()) { |
283 SkRect rect = SkRect::Make(iter.rect()); | 284 SkRect rect = SkRect::Make(iter.rect()); |
284 drawContext->drawRect(maskTexture->asRenderTarget(), GrClip::Wid
eOpen(), grPaint, | 285 drawContext->drawRect(GrClip::WideOpen(), grPaint, inMatrix, rec
t); |
285 in_matrix, rect); | |
286 iter.next(); | 286 iter.next(); |
287 } | 287 } |
288 } | 288 } |
289 | 289 |
290 *fp = AlphaThresholdEffect::Create(texture, | 290 *fp = AlphaThresholdEffect::Create(texture, |
291 maskTexture, | 291 maskTexture, |
292 fInnerThreshold, | 292 fInnerThreshold, |
293 fOuterThreshold); | 293 fOuterThreshold); |
294 } | 294 } |
295 return true; | 295 return true; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 366 } |
367 | 367 |
368 #ifndef SK_IGNORE_TO_STRING | 368 #ifndef SK_IGNORE_TO_STRING |
369 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { | 369 void SkAlphaThresholdFilterImpl::toString(SkString* str) const { |
370 str->appendf("SkAlphaThresholdImageFilter: ("); | 370 str->appendf("SkAlphaThresholdImageFilter: ("); |
371 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); | 371 str->appendf("inner: %f outer: %f", fInnerThreshold, fOuterThreshold); |
372 str->append(")"); | 372 str->append(")"); |
373 } | 373 } |
374 #endif | 374 #endif |
375 | 375 |
OLD | NEW |