| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkPaintImageFilter.h" | 8 #include "SkPaintImageFilter.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 SkPaint paint; | 26 SkPaint paint; |
| 27 buffer.readPaint(&paint); | 27 buffer.readPaint(&paint); |
| 28 return Create(paint, &common.cropRect()); | 28 return Create(paint, &common.cropRect()); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void SkPaintImageFilter::flatten(SkWriteBuffer& buffer) const { | 31 void SkPaintImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 32 this->INHERITED::flatten(buffer); | 32 this->INHERITED::flatten(buffer); |
| 33 buffer.writePaint(fPaint); | 33 buffer.writePaint(fPaint); |
| 34 } | 34 } |
| 35 | 35 |
| 36 SkSpecialImage* SkPaintImageFilter::onFilterImage(SkSpecialImage* source, | 36 sk_sp<SkSpecialImage> SkPaintImageFilter::onFilterImage(SkSpecialImage* source, |
| 37 const Context& ctx, | 37 const Context& ctx, |
| 38 SkIPoint* offset) const { | 38 SkIPoint* offset) const
{ |
| 39 SkIRect bounds; | 39 SkIRect bounds; |
| 40 const SkIRect srcBounds = SkIRect::MakeWH(source->width(), source->height())
; | 40 const SkIRect srcBounds = SkIRect::MakeWH(source->width(), source->height())
; |
| 41 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { | 41 if (!this->applyCropRect(ctx, srcBounds, &bounds)) { |
| 42 return nullptr; | 42 return nullptr; |
| 43 } | 43 } |
| 44 | 44 |
| 45 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), | 45 SkImageInfo info = SkImageInfo::MakeN32(bounds.width(), bounds.height(), |
| 46 kPremul_SkAlphaType); | 46 kPremul_SkAlphaType); |
| 47 | 47 |
| 48 sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); | 48 sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 60 SkRect rect = SkRect::MakeIWH(bounds.width(), bounds.height()); | 60 SkRect rect = SkRect::MakeIWH(bounds.width(), bounds.height()); |
| 61 SkMatrix inverse; | 61 SkMatrix inverse; |
| 62 if (matrix.invert(&inverse)) { | 62 if (matrix.invert(&inverse)) { |
| 63 inverse.mapRect(&rect); | 63 inverse.mapRect(&rect); |
| 64 } | 64 } |
| 65 canvas->setMatrix(matrix); | 65 canvas->setMatrix(matrix); |
| 66 canvas->drawRect(rect, fPaint); | 66 canvas->drawRect(rect, fPaint); |
| 67 | 67 |
| 68 offset->fX = bounds.fLeft; | 68 offset->fX = bounds.fLeft; |
| 69 offset->fY = bounds.fTop; | 69 offset->fY = bounds.fTop; |
| 70 return surf->makeImageSnapshot().release(); | 70 return surf->makeImageSnapshot(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 bool SkPaintImageFilter::canComputeFastBounds() const { | 73 bool SkPaintImageFilter::canComputeFastBounds() const { |
| 74 // http:skbug.com/4627: "make computeFastBounds and onFilterBounds() CropRec
t-aware" | 74 // http:skbug.com/4627: "make computeFastBounds and onFilterBounds() CropRec
t-aware" |
| 75 // computeFastBounds() doesn't currently take the crop rect into account, | 75 // computeFastBounds() doesn't currently take the crop rect into account, |
| 76 // so we can't compute it. If a full crop rect is set, we should return true
here. | 76 // so we can't compute it. If a full crop rect is set, we should return true
here. |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 | 79 |
| 80 #ifndef SK_IGNORE_TO_STRING | 80 #ifndef SK_IGNORE_TO_STRING |
| 81 void SkPaintImageFilter::toString(SkString* str) const { | 81 void SkPaintImageFilter::toString(SkString* str) const { |
| 82 str->appendf("SkPaintImageFilter: ("); | 82 str->appendf("SkPaintImageFilter: ("); |
| 83 str->append(")"); | 83 str->append(")"); |
| 84 } | 84 } |
| 85 #endif | 85 #endif |
| OLD | NEW |