flesh out more of SkLiteDL:
save layer, clips, simple draws BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2226513002 Review-Url: https://codereview.chromium.org/2226513002
This commit is contained in:
parent
9c5052f16b
commit
6f8411dfa4
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
|
#include "SkImageFilter.h"
|
||||||
#include "SkLiteDL.h"
|
#include "SkLiteDL.h"
|
||||||
#include "SkMutex.h"
|
#include "SkMutex.h"
|
||||||
#include "SkSpinlock.h"
|
#include "SkSpinlock.h"
|
||||||
@ -20,6 +21,22 @@ namespace {
|
|||||||
|
|
||||||
struct Save final : Op { void draw(SkCanvas* c) override { c-> save(); } };
|
struct Save final : Op { void draw(SkCanvas* c) override { c-> save(); } };
|
||||||
struct Restore final : Op { void draw(SkCanvas* c) override { c->restore(); } };
|
struct Restore final : Op { void draw(SkCanvas* c) override { c->restore(); } };
|
||||||
|
struct SaveLayer final : Op {
|
||||||
|
SaveLayer(const SkRect* bounds, const SkPaint* paint,
|
||||||
|
const SkImageFilter* backdrop, uint32_t flags) {
|
||||||
|
if (bounds) { this->bounds = *bounds; }
|
||||||
|
if (paint) { this->paint = *paint; }
|
||||||
|
this->backdrop = sk_ref_sp(backdrop);
|
||||||
|
this->flags = flags;
|
||||||
|
}
|
||||||
|
SkRect bounds = {SK_ScalarMin,SK_ScalarMin, SK_ScalarMax,SK_ScalarMax};
|
||||||
|
SkPaint paint;
|
||||||
|
sk_sp<const SkImageFilter> backdrop;
|
||||||
|
uint32_t flags;
|
||||||
|
void draw(SkCanvas* c) override {
|
||||||
|
c->saveLayer({ &bounds, &paint, backdrop.get(), flags });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct Concat final : Op {
|
struct Concat final : Op {
|
||||||
Concat(const SkMatrix& matrix) : matrix(matrix) {}
|
Concat(const SkMatrix& matrix) : matrix(matrix) {}
|
||||||
@ -32,6 +49,13 @@ namespace {
|
|||||||
void draw(SkCanvas* c) override { c->setMatrix(matrix); }
|
void draw(SkCanvas* c) override { c->setMatrix(matrix); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ClipPath final : Op {
|
||||||
|
ClipPath(const SkPath& path, SkRegion::Op op, bool aa) : path(path), op(op), aa(aa) {}
|
||||||
|
SkPath path;
|
||||||
|
SkRegion::Op op;
|
||||||
|
bool aa;
|
||||||
|
void draw(SkCanvas* c) override { c->clipPath(path, op, aa); }
|
||||||
|
};
|
||||||
struct ClipRect final : Op {
|
struct ClipRect final : Op {
|
||||||
ClipRect(const SkRect& rect, SkRegion::Op op, bool aa) : rect(rect), op(op), aa(aa) {}
|
ClipRect(const SkRect& rect, SkRegion::Op op, bool aa) : rect(rect), op(op), aa(aa) {}
|
||||||
SkRect rect;
|
SkRect rect;
|
||||||
@ -39,19 +63,55 @@ namespace {
|
|||||||
bool aa;
|
bool aa;
|
||||||
void draw(SkCanvas* c) override { c->clipRect(rect, op, aa); }
|
void draw(SkCanvas* c) override { c->clipRect(rect, op, aa); }
|
||||||
};
|
};
|
||||||
|
struct ClipRRect final : Op {
|
||||||
|
ClipRRect(const SkRRect& rrect, SkRegion::Op op, bool aa) : rrect(rrect), op(op), aa(aa) {}
|
||||||
|
SkRRect rrect;
|
||||||
|
SkRegion::Op op;
|
||||||
|
bool aa;
|
||||||
|
void draw(SkCanvas* c) override { c->clipRRect(rrect, op, aa); }
|
||||||
|
};
|
||||||
|
struct ClipRegion final : Op {
|
||||||
|
ClipRegion(const SkRegion& region, SkRegion::Op op) : region(region), op(op) {}
|
||||||
|
SkRegion region;
|
||||||
|
SkRegion::Op op;
|
||||||
|
void draw(SkCanvas* c) override { c->clipRegion(region, op); }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DrawPaint final : Op {
|
||||||
|
DrawPaint(const SkPaint& paint) : paint(paint) {}
|
||||||
|
SkPaint paint;
|
||||||
|
void draw(SkCanvas* c) override { c->drawPaint(paint); }
|
||||||
|
};
|
||||||
|
struct DrawPath final : Op {
|
||||||
|
DrawPath(const SkPath& path, const SkPaint& paint) : path(path), paint(paint) {}
|
||||||
|
SkPath path;
|
||||||
|
SkPaint paint;
|
||||||
|
void draw(SkCanvas* c) override { c->drawPath(path, paint); }
|
||||||
|
};
|
||||||
struct DrawRect final : Op {
|
struct DrawRect final : Op {
|
||||||
DrawRect(const SkRect& rect, const SkPaint& paint) : rect(rect), paint(paint) {}
|
DrawRect(const SkRect& rect, const SkPaint& paint) : rect(rect), paint(paint) {}
|
||||||
SkRect rect;
|
SkRect rect;
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
void draw(SkCanvas* c) override { c->drawRect(rect, paint); }
|
void draw(SkCanvas* c) override { c->drawRect(rect, paint); }
|
||||||
};
|
};
|
||||||
|
struct DrawOval final : Op {
|
||||||
struct DrawPath final : Op {
|
DrawOval(const SkRect& oval, const SkPaint& paint) : oval(oval), paint(paint) {}
|
||||||
DrawPath(const SkPath& path, const SkPaint& paint) : path(path), paint(paint) {}
|
SkRect oval;
|
||||||
SkPath path;
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
void draw(SkCanvas* c) override { c->drawPath(path, paint); }
|
void draw(SkCanvas* c) override { c->drawOval(oval, paint); }
|
||||||
|
};
|
||||||
|
struct DrawRRect final : Op {
|
||||||
|
DrawRRect(const SkRRect& rrect, const SkPaint& paint) : rrect(rrect), paint(paint) {}
|
||||||
|
SkRRect rrect;
|
||||||
|
SkPaint paint;
|
||||||
|
void draw(SkCanvas* c) override { c->drawRRect(rrect, paint); }
|
||||||
|
};
|
||||||
|
struct DrawDRRect final : Op {
|
||||||
|
DrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint)
|
||||||
|
: outer(outer), inner(inner), paint(paint) {}
|
||||||
|
SkRRect outer, inner;
|
||||||
|
SkPaint paint;
|
||||||
|
void draw(SkCanvas* c) override { c->drawDRRect(outer, inner, paint); }
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
@ -75,20 +135,45 @@ namespace {
|
|||||||
|
|
||||||
void SkLiteDL:: save() { push <Save>(&fBytes, 0); }
|
void SkLiteDL:: save() { push <Save>(&fBytes, 0); }
|
||||||
void SkLiteDL::restore() { push<Restore>(&fBytes, 0); }
|
void SkLiteDL::restore() { push<Restore>(&fBytes, 0); }
|
||||||
|
void SkLiteDL::saveLayer(const SkRect* bounds, const SkPaint* paint,
|
||||||
|
const SkImageFilter* backdrop, uint32_t flags) {
|
||||||
|
push<SaveLayer>(&fBytes, 0, bounds, paint, backdrop, flags);
|
||||||
|
}
|
||||||
|
|
||||||
void SkLiteDL:: concat(const SkMatrix& matrix) { push <Concat>(&fBytes, 0, matrix); }
|
void SkLiteDL:: concat(const SkMatrix& matrix) { push <Concat>(&fBytes, 0, matrix); }
|
||||||
void SkLiteDL::setMatrix(const SkMatrix& matrix) { push<SetMatrix>(&fBytes, 0, matrix); }
|
void SkLiteDL::setMatrix(const SkMatrix& matrix) { push<SetMatrix>(&fBytes, 0, matrix); }
|
||||||
|
|
||||||
|
void SkLiteDL::clipPath(const SkPath& path, SkRegion::Op op, bool aa) {
|
||||||
|
push<ClipPath>(&fBytes, 0, path, op, aa);
|
||||||
|
}
|
||||||
void SkLiteDL::clipRect(const SkRect& rect, SkRegion::Op op, bool aa) {
|
void SkLiteDL::clipRect(const SkRect& rect, SkRegion::Op op, bool aa) {
|
||||||
push<ClipRect>(&fBytes, 0, rect, op, aa);
|
push<ClipRect>(&fBytes, 0, rect, op, aa);
|
||||||
}
|
}
|
||||||
|
void SkLiteDL::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool aa) {
|
||||||
|
push<ClipRRect>(&fBytes, 0, rrect, op, aa);
|
||||||
|
}
|
||||||
|
void SkLiteDL::clipRegion(const SkRegion& region, SkRegion::Op op) {
|
||||||
|
push<ClipRegion>(&fBytes, 0, region, op);
|
||||||
|
}
|
||||||
|
|
||||||
void SkLiteDL::drawRect(const SkRect& rect, const SkPaint& paint) {
|
void SkLiteDL::drawPaint(const SkPaint& paint) {
|
||||||
push<DrawRect>(&fBytes, 0, rect, paint);
|
push<DrawPaint>(&fBytes, 0, paint);
|
||||||
}
|
}
|
||||||
void SkLiteDL::drawPath(const SkPath& path, const SkPaint& paint) {
|
void SkLiteDL::drawPath(const SkPath& path, const SkPaint& paint) {
|
||||||
push<DrawPath>(&fBytes, 0, path, paint);
|
push<DrawPath>(&fBytes, 0, path, paint);
|
||||||
}
|
}
|
||||||
|
void SkLiteDL::drawRect(const SkRect& rect, const SkPaint& paint) {
|
||||||
|
push<DrawRect>(&fBytes, 0, rect, paint);
|
||||||
|
}
|
||||||
|
void SkLiteDL::drawOval(const SkRect& oval, const SkPaint& paint) {
|
||||||
|
push<DrawOval>(&fBytes, 0, oval, paint);
|
||||||
|
}
|
||||||
|
void SkLiteDL::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
|
||||||
|
push<DrawRRect>(&fBytes, 0, rrect, paint);
|
||||||
|
}
|
||||||
|
void SkLiteDL::drawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
|
||||||
|
push<DrawDRRect>(&fBytes, 0, outer, inner, paint);
|
||||||
|
}
|
||||||
|
|
||||||
void SkLiteDL::onDraw(SkCanvas* canvas) {
|
void SkLiteDL::onDraw(SkCanvas* canvas) {
|
||||||
map(&fBytes, [canvas](Op* op) { op->draw(canvas); });
|
map(&fBytes, [canvas](Op* op) { op->draw(canvas); });
|
||||||
|
@ -20,25 +20,25 @@ public:
|
|||||||
static sk_sp<SkLiteDL> New(SkRect);
|
static sk_sp<SkLiteDL> New(SkRect);
|
||||||
|
|
||||||
void save();
|
void save();
|
||||||
void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, uint32_t) {/*TODO*/}
|
void saveLayer(const SkRect*, const SkPaint*, const SkImageFilter*, uint32_t);
|
||||||
void restore();
|
void restore();
|
||||||
|
|
||||||
void concat (const SkMatrix&);
|
void concat (const SkMatrix&);
|
||||||
void setMatrix (const SkMatrix&);
|
void setMatrix (const SkMatrix&);
|
||||||
void translateZ(SkScalar) {/*TODO*/}
|
void translateZ(SkScalar) {/*TODO*/}
|
||||||
|
|
||||||
void clipPath (const SkPath&, SkRegion::Op, bool aa) {/*TODO*/}
|
void clipPath (const SkPath&, SkRegion::Op, bool aa);
|
||||||
void clipRRect (const SkRRect&, SkRegion::Op, bool aa) {/*TODO*/}
|
|
||||||
void clipRect (const SkRect&, SkRegion::Op, bool aa);
|
void clipRect (const SkRect&, SkRegion::Op, bool aa);
|
||||||
void clipRegion(const SkRegion&, SkRegion::Op) {/*TODO*/}
|
void clipRRect (const SkRRect&, SkRegion::Op, bool aa);
|
||||||
|
void clipRegion(const SkRegion&, SkRegion::Op);
|
||||||
|
|
||||||
|
|
||||||
void drawPaint (const SkPaint&) {/*TODO*/}
|
void drawPaint (const SkPaint&);
|
||||||
void drawPath (const SkPath&, const SkPaint&);
|
void drawPath (const SkPath&, const SkPaint&);
|
||||||
void drawRect (const SkRect&, const SkPaint&);
|
void drawRect (const SkRect&, const SkPaint&);
|
||||||
void drawOval (const SkRect&, const SkPaint&) {/*TODO*/}
|
void drawOval (const SkRect&, const SkPaint&);
|
||||||
void drawRRect (const SkRRect&, const SkPaint&) {/*TODO*/}
|
void drawRRect (const SkRRect&, const SkPaint&);
|
||||||
void drawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) {/*TODO*/}
|
void drawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
|
||||||
|
|
||||||
void drawAnnotation (const SkRect&, const char*, SkData*) {/*TODO*/}
|
void drawAnnotation (const SkRect&, const char*, SkData*) {/*TODO*/}
|
||||||
void drawDrawable (SkDrawable*, const SkMatrix*) {/*TODO*/}
|
void drawDrawable (SkDrawable*, const SkMatrix*) {/*TODO*/}
|
||||||
|
Loading…
Reference in New Issue
Block a user