If the path is a rect, call drawRect to raster the geometry in SkCanvas::drawPath to get better performance.
Committed: http://code.google.com/p/skia/source/detail?r=11842
R=bsalomon@google.com
Review URL: https://codereview.chromium.org/23484007
git-svn-id: http://skia.googlecode.com/svn/trunk/include@11904 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/core/SkCanvas.h b/core/SkCanvas.h
index dc3953e..6869585 100644
--- a/core/SkCanvas.h
+++ b/core/SkCanvas.h
@@ -575,16 +575,20 @@
will be filled or stroked based on the Style in the paint.
@param rect The rect to be drawn
@param paint The paint used to draw the rect
+
+ Overriding this function is deprecated. It will be made non-virtual
+ soon. Instead override onDrawRect.
*/
- virtual void drawRect(const SkRect& rect, const SkPaint& paint);
+ virtual void drawRect(const SkRect& rect, const SkPaint& paint) {
+ this->onDrawRect(rect, paint);
+ }
/** Draw the specified rectangle using the specified paint. The rectangle
will be filled or framed based on the Style in the paint.
@param rect The rect to be drawn
@param paint The paint used to draw the rect
*/
- void drawIRect(const SkIRect& rect, const SkPaint& paint)
- {
+ void drawIRect(const SkIRect& rect, const SkPaint& paint) {
SkRect r;
r.set(rect); // promotes the ints to scalars
this->drawRect(r, paint);
@@ -656,8 +660,18 @@
filled or framed based on the Style in the paint.
@param path The path to be drawn
@param paint The paint used to draw the path
+
+ Overriding this function is deprecated. It will be made non-virtual
+ soon. Instead override onDrawRect.
*/
- virtual void drawPath(const SkPath& path, const SkPaint& paint);
+ virtual void drawPath(const SkPath& path, const SkPaint& paint) {
+ SkRect rect;
+ if (path.isRect(&rect) && !path.isInverseFillType()) {
+ this->onDrawRect(rect, paint);
+ } else {
+ this->onDrawPath(path, paint);
+ }
+ }
/** Draw the specified bitmap, with its top/left corner at (x,y), using the
specified paint, transformed by the current matrix. Note: if the paint
@@ -1034,6 +1048,10 @@
// can perform copy-on-write or invalidate any cached images
void predrawNotify();
+ virtual void onDrawRect(const SkRect& rect, const SkPaint& paint);
+
+ virtual void onDrawPath(const SkPath& path, const SkPaint& paint);
+
/** DEPRECATED -- use constructor(device)
Marked as 'protected' to avoid new clients using this before we can
diff --git a/utils/SkDeferredCanvas.h b/utils/SkDeferredCanvas.h
index c0613ed..052c667 100644
--- a/utils/SkDeferredCanvas.h
+++ b/utils/SkDeferredCanvas.h
@@ -162,10 +162,7 @@
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) SK_OVERRIDE;
virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawPath(const SkPath& path, const SkPaint& paint)
- SK_OVERRIDE;
virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left,
SkScalar top, const SkPaint* paint)
SK_OVERRIDE;
@@ -234,6 +231,8 @@
};
protected:
+ virtual void onDrawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
+ virtual void onDrawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
virtual SkCanvas* canvasForDrawIter();
DeferredDevice* getDeferredDevice() const;
diff --git a/utils/SkDumpCanvas.h b/utils/SkDumpCanvas.h
index 96b45e7..d3ff9a1 100644
--- a/utils/SkDumpCanvas.h
+++ b/utils/SkDumpCanvas.h
@@ -93,9 +93,7 @@
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) SK_OVERRIDE;
virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint) SK_OVERRIDE;
virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
@@ -126,6 +124,10 @@
virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE;
virtual void endCommentGroup() SK_OVERRIDE;
+protected:
+ virtual void onDrawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
+ virtual void onDrawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
+
private:
Dumper* fDumper;
int fNestLevel; // for nesting recursive elements like pictures
diff --git a/utils/SkLuaCanvas.h b/utils/SkLuaCanvas.h
index c34d134..b604d3c 100644
--- a/utils/SkLuaCanvas.h
+++ b/utils/SkLuaCanvas.h
@@ -42,9 +42,7 @@
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) SK_OVERRIDE;
virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint) SK_OVERRIDE;
virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
@@ -72,6 +70,10 @@
const SkPaint& paint) SK_OVERRIDE;
virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
+protected:
+ virtual void onDrawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
+ virtual void onDrawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
+
private:
lua_State* fL;
SkString fFunc;
diff --git a/utils/SkNWayCanvas.h b/utils/SkNWayCanvas.h
index c48bcab..6791c51 100644
--- a/utils/SkNWayCanvas.h
+++ b/utils/SkNWayCanvas.h
@@ -43,9 +43,7 @@
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint&) SK_OVERRIDE;
virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE;
- virtual void drawRect(const SkRect&, const SkPaint&) SK_OVERRIDE;
virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE;
- virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint*) SK_OVERRIDE;
virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
@@ -80,6 +78,8 @@
virtual void endCommentGroup() SK_OVERRIDE;
protected:
+ virtual void onDrawRect(const SkRect&, const SkPaint&) SK_OVERRIDE;
+ virtual void onDrawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE;
SkTDArray<SkCanvas*> fList;
class Iter;
diff --git a/utils/SkProxyCanvas.h b/utils/SkProxyCanvas.h
index 383e532..54cdc3b 100644
--- a/utils/SkProxyCanvas.h
+++ b/utils/SkProxyCanvas.h
@@ -48,9 +48,7 @@
virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) SK_OVERRIDE;
virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE;
- virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
const SkPaint* paint = NULL) SK_OVERRIDE;
virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
@@ -85,6 +83,10 @@
virtual SkBounder* setBounder(SkBounder* bounder) SK_OVERRIDE;
virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
+protected:
+ virtual void onDrawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE;
+ virtual void onDrawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
+
private:
SkCanvas* fProxy;