aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-12-13 10:59:33 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-12-20 14:00:44 +0000
commitb5086961f335d6757a88ce7507c445485aaba2e6 (patch)
treea635252858428f4f0f04144d532cc4ab96388d95 /src
parente1367b4a064737cbcf78f2297fa89e0a032b2060 (diff)
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 <bsalomon@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/atlastext/SkAtlasTextTarget.cpp50
-rw-r--r--src/atlastext/SkInternalAtlasTextContext.cpp4
-rw-r--r--src/atlastext/SkInternalAtlasTextContext.h3
-rw-r--r--src/gpu/GrContext.cpp6
-rw-r--r--src/gpu/text/GrAtlasTextContext.cpp4
-rw-r--r--src/gpu/text/GrAtlasTextContext.h3
6 files changed, 64 insertions, 6 deletions
diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp
index 81dbb07a16..0a318e0c8e 100644
--- a/src/atlastext/SkAtlasTextTarget.cpp
+++ b/src/atlastext/SkAtlasTextTarget.cpp
@@ -21,10 +21,53 @@ static constexpr int kMaxBatchLookBack = 10;
SkAtlasTextTarget::SkAtlasTextTarget(sk_sp<SkAtlasTextContext> context, int width, int height,
void* handle)
- : fHandle(handle), fContext(std::move(context)), fWidth(width), fHeight(height) {}
+ : fHandle(handle)
+ , fContext(std::move(context))
+ , fWidth(width)
+ , fHeight(height)
+ , fMatrixStack(sizeof(SkMatrix), 4)
+ , fSaveCnt(0) {
+ fMatrixStack.push_back();
+ this->accessCTM()->reset();
+}
SkAtlasTextTarget::~SkAtlasTextTarget() { fContext->renderer()->targetDeleted(fHandle); }
+int SkAtlasTextTarget::save() {
+ const auto& currCTM = this->ctm();
+ *static_cast<SkMatrix*>(fMatrixStack.push_back()) = currCTM;
+ return fSaveCnt++;
+}
+
+void SkAtlasTextTarget::restore() {
+ if (fSaveCnt) {
+ fMatrixStack.pop_back();
+ fSaveCnt--;
+ }
+}
+
+void SkAtlasTextTarget::restoreToCount(int count) {
+ while (fSaveCnt > count) {
+ this->restore();
+ }
+}
+
+void SkAtlasTextTarget::translate(SkScalar dx, SkScalar dy) {
+ this->accessCTM()->preTranslate(dx, dy);
+}
+
+void SkAtlasTextTarget::scale(SkScalar sx, SkScalar sy) { this->accessCTM()->preScale(sx, sy); }
+
+void SkAtlasTextTarget::rotate(SkScalar degrees) { this->accessCTM()->preRotate(degrees); }
+
+void SkAtlasTextTarget::rotate(SkScalar degrees, SkScalar px, SkScalar py) {
+ this->accessCTM()->preRotate(degrees, px, py);
+}
+
+void SkAtlasTextTarget::skew(SkScalar sx, SkScalar sy) { this->accessCTM()->preSkew(sx, sy); }
+
+void SkAtlasTextTarget::concat(const SkMatrix& matrix) { this->accessCTM()->preConcat(matrix); }
+
//////////////////////////////////////////////////////////////////////////////
static const GrColorSpaceInfo kColorSpaceInfo(nullptr, kRGBA_8888_GrPixelConfig);
@@ -95,7 +138,7 @@ void SkInternalAtlasTextTarget::drawText(const SkGlyphID glyphs[], const SkPoint
auto atlasTextContext = grContext->contextPriv().drawingManager()->getAtlasTextContext();
size_t byteLength = sizeof(SkGlyphID) * glyphCnt;
const SkScalar* pos = &positions->fX;
- atlasTextContext->drawPosText(grContext, this, GrNoClip(), paint, SkMatrix::I(), props,
+ atlasTextContext->drawPosText(grContext, this, GrNoClip(), paint, this->ctm(), props,
(const char*)glyphs, byteLength, pos, 2, {0, 0}, bounds);
}
@@ -149,7 +192,8 @@ void GrAtlasTextOp::executeForTextTarget(SkAtlasTextTarget* target) {
GrAtlasTextBlob::VertexRegenerator::Result result;
do {
result = regenerator.regenerate();
- context.recordDraw(result.fFirstVertex, result.fGlyphsRegenerated, target->handle());
+ context.recordDraw(result.fFirstVertex, result.fGlyphsRegenerated,
+ fGeoData[i].fViewMatrix, target->handle());
if (!result.fFinished) {
// Make space in the atlas so we can continue generating vertices.
context.flush();
diff --git a/src/atlastext/SkInternalAtlasTextContext.cpp b/src/atlastext/SkInternalAtlasTextContext.cpp
index 858ae4da01..6dde9ae096 100644
--- a/src/atlastext/SkInternalAtlasTextContext.cpp
+++ b/src/atlastext/SkInternalAtlasTextContext.cpp
@@ -30,6 +30,7 @@ SkInternalAtlasTextContext::SkInternalAtlasTextContext(sk_sp<SkAtlasTextRenderer
options.fAllowMultipleGlyphCacheTextures = GrContextOptions::Enable::kNo;
options.fMinDistanceFieldFontSize = 0.f;
options.fGlyphsAsPathsFontSize = SK_ScalarInfinity;
+ options.fDistanceFieldGlyphVerticesAlwaysHaveW = GrContextOptions::Enable::kYes;
fGrContext = GrContext::MakeMock(nullptr, options);
}
@@ -62,7 +63,7 @@ GrDeferredUploadToken SkInternalAtlasTextContext::addASAPUpload(
}
void SkInternalAtlasTextContext::recordDraw(const void* srcVertexData, int glyphCnt,
- void* targetHandle) {
+ const SkMatrix& matrix, void* targetHandle) {
auto vertexDataSize = sizeof(SkAtlasTextRenderer::SDFVertex) * 4 * glyphCnt;
auto vertexData = fArena.makeArrayDefault<char>(vertexDataSize);
memcpy(vertexData, srcVertexData, vertexDataSize);
@@ -72,6 +73,7 @@ void SkInternalAtlasTextContext::recordDraw(const void* srcVertexData, int glyph
// This isn't expected by SkAtlasTextRenderer subclasses.
vertex->fTextureCoord.fX /= 2;
vertex->fTextureCoord.fY /= 2;
+ matrix.mapHomogeneousPoints(&vertex->fPosition, &vertex->fPosition, 1);
}
fDraws.append(&fArena, Draw{glyphCnt, this->issueDrawToken(), targetHandle, vertexData});
}
diff --git a/src/atlastext/SkInternalAtlasTextContext.h b/src/atlastext/SkInternalAtlasTextContext.h
index 1bb12cee5a..ea89435580 100644
--- a/src/atlastext/SkInternalAtlasTextContext.h
+++ b/src/atlastext/SkInternalAtlasTextContext.h
@@ -14,6 +14,7 @@
#include "SkRefCnt.h"
class SkAtlasTextRenderer;
+class SkMatrix;
class GrContext;
class GrAtlasGlyphCache;
class GrTextBlobCache;
@@ -38,7 +39,7 @@ public:
GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) override;
- void recordDraw(const void* vertexData, int glyphCnt, void* targetHandle);
+ void recordDraw(const void* vertexData, int glyphCnt, const SkMatrix&, void* targetHandle);
void flush();
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index c410874fd9..9240d63b4a 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -234,6 +234,12 @@ bool GrContext::init(const GrContextOptions& options) {
GrAtlasTextContext::Options atlasTextContextOptions;
atlasTextContextOptions.fMaxDistanceFieldFontSize = options.fGlyphsAsPathsFontSize;
atlasTextContextOptions.fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize;
+ atlasTextContextOptions.fDistanceFieldVerticesAlwaysHaveW = false;
+#if SK_SUPPORT_ATLAS_TEXT
+ if (GrContextOptions::Enable::kYes == options.fDistanceFieldGlyphVerticesAlwaysHaveW) {
+ atlasTextContextOptions.fDistanceFieldVerticesAlwaysHaveW = true;
+ }
+#endif
fDrawingManager.reset(
new GrDrawingManager(this, prcOptions, atlasTextContextOptions, &fSingleOwner));
diff --git a/src/gpu/text/GrAtlasTextContext.cpp b/src/gpu/text/GrAtlasTextContext.cpp
index 3faa0f7b87..73a27100d3 100644
--- a/src/gpu/text/GrAtlasTextContext.cpp
+++ b/src/gpu/text/GrAtlasTextContext.cpp
@@ -39,6 +39,7 @@ GrAtlasTextContext::GrAtlasTextContext(const Options& options)
fMinDistanceFieldFontSize = options.fMinDistanceFieldFontSize < 0.f
? kDefaultMinDistanceFieldFontSize
: options.fMinDistanceFieldFontSize;
+ fDistanceFieldVerticesAlwaysHaveW = options.fDistanceFieldVerticesAlwaysHaveW;
}
std::unique_ptr<GrAtlasTextContext> GrAtlasTextContext::Make(const Options& options) {
@@ -646,7 +647,8 @@ void GrAtlasTextContext::drawDFPosText(GrAtlasTextBlob* blob, int runIndex,
SkTDArray<char> fallbackTxt;
SkTDArray<SkScalar> fallbackPos;
- bool hasWCoord = viewMatrix.hasPerspective();
+ bool hasWCoord = viewMatrix.hasPerspective() || fDistanceFieldVerticesAlwaysHaveW;
+
// Setup distance field paint and text ratio
SkScalar textRatio;
SkPaint dfPaint(paint);
diff --git a/src/gpu/text/GrAtlasTextContext.h b/src/gpu/text/GrAtlasTextContext.h
index 8db0d7e050..52c8dfcb87 100644
--- a/src/gpu/text/GrAtlasTextContext.h
+++ b/src/gpu/text/GrAtlasTextContext.h
@@ -38,6 +38,8 @@ public:
* be rendered from outline as individual paths. Negative means use a default value.
*/
SkScalar fMaxDistanceFieldFontSize = -1.f;
+ /** Forces all distance field vertices to use 3 components, not just when in perspective. */
+ bool fDistanceFieldVerticesAlwaysHaveW = false;
};
static std::unique_ptr<GrAtlasTextContext> Make(const Options& options);
@@ -142,6 +144,7 @@ private:
SkScalar fMinDistanceFieldFontSize;
SkScalar fMaxDistanceFieldFontSize;
+ bool fDistanceFieldVerticesAlwaysHaveW;
#if GR_TEST_UTILS
static const uint32_t kTextBlobOpScalerContextFlags =