Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: src/core/SkCanvas.cpp

Issue 2205273003: Add onDrawBitmapLattice(), avoid unnecessary bitmap->image copy (Closed) Base URL: https://skia.googlesource.com/skia.git@copypaste
Patch Set: Add support for SkLiteRecorder Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkCanvas.cpp
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 80ff34d417e3a08f08fcda4e41e8c1d52e2617d5..539fd36028ac214dad18d49df808b34b6a187ea9 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -2057,6 +2057,19 @@ void SkCanvas::drawImageNine(const SkImage* image, const SkIRect& center, const
}
}
+void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
+ const SkPaint* paint) {
+ RETURN_ON_NULL(image);
+ if (dst.isEmpty()) {
+ return;
+ }
+ if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) {
+ this->onDrawImageLattice(image, lattice, dst, paint);
+ } else {
+ this->drawImageRect(image, dst, paint);
+ }
+}
+
void SkCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, const SkPaint* paint) {
if (bitmap.drawsNothing()) {
return;
@@ -2093,25 +2106,17 @@ void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
} else {
this->drawBitmapRect(bitmap, dst, paint);
}
-
}
void SkCanvas::drawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, const SkRect& dst,
const SkPaint* paint) {
- sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
- this->drawImageLattice(image.get(), lattice, dst, paint);
-}
-
-void SkCanvas::drawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
- const SkPaint* paint) {
- RETURN_ON_NULL(image);
- if (dst.isEmpty()) {
+ if (bitmap.drawsNothing() || dst.isEmpty()) {
return;
}
- if (SkLatticeIter::Valid(image->width(), image->height(), lattice)) {
- this->onDrawImageLattice(image, lattice, dst, paint);
+ if (SkLatticeIter::Valid(bitmap.width(), bitmap.height(), lattice)) {
+ this->onDrawBitmapLattice(bitmap, lattice, dst, paint);
} else {
- this->drawImageRect(image, dst, paint);
+ this->drawBitmapRect(bitmap, dst, paint);
}
}
@@ -2419,29 +2424,6 @@ void SkCanvas::onDrawImage(const SkImage* image, SkScalar x, SkScalar y, const S
LOOPER_END
}
-void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
- const SkPaint* 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();
- }
-
- LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
-
- while (iter.next()) {
- iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint());
- }
-
- LOOPER_END
-}
-
void SkCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawImageRect()");
@@ -2612,6 +2594,52 @@ void SkCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, c
LOOPER_END
}
+void SkCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, const SkRect& dst,
+ const SkPaint* 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();
+ }
+
+ LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
+
+ while (iter.next()) {
+ iter.fDevice->drawImageLattice(iter, image, lattice, dst, looper.paint());
+ }
+
+ LOOPER_END
+}
+
+void SkCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice,
+ const SkRect& dst, const SkPaint* 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();
+ }
+
+ LOOPER_BEGIN(*paint, SkDrawFilter::kBitmap_Type, &dst)
+
+ while (iter.next()) {
+ iter.fDevice->drawBitmapLattice(iter, bitmap, lattice, dst, looper.paint());
+ }
+
+ LOOPER_END
+}
+
class SkDeviceFilteredPaint {
public:
SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) {
« no previous file with comments | « include/core/SkDevice.h ('k') | src/core/SkDevice.cpp » ('j') | src/core/SkLiteDL.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698