aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/atlastext.cpp
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 /gm/atlastext.cpp
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 'gm/atlastext.cpp')
-rw-r--r--gm/atlastext.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/gm/atlastext.cpp b/gm/atlastext.cpp
index 832a604e6e..ac5b3e4582 100644
--- a/gm/atlastext.cpp
+++ b/gm/atlastext.cpp
@@ -49,7 +49,8 @@ static SkScalar draw_string(SkAtlasTextTarget* target, const SkString& text, SkS
target->drawText(glyphs.get(), positions.get(), cnt, color, *font);
- return positions[cnt - 1].fX + widths[cnt - 1];
+ // Return the width of the of draw.
+ return positions[cnt - 1].fX + widths[cnt - 1] - positions[0].fX;
}
class AtlasTextGM : public skiagm::GM {
@@ -109,12 +110,30 @@ private:
auto size = 2 * s;
for (const auto& typeface : fTypefaces) {
for (const auto& text : kTexts) {
- uint32_t color = random.nextU();
- x = size + draw_string(fTarget.get(), text, x, y, color, typeface, size);
+ // Choose a random color but don't let alpha be too small to see.
+ uint32_t color = random.nextU() | 0x40000000;
+ fTarget->save();
+ // Randomly add a little bit of perspective
+ if (random.nextBool()) {
+ SkMatrix persp;
+ persp.reset();
+ persp.setPerspY(0.0005f);
+ persp.preTranslate(-x, -y + s);
+ persp.postTranslate(x, y - s);
+ fTarget->concat(persp);
+ }
+ // Randomly switch between positioning with a matrix vs x, y passed to draw.
+ SkScalar drawX = x, drawY = y;
+ if (random.nextBool()) {
+ fTarget->translate(x, y);
+ drawX = drawY = 0;
+ }
+ x += size +
+ draw_string(fTarget.get(), text, drawX, drawY, color, typeface, size);
x = SkScalarCeilToScalar(x);
- // Flush periodically to test continued drawing after a flush. Using color
- // to avoid churning the RNG and having to rebaseline images.
- if (!(color & 0xf)) {
+ fTarget->restore();
+ // Flush periodically to test continued drawing after a flush.
+ if ((random.nextU() % 8) == 0) {
fTarget->flush();
}
if (x + 100 > kSize) {