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" |
11 #include "SkDrawFilter.h" | 11 #include "SkDrawFilter.h" |
12 #include "SkImage_Base.h" | 12 #include "SkImage_Base.h" |
13 #include "SkMetaData.h" | 13 #include "SkMetaData.h" |
14 #include "SkNinePatchIter.h" | 14 #include "SkNinePatchIter.h" |
15 #include "SkPatchUtils.h" | 15 #include "SkPatchUtils.h" |
16 #include "SkPathMeasure.h" | 16 #include "SkPathMeasure.h" |
17 #include "SkRasterClip.h" | 17 #include "SkRasterClip.h" |
18 #include "SkRSXform.h" | 18 #include "SkRSXform.h" |
19 #include "SkShader.h" | 19 #include "SkShader.h" |
20 #include "SkSpecialImage.h" | |
20 #include "SkTextBlobRunIterator.h" | 21 #include "SkTextBlobRunIterator.h" |
21 #include "SkTextToPathIter.h" | 22 #include "SkTextToPathIter.h" |
22 | 23 |
23 SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) | 24 SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) |
24 : fSurfaceProps(surfaceProps) | 25 : fSurfaceProps(surfaceProps) |
25 #ifdef SK_DEBUG | 26 #ifdef SK_DEBUG |
26 , fAttachedToCanvas(false) | 27 , fAttachedToCanvas(false) |
27 #endif | 28 #endif |
28 { | 29 { |
29 fOrigin.setZero(); | 30 fOrigin.setZero(); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
401 } | 402 } |
402 } | 403 } |
403 | 404 |
404 //////////////////////////////////////////////////////////////////////////////// ////////// | 405 //////////////////////////////////////////////////////////////////////////////// ////////// |
405 | 406 |
406 void SkBaseDevice::drawBitmapAsSprite(const SkDraw& draw, const SkBitmap& bitmap , int x, int y, | 407 void SkBaseDevice::drawBitmapAsSprite(const SkDraw& draw, const SkBitmap& bitmap , int x, int y, |
407 const SkPaint& paint) { | 408 const SkPaint& paint) { |
408 SkImageFilter* filter = paint.getImageFilter(); | 409 SkImageFilter* filter = paint.getImageFilter(); |
409 if (filter && !this->canHandleImageFilter(filter)) { | 410 if (filter && !this->canHandleImageFilter(filter)) { |
410 SkImageFilter::DeviceProxy proxy(this); | 411 SkImageFilter::DeviceProxy proxy(this); |
411 SkBitmap dst; | |
412 SkIPoint offset = SkIPoint::Make(0, 0); | 412 SkIPoint offset = SkIPoint::Make(0, 0); |
413 SkMatrix matrix = *draw.fMatrix; | 413 SkMatrix matrix = *draw.fMatrix; |
414 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); | 414 matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); |
415 const SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-x, -y); | 415 const SkIRect clipBounds = draw.fClip->getBounds().makeOffset(-x, -y); |
416 SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache()); | 416 SkAutoTUnref<SkImageFilter::Cache> cache(this->getImageFilterCache()); |
417 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); | 417 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); |
418 if (filter->filterImageDeprecated(&proxy, bitmap, ctx, &dst, &offset)) { | 418 |
419 SkAutoTUnref<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(&pro xy, bitmap)); | |
420 if (!srcImg) { | |
421 return; // something disastrous happened | |
422 } | |
423 | |
424 SkAutoTUnref<SkSpecialImage> resultImg(filter->filterImage(srcImg, ctx, &offset)); | |
425 if (resultImg) { | |
419 SkPaint tmpUnfiltered(paint); | 426 SkPaint tmpUnfiltered(paint); |
420 tmpUnfiltered.setImageFilter(nullptr); | 427 tmpUnfiltered.setImageFilter(nullptr); |
421 this->drawSprite(draw, dst, x + offset.x(), y + offset.y(), tmpUnfil tered); | 428 SkBitmap resultBM; |
429 if (resultImg->internal_getBM(&resultBM)) { | |
430 // TODO: add drawSprite(SkSpecialImage) to SkDevice? | |
Stephen White
2016/03/04 22:52:55
Nit: log a bug and reference it, or just remove th
robertphillips
2016/03/07 17:35:57
Done.
| |
431 this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(), tmpUnfiltered); | |
432 } | |
422 } | 433 } |
423 } else { | 434 } else { |
424 this->drawSprite(draw, bitmap, x, y, paint); | 435 this->drawSprite(draw, bitmap, x, y, paint); |
425 } | 436 } |
426 } | 437 } |
427 | 438 |
428 uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const { | 439 uint32_t SkBaseDevice::filterTextFlags(const SkPaint& paint) const { |
429 uint32_t flags = paint.getFlags(); | 440 uint32_t flags = paint.getFlags(); |
430 | 441 |
431 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { | 442 if (!paint.isLCDRenderText() || !paint.isAntiAlias()) { |
432 return flags; | 443 return flags; |
433 } | 444 } |
434 | 445 |
435 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() | 446 if (kUnknown_SkPixelGeometry == fSurfaceProps.pixelGeometry() |
436 || this->onShouldDisableLCD(paint)) { | 447 || this->onShouldDisableLCD(paint)) { |
437 | 448 |
438 flags &= ~SkPaint::kLCDRenderText_Flag; | 449 flags &= ~SkPaint::kLCDRenderText_Flag; |
439 flags |= SkPaint::kGenA8FromLCD_Flag; | 450 flags |= SkPaint::kGenA8FromLCD_Flag; |
440 } | 451 } |
441 | 452 |
442 return flags; | 453 return flags; |
443 } | 454 } |
444 | 455 |
OLD | NEW |