diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-12 19:02:53 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-12-12 19:02:53 +0000 |
commit | 68d61ed83ec7b6e98e9623c2f5c9e7b1a32d25bb (patch) | |
tree | 1462843b0770736314438d38676b3dd542bd9d1a /src/pipe | |
parent | 8cdf0f52ff395d4053f7ed5c20861c42eba25d31 (diff) |
make RRect and Oval first-class drawing primitives in SkCanvas.
add RRect as a first-class clip primitive.
Review URL: https://codereview.appspot.com/6923058
git-svn-id: http://skia.googlecode.com/svn/trunk@6762 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/pipe')
-rw-r--r-- | src/pipe/SkGPipePriv.h | 3 | ||||
-rw-r--r-- | src/pipe/SkGPipeRead.cpp | 29 | ||||
-rw-r--r-- | src/pipe/SkGPipeWrite.cpp | 40 |
3 files changed, 70 insertions, 2 deletions
diff --git a/src/pipe/SkGPipePriv.h b/src/pipe/SkGPipePriv.h index 31803ea9b5..b563652cb9 100644 --- a/src/pipe/SkGPipePriv.h +++ b/src/pipe/SkGPipePriv.h @@ -37,6 +37,7 @@ enum DrawOps { kClipPath_DrawOp, kClipRegion_DrawOp, kClipRect_DrawOp, + kClipRRect_DrawOp, kConcat_DrawOp, kDrawBitmap_DrawOp, kDrawBitmapMatrix_DrawOp, @@ -44,6 +45,7 @@ enum DrawOps { kDrawBitmapRectToRect_DrawOp, kDrawClear_DrawOp, kDrawData_DrawOp, + kDrawOval_DrawOp, kDrawPaint_DrawOp, kDrawPath_DrawOp, kDrawPicture_DrawOp, @@ -51,6 +53,7 @@ enum DrawOps { kDrawPosText_DrawOp, kDrawPosTextH_DrawOp, kDrawRect_DrawOp, + kDrawRRect_DrawOp, kDrawSprite_DrawOp, kDrawText_DrawOp, kDrawTextOnPath_DrawOp, diff --git a/src/pipe/SkGPipeRead.cpp b/src/pipe/SkGPipeRead.cpp index 1f13dafa7d..8a86c582c2 100644 --- a/src/pipe/SkGPipeRead.cpp +++ b/src/pipe/SkGPipeRead.cpp @@ -21,6 +21,7 @@ #include "SkOrderedReadBuffer.h" #include "SkPathEffect.h" #include "SkRasterizer.h" +#include "SkRRect.h" #include "SkShader.h" #include "SkTypeface.h" #include "SkXfermode.h" @@ -237,6 +238,14 @@ static void clipRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, canvas->clipRect(*rect, (SkRegion::Op)DrawOp_unpackData(op32), doAA); } +static void clipRRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, + SkGPipeState* state) { + SkRRect rrect; + reader->readRRect(&rrect); + bool doAA = SkToBool(DrawOp_unpackFlags(op32) & kClip_HasAntiAlias_DrawOpFlag); + canvas->clipRRect(rrect, (SkRegion::Op)DrawOp_unpackData(op32), doAA); +} + /////////////////////////////////////////////////////////////////////////////// static void setMatrix_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, @@ -332,6 +341,14 @@ static void drawPoints_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, } } +static void drawOval_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, + SkGPipeState* state) { + const SkRect* rect = skip<SkRect>(reader); + if (state->shouldDraw()) { + canvas->drawOval(*rect, state->paint()); + } +} + static void drawRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, SkGPipeState* state) { const SkRect* rect = skip<SkRect>(reader); @@ -340,6 +357,15 @@ static void drawRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, } } +static void drawRRect_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, + SkGPipeState* state) { + SkRRect rrect; + reader->readRRect(&rrect); + if (state->shouldDraw()) { + canvas->drawRRect(rrect, state->paint()); + } +} + static void drawPath_rp(SkCanvas* canvas, SkReader32* reader, uint32_t op32, SkGPipeState* state) { SkPath path; @@ -677,6 +703,7 @@ static const ReadProc gReadTable[] = { clipPath_rp, clipRegion_rp, clipRect_rp, + clipRRect_rp, concat_rp, drawBitmap_rp, drawBitmapMatrix_rp, @@ -684,6 +711,7 @@ static const ReadProc gReadTable[] = { drawBitmapRect_rp, drawClear_rp, drawData_rp, + drawOval_rp, drawPaint_rp, drawPath_rp, drawPicture_rp, @@ -691,6 +719,7 @@ static const ReadProc gReadTable[] = { drawPosText_rp, drawPosTextH_rp, drawRect_rp, + drawRRect_rp, drawSprite_rp, drawText_rp, drawTextOnPath_rp, diff --git a/src/pipe/SkGPipeWrite.cpp b/src/pipe/SkGPipeWrite.cpp index f0b4e0aee6..cfd1e7ceef 100644 --- a/src/pipe/SkGPipeWrite.cpp +++ b/src/pipe/SkGPipeWrite.cpp @@ -21,12 +21,17 @@ #include "SkPathEffect.h" #include "SkPictureFlat.h" #include "SkRasterizer.h" +#include "SkRRect.h" #include "SkShader.h" #include "SkStream.h" #include "SkTSearch.h" #include "SkTypeface.h" #include "SkWriter32.h" +enum { + kSizeOfFlatRRect = sizeof(SkRect) + 4 * sizeof(SkVector) +}; + static bool isCrossProcess(uint32_t flags) { return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag); } @@ -208,8 +213,8 @@ public: virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; - virtual bool clipRect(const SkRect& rect, SkRegion::Op op, - bool doAntiAlias = false) SK_OVERRIDE; + virtual bool clipRect(const SkRect&, SkRegion::Op op, bool doAntiAlias = false) SK_OVERRIDE; + virtual bool clipRRect(const SkRRect&, SkRegion::Op op, bool doAntiAlias = false) SK_OVERRIDE; virtual bool clipPath(const SkPath& path, SkRegion::Op op, bool doAntiAlias = false) SK_OVERRIDE; virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE; @@ -217,7 +222,9 @@ public: virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) SK_OVERRIDE; + virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; virtual void drawRect(const SkRect& rect, 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&, SkScalar left, SkScalar top, const SkPaint*) SK_OVERRIDE; @@ -625,6 +632,17 @@ bool SkGPipeCanvas::clipRect(const SkRect& rect, SkRegion::Op rgnOp, return this->INHERITED::clipRect(rect, rgnOp, doAntiAlias); } +bool SkGPipeCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op rgnOp, + bool doAntiAlias) { + NOTIFY_SETUP(this); + if (this->needOpBytes(kSizeOfFlatRRect)) { + unsigned flags = doAntiAlias & kClip_HasAntiAlias_DrawOpFlag; + this->writeOp(kClipRRect_DrawOp, flags, rgnOp); + fWriter.writeRRect(rrect); + } + return this->INHERITED::clipRRect(rrect, rgnOp, doAntiAlias); +} + bool SkGPipeCanvas::clipPath(const SkPath& path, SkRegion::Op rgnOp, bool doAntiAlias) { NOTIFY_SETUP(this); @@ -683,6 +701,15 @@ void SkGPipeCanvas::drawPoints(PointMode mode, size_t count, } } +void SkGPipeCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { + NOTIFY_SETUP(this); + this->writePaint(paint); + if (this->needOpBytes(sizeof(SkRect))) { + this->writeOp(kDrawOval_DrawOp); + fWriter.writeRect(rect); + } +} + void SkGPipeCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); @@ -692,6 +719,15 @@ void SkGPipeCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { } } +void SkGPipeCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { + NOTIFY_SETUP(this); + this->writePaint(paint); + if (this->needOpBytes(kSizeOfFlatRRect)) { + this->writeOp(kDrawRRect_DrawOp); + fWriter.writeRRect(rrect); + } +} + void SkGPipeCanvas::drawPath(const SkPath& path, const SkPaint& paint) { NOTIFY_SETUP(this); this->writePaint(paint); |