aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm
diff options
context:
space:
mode:
authorGravatar cdalton <cdalton@nvidia.com>2014-07-25 14:13:57 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-25 14:13:57 -0700
commitb2808cd0411b5860f04f1364138674463768e414 (patch)
tree8db0814c25536e224db03941758e3faedea34231 /gm
parentfc7063b3a50f4cf0801301f7b7b7b119f6b41cf8 (diff)
Send less transform data when drawing text with nvpr
Before this change, GrStencilAndCoverTextContext would send 6-float affine transforms to drawPaths for every glyph. This updates it to concat the text scale onto the context matrix, and then only send 2-float translates (or 1-float x-translates when possible). Also adds a glyph_pos_align test to gm that exercises the newly added codepaths, and starts ignoring a few gm tests with benign pixel diffs until we can rebaseline. BUG=skia: R=bsalomon@google.com, kkinnunen@nvidia.com, jvanverth@google.com, bungeman@google.com Author: cdalton@nvidia.com Review URL: https://codereview.chromium.org/406523003
Diffstat (limited to 'gm')
-rw-r--r--gm/glyph_pos_align.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/gm/glyph_pos_align.cpp b/gm/glyph_pos_align.cpp
new file mode 100644
index 0000000000..9a94e75b92
--- /dev/null
+++ b/gm/glyph_pos_align.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkGradientShader.h"
+
+/**
+ * This test exercises drawPosTextH and drawPosText with every text align.
+ */
+static const int kWidth = 480;
+static const int kHeight = 600;
+static const SkScalar kTextHeight = 64.0f;
+static const int kMaxStringLength = 12;
+
+namespace skiagm {
+
+class GlyphPosAlignGM : public GM {
+protected:
+ virtual uint32_t onGetFlags() const SK_OVERRIDE {
+ return kSkipTiled_Flag;
+ }
+
+ virtual SkString onShortName() SK_OVERRIDE {
+ return SkString("glyph_pos_align");
+ }
+
+ virtual SkISize onISize() { return SkISize::Make(kWidth, kHeight); }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->clear(SK_ColorBLACK);
+
+ SkPaint paint;
+ paint.setTextSize(kTextHeight);
+ paint.setFakeBoldText(true);
+ const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE };
+ const SkPoint pts[] = {{0, 0}, {kWidth, kHeight}};
+ SkAutoTUnref<SkShader> grad(SkGradientShader::CreateLinear(pts, colors, NULL,
+ SK_ARRAY_COUNT(colors),
+ SkShader::kMirror_TileMode));
+ paint.setShader(grad);
+
+
+ paint.setTextAlign(SkPaint::kRight_Align);
+ drawTestCase(canvas, "Right Align", kTextHeight, paint);
+
+ paint.setTextAlign(SkPaint::kCenter_Align);
+ drawTestCase(canvas, "Center Align", 4 * kTextHeight, paint);
+
+ paint.setTextAlign(SkPaint::kLeft_Align);
+ drawTestCase(canvas, "Left Align", 7 * kTextHeight, paint);
+ }
+
+ void drawTestCase(SkCanvas* canvas, const char* text, SkScalar y, const SkPaint& paint) {
+ SkScalar widths[kMaxStringLength];
+ SkScalar posX[kMaxStringLength];
+ SkPoint pos[kMaxStringLength];
+ int length = strlen(text);
+ SkASSERT(length <= kMaxStringLength);
+
+ paint.getTextWidths(text, length, widths);
+
+ float originX;
+ switch (paint.getTextAlign()) {
+ case SkPaint::kRight_Align: originX = 1; break;
+ case SkPaint::kCenter_Align: originX = 0.5f; break;
+ case SkPaint::kLeft_Align: originX = 0; break;
+ default: SkFAIL("Invalid paint origin"); return;
+ }
+
+ float x = kTextHeight;
+ for (int i = 0; i < length; ++i) {
+ posX[i] = x + originX * widths[i];
+ pos[i].set(posX[i], i ? pos[i - 1].y() + 3 : y + kTextHeight);
+ x += widths[i];
+ }
+
+ canvas->drawPosTextH(text, length, posX, y, paint);
+ canvas->drawPosText(text, length, pos, paint);
+ }
+
+private:
+
+ typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static GM* GlyphPosAlignFactory(void*) {
+ return new GlyphPosAlignGM();
+}
+
+static GMRegistry reg(GlyphPosAlignFactory);
+
+}