aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkCanvas.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-04-11 14:50:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-11 19:32:47 +0000
commitf441cfc5dfec7afe8f2d67785bb88b696f393f4c (patch)
tree596521f8d162083427d9530547b0de274b642e54 /src/core/SkCanvas.cpp
parent8540e110f91df1b1596bd66711e5ad908de1888a (diff)
Clean-up paints for drawImage (etc.) to enforce that we always
ignore stroking and patheffects. Bug: skia:7804 Change-Id: I0b5f3a6734c5e4201a6e3a2bd5e398d213c8950e Reviewed-on: https://skia-review.googlesource.com/120504 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/core/SkCanvas.cpp')
-rw-r--r--src/core/SkCanvas.cpp76
1 files changed, 43 insertions, 33 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 4eb735e469..803b370901 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -28,6 +28,7 @@
#include "SkNx.h"
#include "SkPaintPriv.h"
#include "SkPatchUtils.h"
+#include "SkPathEffect.h"
#include "SkPicture.h"
#include "SkRasterClip.h"
#include "SkRasterHandleAllocator.h"
@@ -2118,7 +2119,23 @@ bool SkCanvas::canDrawBitmapAsSprite(SkScalar x, SkScalar y, int w, int h, const
return ir.contains(fMCRec->fRasterClip.getBounds());
}
+// Given storage for a real paint, and an optional paint parameter, clean-up the param (if non-null)
+// given the drawing semantics for drawImage/bitmap (skbug.com/7804) and return it, or the original
+// null.
+static const SkPaint* init_image_paint(SkPaint* real, const SkPaint* paintParam) {
+ if (paintParam) {
+ *real = *paintParam;
+ real->setStyle(SkPaint::kFill_Style);
+ real->setPathEffect(nullptr);
+ paintParam = real;
+ }
+ return paintParam;
+}
+
void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const SkPaint* paint) {
+ SkPaint realPaint;
+ paint = init_image_paint(&realPaint, paint);
+
SkRect bounds = SkRect::MakeXYWH(x, y,
SkIntToScalar(image->width()), SkIntToScalar(image->height()));
if (nullptr == paint || paint->canComputeFastBounds()) {
@@ -2130,11 +2147,10 @@ void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S
return;
}
}
-
- SkLazyPaint lazy;
- if (nullptr == paint) {
- paint = lazy.init();
- }
+ // At this point we need a real paint object. If the caller passed null, then we should
+ // use realPaint (in its default state). If the caller did pass a paint, then we have copied
+ // (and modified) it in realPaint. Thus either way, "realPaint" is what we want to use.
+ paint = &realPaint;
sk_sp<SkSpecialImage> special;
bool drawAsSprite = this->canDrawBitmapAsSprite(x, y, image->width(), image->height(),
@@ -2167,6 +2183,9 @@ void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S
void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
+ SkPaint realPaint;
+ paint = init_image_paint(&realPaint, paint);
+
if (nullptr == paint || paint->canComputeFastBounds()) {
SkRect storage = dst;
if (paint) {
@@ -2176,10 +2195,7 @@ void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const Sk
return;
}
}
- SkLazyPaint lazy;
- if (nullptr == paint) {
- paint = lazy.init();
- }
+ paint = &realPaint;
LOOPER_BEGIN_CHECK_COMPLETE_OVERWRITE(*paint, SkDrawFilter::kBitmap_Type, &dst,
image->isOpaque())
@@ -2198,10 +2214,9 @@ void SkCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, cons
return;
}
- SkLazyPaint lazy;
- if (nullptr == paint) {
- paint = lazy.init();
- }
+ SkPaint realPaint;
+ init_image_paint(&realPaint, paint);
+ paint = &realPaint;
SkRect bounds;
bitmap.getBounds(&bounds);
@@ -2281,17 +2296,16 @@ void SkCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const
void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst,
const SkPaint* paint) {
+ SkPaint realPaint;
+ paint = init_image_paint(&realPaint, paint);
+
if (nullptr == paint || paint->canComputeFastBounds()) {
SkRect storage;
if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
return;
}
}
-
- SkLazyPaint lazy;
- if (nullptr == paint) {
- paint = lazy.init();
- }
+ paint = &realPaint;
LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
@@ -2305,6 +2319,8 @@ void SkCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, cons
void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
const SkPaint* paint) {
SkDEBUGCODE(bitmap.validate();)
+ SkPaint realPaint;
+ paint = init_image_paint(&realPaint, paint);
if (nullptr == paint || paint->canComputeFastBounds()) {
SkRect storage;
@@ -2312,11 +2328,7 @@ void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, c
return;
}
}
-
- SkLazyPaint lazy;
- if (nullptr == paint) {
- paint = lazy.init();
- }
+ paint = &realPaint;
LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
@@ -2329,17 +2341,16 @@ void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, c
void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint) {
+ SkPaint realPaint;
+ paint = init_image_paint(&realPaint, paint);
+
if (nullptr == paint || paint->canComputeFastBounds()) {
SkRect storage;
if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
return;
}
}
-
- SkLazyPaint lazy;
- if (nullptr == paint) {
- paint = lazy.init();
- }
+ paint = &realPaint;
LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
@@ -2352,17 +2363,16 @@ void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice,
void SkCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
const SkRect& dst, const SkPaint* paint) {
+ SkPaint realPaint;
+ paint = init_image_paint(&realPaint, paint);
+
if (nullptr == paint || paint->canComputeFastBounds()) {
SkRect storage;
if (this->quickReject(paint ? paint->computeFastBounds(dst, &storage) : dst)) {
return;
}
}
-
- SkLazyPaint lazy;
- if (nullptr == paint) {
- paint = lazy.init();
- }
+ paint = &realPaint;
LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)