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

Unified Diff: src/utils/SkPaintFilterCanvas.cpp

Issue 1577933002: SkPaintFilterCanvas skip-draw support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: lazy paint copy + missing onDrawImageNine override Created 4 years, 11 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
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/utils/debugger/SkDebugCanvas.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkPaintFilterCanvas.cpp
diff --git a/src/utils/SkPaintFilterCanvas.cpp b/src/utils/SkPaintFilterCanvas.cpp
index ce1e4b7dbf2134f2ae5663c483c85ece9fe2adb3..0a5b7e66295fb6b6510c0760eea71b5cb492aab1 100644
--- a/src/utils/SkPaintFilterCanvas.cpp
+++ b/src/utils/SkPaintFilterCanvas.cpp
@@ -12,20 +12,24 @@
class SkPaintFilterCanvas::AutoPaintFilter {
public:
- AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint* paint) {
- if (paint) {
- canvas->onFilterPaint(fLazyPaint.set(*paint), type);
- }
+ AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint* paint)
+ : fOrigPaint(paint) {
+ fShouldDraw = canvas->onFilter(fOrigPaint, type, &fFilteredPaint);
}
- AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint& paint) {
- canvas->onFilterPaint(fLazyPaint.set(paint), type);
+ AutoPaintFilter(const SkPaintFilterCanvas* canvas, Type type, const SkPaint& paint)
+ : AutoPaintFilter(canvas, type, &paint) { }
+
+ const SkPaint* paint() const {
+ return fFilteredPaint.isValid() ? fFilteredPaint.get() : fOrigPaint;
}
- const SkPaint* paint() const { return fLazyPaint.getMaybeNull(); }
+ bool shouldDraw() const { return fShouldDraw; }
private:
- SkTLazy<SkPaint> fLazyPaint;
+ const SkPaint* fOrigPaint;
+ SkTLazy<SkPaint> fFilteredPaint;
+ bool fShouldDraw;
};
SkPaintFilterCanvas::SkPaintFilterCanvas(int width, int height) : INHERITED(width, height) { }
@@ -44,70 +48,102 @@ SkPaintFilterCanvas::SkPaintFilterCanvas(SkCanvas *canvas)
void SkPaintFilterCanvas::onDrawPaint(const SkPaint& paint) {
AutoPaintFilter apf(this, kPaint_Type, paint);
- this->INHERITED::onDrawPaint(*apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawPaint(*apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) {
AutoPaintFilter apf(this, kPoint_Type, paint);
- this->INHERITED::onDrawPoints(mode, count, pts, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawPoints(mode, count, pts, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) {
AutoPaintFilter apf(this, kRect_Type, paint);
- this->INHERITED::onDrawRect(rect, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawRect(rect, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
AutoPaintFilter apf(this, kRRect_Type, paint);
- this->INHERITED::onDrawRRect(rrect, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawRRect(rrect, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
const SkPaint& paint) {
AutoPaintFilter apf(this, kDRRect_Type, paint);
- this->INHERITED::onDrawDRRect(outer, inner, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawDRRect(outer, inner, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) {
AutoPaintFilter apf(this, kOval_Type, paint);
- this->INHERITED::onDrawOval(rect, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawOval(rect, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) {
AutoPaintFilter apf(this, kPath_Type, paint);
- this->INHERITED::onDrawPath(path, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawPath(path, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawBitmap(const SkBitmap& bm, SkScalar left, SkScalar top,
const SkPaint* paint) {
AutoPaintFilter apf(this, kBitmap_Type, paint);
- this->INHERITED::onDrawBitmap(bm, left, top, apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawBitmap(bm, left, top, apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawBitmapRect(const SkBitmap& bm, const SkRect* src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
AutoPaintFilter apf(this, kBitmap_Type, paint);
- this->INHERITED::onDrawBitmapRect(bm, src, dst, apf.paint(), constraint);
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawBitmapRect(bm, src, dst, apf.paint(), constraint);
+ }
+}
+
+void SkPaintFilterCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& center,
+ const SkRect& dst, const SkPaint* paint) {
+ AutoPaintFilter apf(this, kBitmap_Type, paint);
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawBitmapNine(bm, center, dst, apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top,
const SkPaint* paint) {
AutoPaintFilter apf(this, kBitmap_Type, paint);
- this->INHERITED::onDrawImage(image, left, top, apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawImage(image, left, top, apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawImageRect(const SkImage* image, const SkRect* src,
const SkRect& dst, const SkPaint* paint,
SrcRectConstraint constraint) {
AutoPaintFilter apf(this, kBitmap_Type, paint);
- this->INHERITED::onDrawImageRect(image, src, dst, apf.paint(), constraint);
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawImageRect(image, src, dst, apf.paint(), constraint);
+ }
}
-void SkPaintFilterCanvas::onDrawBitmapNine(const SkBitmap& bm, const SkIRect& center,
- const SkRect& dst, const SkPaint* paint) {
+void SkPaintFilterCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center,
+ const SkRect& dst, const SkPaint* paint) {
AutoPaintFilter apf(this, kBitmap_Type, paint);
- this->INHERITED::onDrawBitmapNine(bm, center, dst, apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawImageNine(image, center, dst, apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount,
@@ -116,49 +152,65 @@ void SkPaintFilterCanvas::onDrawVertices(VertexMode vmode, int vertexCount,
const uint16_t indices[], int indexCount,
const SkPaint& paint) {
AutoPaintFilter apf(this, kVertices_Type, paint);
- this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors, xmode, indices,
- indexCount, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawVertices(vmode, vertexCount, vertices, texs, colors, xmode, indices,
+ indexCount, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawPatch(const SkPoint cubics[], const SkColor colors[],
const SkPoint texCoords[], SkXfermode* xmode,
const SkPaint& paint) {
AutoPaintFilter apf(this, kPatch_Type, paint);
- this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawPatch(cubics, colors, texCoords, xmode, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* m,
const SkPaint* paint) {
AutoPaintFilter apf(this, kPicture_Type, paint);
- this->INHERITED::onDrawPicture(picture, m, apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawPicture(picture, m, apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
const SkPaint& paint) {
AutoPaintFilter apf(this, kText_Type, paint);
- this->INHERITED::onDrawText(text, byteLength, x, y, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawText(text, byteLength, x, y, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
const SkPaint& paint) {
AutoPaintFilter apf(this, kText_Type, paint);
- this->INHERITED::onDrawPosText(text, byteLength, pos, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawPosText(text, byteLength, pos, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
SkScalar constY, const SkPaint& paint) {
AutoPaintFilter apf(this, kText_Type, paint);
- this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawPosTextH(text, byteLength, xpos, constY, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
const SkMatrix* matrix, const SkPaint& paint) {
AutoPaintFilter apf(this, kText_Type, paint);
- this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawTextOnPath(text, byteLength, path, matrix, *apf.paint());
+ }
}
void SkPaintFilterCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
const SkPaint& paint) {
AutoPaintFilter apf(this, kTextBlob_Type, paint);
- this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint());
+ if (apf.shouldDraw()) {
+ this->INHERITED::onDrawTextBlob(blob, x, y, *apf.paint());
+ }
}
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/utils/debugger/SkDebugCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698