diff options
Diffstat (limited to 'experimental/sksg/geometry')
-rw-r--r-- | experimental/sksg/geometry/SkSGGeometryTransform.cpp | 53 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGGeometryTransform.h | 58 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGMerge.cpp | 84 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGMerge.h | 64 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGPath.cpp | 41 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGPath.h | 48 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGPlane.cpp | 36 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGPlane.h | 40 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGRect.cpp | 60 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGRect.h | 76 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGRoundEffect.cpp | 56 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGRoundEffect.h | 50 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGText.cpp | 77 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGText.h | 69 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGTrimEffect.cpp | 56 | ||||
-rw-r--r-- | experimental/sksg/geometry/SkSGTrimEffect.h | 58 |
16 files changed, 0 insertions, 926 deletions
diff --git a/experimental/sksg/geometry/SkSGGeometryTransform.cpp b/experimental/sksg/geometry/SkSGGeometryTransform.cpp deleted file mode 100644 index 5b366b9620..0000000000 --- a/experimental/sksg/geometry/SkSGGeometryTransform.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGGeometryTransform.h" - -#include "SkCanvas.h" - -namespace sksg { - -GeometryTransform::GeometryTransform(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix) - : fChild(std::move(child)) - , fMatrix(std::move(matrix)) { - this->observeInval(fChild); - this->observeInval(fMatrix); -} - -GeometryTransform::~GeometryTransform() { - this->unobserveInval(fChild); - this->unobserveInval(fMatrix); -} - -void GeometryTransform::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipPath(fTransformed, SkClipOp::kIntersect, antiAlias); -} - -void GeometryTransform::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - canvas->drawPath(fTransformed, paint); -} - -SkRect GeometryTransform::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { - SkASSERT(this->hasInval()); - - // We don't care about matrix reval results. - fMatrix->revalidate(ic, ctm); - const auto& m = fMatrix->getMatrix(); - - auto bounds = fChild->revalidate(ic, ctm); - fTransformed = fChild->asPath(); - fTransformed.transform(m); - - m.mapRect(&bounds); - return bounds; -} - -SkPath GeometryTransform::onAsPath() const { - return fTransformed; -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGGeometryTransform.h b/experimental/sksg/geometry/SkSGGeometryTransform.h deleted file mode 100644 index fe7e026031..0000000000 --- a/experimental/sksg/geometry/SkSGGeometryTransform.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGGeometryTransform_DEFINED -#define SkSGGeometryTransform_DEFINED - -#include "SkSGGeometryNode.h" - -#include "SkPath.h" -#include "SkSGTransform.h" - -class SkMatrix; - -namespace sksg { - -/** - * Concrete Effect node, binding a Matrix to a GeometryNode. - */ -class GeometryTransform final : public GeometryNode { -public: - static sk_sp<GeometryTransform> Make(sk_sp<GeometryNode> child, sk_sp<Matrix> matrix) { - return child && matrix - ? sk_sp<GeometryTransform>(new GeometryTransform(std::move(child), std::move(matrix))) - : nullptr; - } - - static sk_sp<GeometryTransform> Make(sk_sp<GeometryNode> child, const SkMatrix& m) { - return Make(std::move(child), Matrix::Make(m)); - } - - ~GeometryTransform() override; - - const sk_sp<Matrix>& getMatrix() const { return fMatrix; } - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - GeometryTransform(sk_sp<GeometryNode>, sk_sp<Matrix>); - - const sk_sp<GeometryNode> fChild; - const sk_sp<Matrix> fMatrix; - SkPath fTransformed; - - using INHERITED = GeometryNode; -}; - -} - -#endif // SkSGGeometryTransform_DEFINED diff --git a/experimental/sksg/geometry/SkSGMerge.cpp b/experimental/sksg/geometry/SkSGMerge.cpp deleted file mode 100644 index be1ff4123a..0000000000 --- a/experimental/sksg/geometry/SkSGMerge.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGMerge.h" - -#include "SkCanvas.h" -#include "SkPathOps.h" - -namespace sksg { - -Merge::Merge(std::vector<sk_sp<GeometryNode>>&& geos, Mode mode) - : fGeos(std::move(geos)) - , fMode(mode) { - for (const auto& geo : fGeos) { - this->observeInval(geo); - } -} - -Merge::~Merge() { - for (const auto& geo : fGeos) { - this->unobserveInval(geo); - } -} - -void Merge::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipPath(fMerged, SkClipOp::kIntersect, antiAlias); -} - -void Merge::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - canvas->drawPath(fMerged, paint); -} - -SkPath Merge::onAsPath() const { - return fMerged; -} - -static SkPathOp mode_to_op(Merge::Mode mode) { - switch (mode) { - case Merge::Mode::kUnion: - return kUnion_SkPathOp; - case Merge::Mode::kIntersect: - return kIntersect_SkPathOp; - case Merge::Mode::kDifference: - return kDifference_SkPathOp; - case Merge::Mode::kReverseDifference: - return kReverseDifference_SkPathOp; - case Merge::Mode::kXOR: - return kXOR_SkPathOp; - default: - break; - } - - return kUnion_SkPathOp; -} - -SkRect Merge::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { - SkASSERT(this->hasInval()); - - const auto op = mode_to_op(fMode); - SkOpBuilder builder; - - fMerged.reset(); - - for (const auto& geo : fGeos) { - geo->revalidate(ic, ctm); - if (fMode == Mode::kMerge) { - fMerged.addPath(geo->asPath()); - } else { - builder.add(geo->asPath(), geo == fGeos.front() ? kUnion_SkPathOp : op); - } - } - - if (fMode != Mode::kMerge) { - builder.resolve(&fMerged); - } - - return fMerged.computeTightBounds(); -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGMerge.h b/experimental/sksg/geometry/SkSGMerge.h deleted file mode 100644 index 54924d6475..0000000000 --- a/experimental/sksg/geometry/SkSGMerge.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGMerge_DEFINED -#define SkSGMerge_DEFINED - -#include "SkSGGeometryNode.h" - -#include "SkPath.h" - -#include <vector> - -class SkCanvas; -class SkPaint; - -namespace sksg { - -/** - * Concrete Geometry node, combining other geometries based on Mode. - */ -class Merge final : public GeometryNode { -public: - enum class Mode { - // Append path mode. - kMerge, - - // SkPathOp ops. - kUnion, - kIntersect, - kDifference, - kReverseDifference, - kXOR, - }; - - static sk_sp<Merge> Make(std::vector<sk_sp<GeometryNode>>&& geos, Mode mode) { - return sk_sp<Merge>(new Merge(std::move(geos), mode)); - } - - ~Merge() override; - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - Merge(std::vector<sk_sp<GeometryNode>>&& geos, Mode); - - std::vector<sk_sp<GeometryNode>> fGeos; - SkPath fMerged; - Mode fMode; - - using INHERITED = GeometryNode; -}; - -} // namespace sksg - -#endif // SkSGMerge_DEFINED diff --git a/experimental/sksg/geometry/SkSGPath.cpp b/experimental/sksg/geometry/SkSGPath.cpp deleted file mode 100644 index 230442d409..0000000000 --- a/experimental/sksg/geometry/SkSGPath.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGPath.h" - -#include "SkCanvas.h" -#include "SkPaint.h" -#include "SkRectPriv.h" - -namespace sksg { - -Path::Path(const SkPath& path) : fPath(path) {} - -void Path::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipPath(fPath, SkClipOp::kIntersect, antiAlias); -} - -void Path::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - canvas->drawPath(fPath, paint); -} - -SkRect Path::onRevalidate(InvalidationController*, const SkMatrix&) { - SkASSERT(this->hasInval()); - - const auto ft = fPath.getFillType(); - return (ft == SkPath::kWinding_FillType || ft == SkPath::kEvenOdd_FillType) - // "Containing" fills have finite bounds. - ? fPath.computeTightBounds() - // Inverse fills are "infinite". - : SkRectPriv::MakeLargeS32(); -} - -SkPath Path::onAsPath() const { - return fPath; -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGPath.h b/experimental/sksg/geometry/SkSGPath.h deleted file mode 100644 index 1a8718868d..0000000000 --- a/experimental/sksg/geometry/SkSGPath.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGPath_DEFINED -#define SkSGPath_DEFINED - -#include "SkSGGeometryNode.h" - -#include "SkPath.h" - -class SkCanvas; -class SkPaint; - -namespace sksg { - -/** - * Concrete Geometry node, wrapping an SkPath. - */ -class Path : public GeometryNode { -public: - static sk_sp<Path> Make() { return sk_sp<Path>(new Path(SkPath())); } - static sk_sp<Path> Make(const SkPath& r) { return sk_sp<Path>(new Path(r)); } - - SG_ATTRIBUTE(Path, SkPath, fPath) - SG_MAPPED_ATTRIBUTE(FillType, SkPath::FillType, fPath) - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - explicit Path(const SkPath&); - - SkPath fPath; - - using INHERITED = GeometryNode; -}; - -} // namespace sksg - -#endif // SkSGPath_DEFINED diff --git a/experimental/sksg/geometry/SkSGPlane.cpp b/experimental/sksg/geometry/SkSGPlane.cpp deleted file mode 100644 index 806fcc7d29..0000000000 --- a/experimental/sksg/geometry/SkSGPlane.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGPlane.h" - -#include "SkCanvas.h" -#include "SkPath.h" - -namespace sksg { - -Plane::Plane() = default; - -void Plane::onClip(SkCanvas*, bool) const {} - -void Plane::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - canvas->drawPaint(paint); -} - -SkRect Plane::onRevalidate(InvalidationController*, const SkMatrix&) { - SkASSERT(this->hasInval()); - - return SkRect::MakeLTRB(SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax); -} - -SkPath Plane::onAsPath() const { - SkPath path; - path.setFillType(SkPath::kInverseWinding_FillType); - - return path; -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGPlane.h b/experimental/sksg/geometry/SkSGPlane.h deleted file mode 100644 index c0a26375b2..0000000000 --- a/experimental/sksg/geometry/SkSGPlane.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGPlane_DEFINED -#define SkSGPlane_DEFINED - -#include "SkSGGeometryNode.h" - -class SkCanvas; -class SkPaint; - -namespace sksg { - -/** - * Concrete Geometry node, representing the whole canvas. - */ -class Plane final : public GeometryNode { -public: - static sk_sp<Plane> Make() { return sk_sp<Plane>(new Plane()); } - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - Plane(); - - using INHERITED = GeometryNode; -}; - -} // namespace sksg - -#endif // SkSGPlane_DEFINED diff --git a/experimental/sksg/geometry/SkSGRect.cpp b/experimental/sksg/geometry/SkSGRect.cpp deleted file mode 100644 index 16f0a6f1e1..0000000000 --- a/experimental/sksg/geometry/SkSGRect.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGRect.h" - -#include "SkCanvas.h" -#include "SkPaint.h" -#include "SkPath.h" - -namespace sksg { - -Rect::Rect(const SkRect& rect) : fRect(rect) {} - -void Rect::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipRect(fRect, SkClipOp::kIntersect, antiAlias); -} - -void Rect::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - canvas->drawRect(fRect, paint); -} - -SkRect Rect::onRevalidate(InvalidationController*, const SkMatrix&) { - SkASSERT(this->hasInval()); - - return fRect; -} - -SkPath Rect::onAsPath() const { - SkPath path; - path.addRect(fRect); - return path; -} - -RRect::RRect(const SkRRect& rr) : fRRect(rr) {} - -void RRect::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipRRect(fRRect, SkClipOp::kIntersect, antiAlias); -} - -void RRect::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - canvas->drawRRect(fRRect, paint); -} - -SkRect RRect::onRevalidate(InvalidationController*, const SkMatrix&) { - SkASSERT(this->hasInval()); - - return fRRect.getBounds(); -} - -SkPath RRect::onAsPath() const { - SkPath path; - path.addRRect(fRRect); - return path; -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGRect.h b/experimental/sksg/geometry/SkSGRect.h deleted file mode 100644 index f5fcb962c6..0000000000 --- a/experimental/sksg/geometry/SkSGRect.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGRect_DEFINED -#define SkSGRect_DEFINED - -#include "SkSGGeometryNode.h" - -#include "SkRect.h" -#include "SkRRect.h" - -class SkCanvas; -class SkPaint; - -namespace sksg { - -/** - * Concrete Geometry node, wrapping an SkRect. - */ -class Rect final : public GeometryNode { -public: - static sk_sp<Rect> Make() { return sk_sp<Rect>(new Rect(SkRect::MakeEmpty())); } - static sk_sp<Rect> Make(const SkRect& r) { return sk_sp<Rect>(new Rect(r)); } - - SG_ATTRIBUTE(L, SkScalar, fRect.fLeft ) - SG_ATTRIBUTE(T, SkScalar, fRect.fTop ) - SG_ATTRIBUTE(R, SkScalar, fRect.fRight ) - SG_ATTRIBUTE(B, SkScalar, fRect.fBottom) - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - explicit Rect(const SkRect&); - - SkRect fRect; - - using INHERITED = GeometryNode; -}; - -/** - * Concrete Geometry node, wrapping an SkRRect. - */ -class RRect final : public GeometryNode { -public: - static sk_sp<RRect> Make() { return sk_sp<RRect>(new RRect(SkRRect())); } - static sk_sp<RRect> Make(const SkRRect& rr) { return sk_sp<RRect>(new RRect(rr)); } - - SG_ATTRIBUTE(RRect, SkRRect, fRRect) - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - explicit RRect(const SkRRect&); - - SkRRect fRRect; - - using INHERITED = GeometryNode; -}; - -} // namespace sksg - -#endif // SkSGRect_DEFINED diff --git a/experimental/sksg/geometry/SkSGRoundEffect.cpp b/experimental/sksg/geometry/SkSGRoundEffect.cpp deleted file mode 100644 index 8cf9068f65..0000000000 --- a/experimental/sksg/geometry/SkSGRoundEffect.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGRoundEffect.h" - -#include "SkCanvas.h" -#include "SkCornerPathEffect.h" -#include "SkStrokeRec.h" - -namespace sksg { - -RoundEffect::RoundEffect(sk_sp<GeometryNode> child) - : fChild(std::move(child)) { - this->observeInval(fChild); -} - -RoundEffect::~RoundEffect() { - this->unobserveInval(fChild); -} - -void RoundEffect::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipPath(fRoundedPath, SkClipOp::kIntersect, antiAlias); -} - -void RoundEffect::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - SkASSERT(!paint.getPathEffect()); - - canvas->drawPath(fRoundedPath, paint); -} - -SkPath RoundEffect::onAsPath() const { - return fRoundedPath; -} - -SkRect RoundEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { - SkASSERT(this->hasInval()); - - const auto childbounds = fChild->revalidate(ic, ctm); - const auto path = fChild->asPath(); - - if (auto round = SkCornerPathEffect::Make(fRadius)) { - fRoundedPath.reset(); - SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); - SkAssertResult(round->filterPath(&fRoundedPath, path, &rec, &childbounds)); - } else { - fRoundedPath = path; - } - - return fRoundedPath.computeTightBounds(); -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGRoundEffect.h b/experimental/sksg/geometry/SkSGRoundEffect.h deleted file mode 100644 index 67124ca072..0000000000 --- a/experimental/sksg/geometry/SkSGRoundEffect.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGRoundEffect_DEFINED -#define SkSGRoundEffect_DEFINED - -#include "SkSGGeometryNode.h" - -#include "SkPath.h" - -namespace sksg { - -/** - * Concrete Geometry node, applying a rounded-corner effect to its child. - */ -class RoundEffect final : public GeometryNode { -public: - static sk_sp<RoundEffect> Make(sk_sp<GeometryNode> child) { - return child ? sk_sp<RoundEffect>(new RoundEffect(std::move(child))) : nullptr; - } - - ~RoundEffect() override; - - SG_ATTRIBUTE(Radius, SkScalar, fRadius) - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - explicit RoundEffect(sk_sp<GeometryNode>); - - const sk_sp<GeometryNode> fChild; - - SkPath fRoundedPath; - SkScalar fRadius = 0; - - using INHERITED = GeometryNode; -}; - -} // namespace sksg - -#endif // SkSGRoundEffect_DEFINED diff --git a/experimental/sksg/geometry/SkSGText.cpp b/experimental/sksg/geometry/SkSGText.cpp deleted file mode 100644 index c149390023..0000000000 --- a/experimental/sksg/geometry/SkSGText.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGText.h" - -#include "SkCanvas.h" -#include "SkPaint.h" -#include "SkPath.h" -#include "SkTArray.h" -#include "SkTextBlob.h" -#include "SkTypeface.h" - -namespace sksg { - -sk_sp<Text> Text::Make(sk_sp<SkTypeface> tf, const SkString& text) { - return sk_sp<Text>(new Text(std::move(tf), text)); -} - -Text::Text(sk_sp<SkTypeface> tf, const SkString& text) - : fTypeface(std::move(tf)) - , fText(text) {} - -Text::~Text() = default; - -SkRect Text::onRevalidate(InvalidationController*, const SkMatrix&) { - // TODO: we could potentially track invals which don't require rebuilding the blob. - - SkPaint font; - font.setFlags(fFlags); - font.setTypeface(fTypeface); - font.setTextSize(fSize); - font.setTextScaleX(fScaleX); - font.setTextSkewX(fSkewX); - font.setTextAlign(fAlign); - font.setHinting(fHinting); - - // First, convert to glyphIDs. - font.setTextEncoding(SkPaint::kUTF8_TextEncoding); - SkSTArray<256, SkGlyphID, true> glyphs; - glyphs.reset(font.textToGlyphs(fText.c_str(), fText.size(), nullptr)); - SkAssertResult(font.textToGlyphs(fText.c_str(), fText.size(), glyphs.begin()) == glyphs.count()); - font.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - - // Next, build the cached blob. - SkTextBlobBuilder builder; - const auto& buf = builder.allocRun(font, glyphs.count(), 0, 0, nullptr); - if (!buf.glyphs) { - fBlob.reset(); - return SkRect::MakeEmpty(); - } - - memcpy(buf.glyphs, glyphs.begin(), glyphs.count() * sizeof(SkGlyphID)); - - fBlob = builder.make(); - return fBlob - ? fBlob->bounds().makeOffset(fPosition.x(), fPosition.y()) - : SkRect::MakeEmpty(); -} - -void Text::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - canvas->drawTextBlob(fBlob, fPosition.x(), fPosition.y(), paint); -} - -SkPath Text::onAsPath() const { - // TODO - return SkPath(); -} - -void Text::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipPath(this->asPath(), antiAlias); -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGText.h b/experimental/sksg/geometry/SkSGText.h deleted file mode 100644 index eb43337a10..0000000000 --- a/experimental/sksg/geometry/SkSGText.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2018 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGText_DEFINED -#define SkSGText_DEFINED - -#include "SkSGGeometryNode.h" - -#include "SkPaintDefaults.h" -#include "SkPoint.h" -#include "SkString.h" - -class SkCanvas; -class SkPaint; -class SkTextBlob; -class SkTypeface; - -namespace sksg { - -/** - * Concrete Geometry node, wrapping a (shaped) SkTextBlob. - */ -class Text final : public GeometryNode { -public: - static sk_sp<Text> Make(sk_sp<SkTypeface> tf, const SkString& text); - ~Text() override; - - SG_ATTRIBUTE(Text , SkString , fText ) - SG_ATTRIBUTE(Flags , uint32_t , fFlags ) - SG_ATTRIBUTE(Position, SkPoint , fPosition) - SG_ATTRIBUTE(Size , SkScalar , fSize ) - SG_ATTRIBUTE(ScaleX , SkScalar , fScaleX ) - SG_ATTRIBUTE(SkewX , SkScalar , fSkewX ) - SG_ATTRIBUTE(Align , SkPaint::Align, fAlign ) - - // TODO: add shaping functionality. - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - explicit Text(sk_sp<SkTypeface>, const SkString&); - - const sk_sp<SkTypeface> fTypeface; - SkString fText; - uint32_t fFlags = SkPaintDefaults_Flags; - SkPoint fPosition = SkPoint::Make(0, 0); - SkScalar fSize = SkPaintDefaults_TextSize; - SkScalar fScaleX = 1; - SkScalar fSkewX = 0; - SkPaint::Align fAlign = SkPaint::kLeft_Align; - SkPaint::Hinting fHinting = SkPaintDefaults_Hinting; - - sk_sp<SkTextBlob> fBlob; // cached text blob - - using INHERITED = GeometryNode; -}; - -} // namespace sksg - -#endif // SkSGText_DEFINED diff --git a/experimental/sksg/geometry/SkSGTrimEffect.cpp b/experimental/sksg/geometry/SkSGTrimEffect.cpp deleted file mode 100644 index b8c59bcfe8..0000000000 --- a/experimental/sksg/geometry/SkSGTrimEffect.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkSGTrimEffect.h" - -#include "SkCanvas.h" -#include "SkStrokeRec.h" -#include "SkTrimPathEffect.h" - -namespace sksg { - -TrimEffect::TrimEffect(sk_sp<GeometryNode> child) - : fChild(std::move(child)) { - this->observeInval(fChild); -} - -TrimEffect::~TrimEffect() { - this->unobserveInval(fChild); -} - -void TrimEffect::onClip(SkCanvas* canvas, bool antiAlias) const { - canvas->clipPath(fTrimmedPath, SkClipOp::kIntersect, antiAlias); -} - -void TrimEffect::onDraw(SkCanvas* canvas, const SkPaint& paint) const { - SkASSERT(!paint.getPathEffect()); - - canvas->drawPath(fTrimmedPath, paint); -} - -SkPath TrimEffect::onAsPath() const { - return fTrimmedPath; -} - -SkRect TrimEffect::onRevalidate(InvalidationController* ic, const SkMatrix& ctm) { - SkASSERT(this->hasInval()); - - const auto childbounds = fChild->revalidate(ic, ctm); - const auto path = fChild->asPath(); - - if (auto trim = SkTrimPathEffect::Make(fStart, fStop, fMode)) { - fTrimmedPath.reset(); - SkStrokeRec rec(SkStrokeRec::kHairline_InitStyle); - SkAssertResult(trim->filterPath(&fTrimmedPath, path, &rec, &childbounds)); - } else { - fTrimmedPath = path; - } - - return fTrimmedPath.computeTightBounds(); -} - -} // namespace sksg diff --git a/experimental/sksg/geometry/SkSGTrimEffect.h b/experimental/sksg/geometry/SkSGTrimEffect.h deleted file mode 100644 index 18f15921e7..0000000000 --- a/experimental/sksg/geometry/SkSGTrimEffect.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef SkSGTrimEffect_DEFINED -#define SkSGTrimEffect_DEFINED - -#include "SkSGGeometryNode.h" - -#include "SkPath.h" -#include "SkTrimPathEffect.h" - -class SkCanvas; -class SkPaint; - -namespace sksg { - -/** - * Concrete Geometry node, applying a trim effect to its child. - */ -class TrimEffect final : public GeometryNode { -public: - static sk_sp<TrimEffect> Make(sk_sp<GeometryNode> child) { - return child ? sk_sp<TrimEffect>(new TrimEffect(std::move(child))) : nullptr; - } - - ~TrimEffect() override; - - SG_ATTRIBUTE(Start , SkScalar , fStart ) - SG_ATTRIBUTE(Stop , SkScalar , fStop ) - SG_ATTRIBUTE(Mode , SkTrimPathEffect::Mode, fMode ) - -protected: - void onClip(SkCanvas*, bool antiAlias) const override; - void onDraw(SkCanvas*, const SkPaint&) const override; - - SkRect onRevalidate(InvalidationController*, const SkMatrix&) override; - SkPath onAsPath() const override; - -private: - explicit TrimEffect(sk_sp<GeometryNode>); - - const sk_sp<GeometryNode> fChild; - - SkPath fTrimmedPath; - SkScalar fStart = 0, - fStop = 1; - SkTrimPathEffect::Mode fMode = SkTrimPathEffect::Mode::kNormal; - - using INHERITED = GeometryNode; -}; - -} // namespace sksg - -#endif // SkSGTrimEffect_DEFINED |