From 6a070dc06af4e9f305f9d08a69e34d18ade473cb Mon Sep 17 00:00:00 2001 From: reed Date: Tue, 11 Nov 2014 19:36:09 -0800 Subject: experimental BUG=skia: Review URL: https://codereview.chromium.org/716793004 --- include/core/SkCanvas.h | 7 +++- samplecode/SampleArc.cpp | 88 +++++++++++++++++++++++++++++------------------- src/core/SkCanvas.cpp | 14 ++++++++ 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 2445c6e60d..57a7913150 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -25,8 +25,9 @@ #define SK_LEGACY_DRAWTEXT_VIRTUAL #endif -class SkCanvasClipVisitor; class SkBaseDevice; +class SkCanvasClipVisitor; +class SkCanvasDrawable; class SkDraw; class SkDrawFilter; class SkImage; @@ -1069,6 +1070,8 @@ public: void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint); + void EXPERIMENTAL_drawDrawable(SkCanvasDrawable*); + /** Send a blob of data to the canvas. For canvases that draw, this call is effectively a no-op, as the data is not parsed, but just ignored. However, this call exists for @@ -1254,6 +1257,8 @@ protected: virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkXfermode* xmode, const SkPaint& paint); + virtual void onDrawDrawable(SkCanvasDrawable*); + enum ClipEdgeStyle { kHard_ClipEdgeStyle, kSoft_ClipEdgeStyle diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp index 8209c3b764..c9310d6dd6 100644 --- a/samplecode/SampleArc.cpp +++ b/samplecode/SampleArc.cpp @@ -22,6 +22,8 @@ #include "SkColorFilter.h" #include "SkLayerRasterizer.h" +#include "SkCanvasDrawable.h" + #include "SkParsePath.h" static void testparse() { SkRect r; @@ -36,11 +38,58 @@ static void testparse() { } class ArcsView : public SampleView { + class MyDrawable : public SkCanvasDrawable { + SkRect fR; + SkScalar fSweep; + public: + MyDrawable(const SkRect& r) : fR(r), fSweep(0) { + } + + void setSweep(SkScalar sweep) { + if (fSweep != sweep) { + fSweep = sweep; + this->notifyDrawingChanged(); + } + } + + void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStrokeWidth(SkIntToScalar(2)); + + paint.setStyle(SkPaint::kFill_Style); + paint.setColor(0x800000FF); + canvas->drawArc(fR, 0, fSweep, true, paint); + + paint.setColor(0x800FF000); + canvas->drawArc(fR, 0, fSweep, false, paint); + + paint.setStyle(SkPaint::kStroke_Style); + paint.setColor(SK_ColorRED); + canvas->drawArc(fR, 0, fSweep, true, paint); + + paint.setStrokeWidth(0); + paint.setColor(SK_ColorBLUE); + canvas->drawArc(fR, 0, fSweep, false, paint); + } + }; + public: + SkRect fRect; + MyDrawable* fDrawable; + ArcsView() { testparse(); fSweep = SkIntToScalar(100); this->setBGColor(0xFFDDDDDD); + + fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); + fRect.offset(SkIntToScalar(20), SkIntToScalar(20)); + fDrawable = SkNEW_ARGS(MyDrawable, (fRect)); + } + + virtual ~ArcsView() SK_OVERRIDE { + fDrawable->unref(); } protected: @@ -121,48 +170,17 @@ protected: } virtual void onDrawContent(SkCanvas* canvas) { - fSweep = SampleCode::GetAnimScalar(SkIntToScalar(360)/24, - SkIntToScalar(360)); -// fSweep = 359.99f; + fDrawable->setSweep(SampleCode::GetAnimScalar(SkIntToScalar(360)/24, + SkIntToScalar(360))); - SkRect r; SkPaint paint; - paint.setAntiAlias(true); paint.setStrokeWidth(SkIntToScalar(2)); paint.setStyle(SkPaint::kStroke_Style); - r.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); - r.offset(SkIntToScalar(20), SkIntToScalar(20)); - - if (false) { - const SkScalar d = SkIntToScalar(3); - const SkScalar rad[] = { d, d, d, d, d, d, d, d }; - SkPath path; - path.addRoundRect(r, rad); - canvas->drawPath(path, paint); - return; - } - - drawRectWithLines(canvas, r, paint); - - // printf("----- sweep %g %X\n", SkScalarToFloat(fSweep), SkDegreesToRadians(fSweep)); - - - paint.setStyle(SkPaint::kFill_Style); - paint.setColor(0x800000FF); - canvas->drawArc(r, 0, fSweep, true, paint); - - paint.setColor(0x800FF000); - canvas->drawArc(r, 0, fSweep, false, paint); - - paint.setStyle(SkPaint::kStroke_Style); - paint.setColor(SK_ColorRED); - canvas->drawArc(r, 0, fSweep, true, paint); + drawRectWithLines(canvas, fRect, paint); - paint.setStrokeWidth(0); - paint.setColor(SK_ColorBLUE); - canvas->drawArc(r, 0, fSweep, false, paint); + canvas->EXPERIMENTAL_drawDrawable(fDrawable); drawArcs(canvas); this->inval(NULL); diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 2d9b55929b..ead844fcc1 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -6,6 +6,7 @@ */ #include "SkCanvas.h" +#include "SkCanvasDrawable.h" #include "SkCanvasPriv.h" #include "SkBitmapDevice.h" #include "SkDeviceImageFilterProxy.h" @@ -2304,6 +2305,19 @@ void SkCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], LOOPER_END } +void SkCanvas::EXPERIMENTAL_drawDrawable(SkCanvasDrawable* dr) { + if (dr) { + SkRect bounds; + if (!dr->getBounds(&bounds) || !this->quickReject(bounds)) { + this->onDrawDrawable(dr); + } + } +} + +void SkCanvas::onDrawDrawable(SkCanvasDrawable* dr) { + dr->draw(this); +} + ////////////////////////////////////////////////////////////////////////////// // These methods are NOT virtual, and therefore must call back into virtual // methods, rather than actually drawing themselves. -- cgit v1.2.3