Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(877)

Unified Diff: gm/lcdoverlap.cpp

Issue 1358563002: add new gm to test overlapping lcd text (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/lcdoverlap.cpp
diff --git a/gm/lcdoverlap.cpp b/gm/lcdoverlap.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..17775646a6bee6256bb1924311311da8a1fb4925
--- /dev/null
+++ b/gm/lcdoverlap.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+/*
+ * Tests overlapping LCD text
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkSurface.h"
+#include "SkTextBlob.h"
+
+namespace skiagm {
+
+static const int kWidth = 750;
+static const int kHeight = 750;
+
+class LcdOverlapGM : public skiagm::GM {
+public:
+ LcdOverlapGM() {
+ const int kPointSize = 25;
+ fTextHeight = SkIntToScalar(kPointSize);
+ }
+
+protected:
+ SkString onShortName() override {
+ return SkString("lcdoverlap");
+ }
+
+ void onOnceBeforeDraw() override {
+ // build text blob
+ SkTextBlobBuilder builder;
+
+ SkPaint paint;
+ sk_tool_utils::set_portable_typeface(&paint);
+ paint.setTextSize(32);
+ const char* text = "able was I ere I saw elba";
+ paint.setAntiAlias(true);
+ paint.setSubpixelText(true);
+ paint.setLCDRenderText(true);
+ sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
+ fBlob.reset(builder.build());
+ }
+
+ SkISize onISize() override { return SkISize::Make(kWidth, kHeight); }
+
+ void drawTestCase(SkCanvas* canvas, SkScalar x, SkScalar y, SkXfermode::Mode mode,
+ SkXfermode::Mode mode2) {
+ const SkColor colors[] {
+ SK_ColorRED,
+ SK_ColorGREEN,
+ SK_ColorBLUE,
+ SK_ColorYELLOW,
+ SK_ColorCYAN,
+ SK_ColorMAGENTA,
+ };
+
+ SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(mode));
+ SkAutoTUnref<SkXfermode> xfermode2(SkXfermode::Create(mode2));
+ for (size_t i = 0; i < SK_ARRAY_COUNT(colors); i++) {
+ canvas->save();
+ canvas->translate(x, y);
+ canvas->rotate(360.0f / SK_ARRAY_COUNT(colors) * i);
+ canvas->translate(-fBlob->bounds().width() / 2.0f + 0.5f, 0);
+
+ SkPaint textPaint;
+ textPaint.setColor(colors[i]);
+ textPaint.setXfermode(i % 2 == 0 ? xfermode : xfermode2);
+ canvas->drawTextBlob(fBlob, 0, 0, textPaint);
+ canvas->restore();
+ }
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ SkScalar offsetX = kWidth / 4.0f;
+ SkScalar offsetY = kHeight / 4.0f;
+ drawTestCase(canvas, offsetX, offsetY, SkXfermode::kSrc_Mode, SkXfermode::kSrc_Mode);
+ drawTestCase(canvas, 3 * offsetX, offsetY, SkXfermode::kSrcOver_Mode,
+ SkXfermode::kSrcOver_Mode);
+ drawTestCase(canvas, offsetX, 3 * offsetY, SkXfermode::kHardLight_Mode,
+ SkXfermode::kLuminosity_Mode);
+ drawTestCase(canvas, 3 * offsetX, 3 * offsetY, SkXfermode::kSrcOver_Mode,
+ SkXfermode::kSrc_Mode);
+ }
+
+private:
+ SkScalar fTextHeight;
+ SkAutoTUnref<const SkTextBlob> fBlob;
+ typedef skiagm::GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return new LcdOverlapGM; )
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698