OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkColorFilter.h" | 8 #include "SkColorFilter.h" |
9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
10 #include "SkDraw.h" | 10 #include "SkDraw.h" |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 402 } |
403 | 403 |
404 ////////////////////////////////////////////////////////////////////////////////
////////// | 404 ////////////////////////////////////////////////////////////////////////////////
////////// |
405 | 405 |
406 void SkBaseDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitm
ap, | 406 void SkBaseDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitm
ap, |
407 int x, int y, | 407 int x, int y, |
408 const SkPaint& paint) { | 408 const SkPaint& paint) { |
409 SkImageFilter* filter = paint.getImageFilter(); | 409 SkImageFilter* filter = paint.getImageFilter(); |
410 SkASSERT(filter); | 410 SkASSERT(filter); |
411 | 411 |
412 if (!this->canHandleImageFilter(filter)) { | 412 SkImageFilter::DeviceProxy proxy(this); |
413 SkImageFilter::DeviceProxy proxy(this); | 413 SkIPoint offset = SkIPoint::Make(0, 0); |
414 SkIPoint offset = SkIPoint::Make(0, 0); | 414 SkMatrix matrix = *draw.fMatrix; |
415 SkMatrix matrix = *draw.fMatrix; | 415 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
416 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); | 416 const SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-x, -y); |
417 const SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-x, -y); | 417 SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache()); |
418 SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache()); | 418 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); |
419 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); | |
420 | 419 |
421 sk_sp<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(&proxy, bit
map, | 420 sk_sp<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(&proxy, bitmap, |
422 &this->surf
aceProps())); | 421 &this->surfaceP
rops())); |
423 if (!srcImg) { | 422 if (!srcImg) { |
424 return; // something disastrous happened | 423 return; // something disastrous happened |
| 424 } |
| 425 |
| 426 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offs
et)); |
| 427 if (resultImg) { |
| 428 SkPaint tmpUnfiltered(paint); |
| 429 tmpUnfiltered.setImageFilter(nullptr); |
| 430 SkBitmap resultBM; |
| 431 if (resultImg->internal_getBM(&resultBM)) { |
| 432 // TODO: add drawSprite(SkSpecialImage) to SkDevice? (see skbug.com/
5073) |
| 433 this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(), tmp
Unfiltered); |
425 } | 434 } |
426 | |
427 sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &
offset)); | |
428 if (resultImg) { | |
429 SkPaint tmpUnfiltered(paint); | |
430 tmpUnfiltered.setImageFilter(nullptr); | |
431 SkBitmap resultBM; | |
432 if (resultImg->internal_getBM(&resultBM)) { | |
433 // TODO: add drawSprite(SkSpecialImage) to SkDevice? (see skbug.
com/5073) | |
434 this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(),
tmpUnfiltered); | |
435 } | |
436 } | |
437 } else { | |
438 this->drawSprite(draw, bitmap, x, y, paint); | |
439 } | 435 } |
440 } | 436 } |
441 | 437 |
442 uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const { | 438 uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const { |
443 uint32_t flags = paint.getFlags(); | 439 uint32_t flags = paint.getFlags(); |
444 | 440 |
445 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { | 441 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
446 return flags; | 442 return flags; |
447 } | 443 } |
448 | 444 |
449 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() | 445 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() |
450 || this->onShouldDisableLCD(paint)) { | 446 || this->onShouldDisableLCD(paint)) { |
451 | 447 |
452 flags &= ~SkPaint::kLCDRenderText_Flag; | 448 flags &= ~SkPaint::kLCDRenderText_Flag; |
453 flags |= SkPaint::kGenA8FromLCD_Flag; | 449 flags |= SkPaint::kGenA8FromLCD_Flag; |
454 } | 450 } |
455 | 451 |
456 return flags; | 452 return flags; |
457 } | 453 } |
458 | 454 |
459 sk_sp<SkSurface> SkBaseDevice::makeSurface(SkImageInfo const&, SkSurfaceProps co
nst&) { | 455 sk_sp<SkSurface> SkBaseDevice::makeSurface(SkImageInfo const&, SkSurfaceProps co
nst&) { |
460 return nullptr; | 456 return nullptr; |
461 } | 457 } |
OLD | NEW |