From b5086961f335d6757a88ce7507c445485aaba2e6 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Wed, 13 Dec 2017 10:59:33 -0500 Subject: Add matrix stack to SkAtlasTextTarget. Makes SkAtlasTextRenderer::SDFVertex now has a 3 component position vector. Change-Id: I7ec1a8068fb84388a82e1748d6e9d02820d55abd Reviewed-on: https://skia-review.googlesource.com/84202 Commit-Queue: Brian Salomon Reviewed-by: Jim Van Verth --- include/atlastext/SkAtlasTextRenderer.h | 6 +++--- include/atlastext/SkAtlasTextTarget.h | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'include/atlastext') diff --git a/include/atlastext/SkAtlasTextRenderer.h b/include/atlastext/SkAtlasTextRenderer.h index a78e270edb..f5eb5240c9 100644 --- a/include/atlastext/SkAtlasTextRenderer.h +++ b/include/atlastext/SkAtlasTextRenderer.h @@ -5,7 +5,7 @@ * found in the LICENSE file. */ -#include "SkPoint.h" +#include "SkPoint3.h" #include "SkRefCnt.h" #ifndef SkAtlasTextRenderer_DEFINED @@ -25,8 +25,8 @@ public: }; struct SDFVertex { - /** Position in device space (not normalized). */ - SkPoint fPosition; + /** Position in device space (not normalized). The third component is w (not z). */ + SkPoint3 fPosition; /** Color, same value for all four corners of a glyph quad. */ uint32_t fColor; /** Texture coordinate (in texel units, not normalized). */ diff --git a/include/atlastext/SkAtlasTextTarget.h b/include/atlastext/SkAtlasTextTarget.h index ff879617d8..c29f381dc8 100644 --- a/include/atlastext/SkAtlasTextTarget.h +++ b/include/atlastext/SkAtlasTextTarget.h @@ -9,11 +9,13 @@ #define SkAtlasTextTarget_DEFINED #include +#include "SkDeque.h" #include "SkRefCnt.h" #include "SkScalar.h" class SkAtlasTextContext; class SkAtlasTextFont; +class SkMatrix; struct SkPoint; /** Represents a client-created renderable surface and is used to draw text into the surface. */ @@ -46,15 +48,47 @@ public: SkAtlasTextContext* context() const { return fContext.get(); } + /** Saves the current matrix in a stack. Returns the prior depth of the saved matrix stack. */ + int save(); + /** Pops the top matrix on the stack if the stack is not empty. */ + void restore(); + /** + * Pops the matrix stack until the stack depth is count. Does nothing if the depth is already + * less than count. + */ + void restoreToCount(int count); + + /** Pre-translates the current CTM. */ + void translate(SkScalar dx, SkScalar dy); + /** Pre-scales the current CTM. */ + void scale(SkScalar sx, SkScalar sy); + /** Pre-rotates the current CTM about the origin. */ + void rotate(SkScalar degrees); + /** Pre-rotates the current CTM about the (px, py). */ + void rotate(SkScalar degrees, SkScalar px, SkScalar py); + /** Pre-skews the current CTM. */ + void skew(SkScalar sx, SkScalar sy); + /** Pre-concats the current CTM. */ + void concat(const SkMatrix& matrix); + protected: SkAtlasTextTarget(sk_sp, int width, int height, void* handle); + const SkMatrix& ctm() const { return *static_cast(fMatrixStack.back()); } + void* const fHandle; const sk_sp fContext; const int fWidth; const int fHeight; private: + SkDeque fMatrixStack; + int fSaveCnt; + + SkMatrix* accessCTM() const { + return static_cast(const_cast(fMatrixStack.back())); + } + SkAtlasTextTarget() = delete; SkAtlasTextTarget(const SkAtlasTextContext&) = delete; SkAtlasTextTarget& operator=(const SkAtlasTextContext&) = delete; -- cgit v1.2.3