blob: 380878539f3adedcd4dea1895740c8200066723e [file] [log] [blame]
joshualitt496d29f2015-09-18 12:03:13 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9/*
10 * Tests overlapping LCD text
11 */
12
13#include "gm.h"
14#include "SkCanvas.h"
15#include "SkSurface.h"
16#include "SkTextBlob.h"
17
18namespace skiagm {
19
mtkleindbfd7ab2016-09-01 11:24:54 -070020constexpr int kWidth = 750;
21constexpr int kHeight = 750;
joshualitt496d29f2015-09-18 12:03:13 -070022
23class LcdOverlapGM : public skiagm::GM {
24public:
25 LcdOverlapGM() {
26 const int kPointSize = 25;
27 fTextHeight = SkIntToScalar(kPointSize);
28 }
29
30protected:
31 SkString onShortName() override {
32 return SkString("lcdoverlap");
33 }
34
35 void onOnceBeforeDraw() override {
36 // build text blob
37 SkTextBlobBuilder builder;
38
39 SkPaint paint;
40 sk_tool_utils::set_portable_typeface(&paint);
41 paint.setTextSize(32);
42 const char* text = "able was I ere I saw elba";
43 paint.setAntiAlias(true);
44 paint.setSubpixelText(true);
45 paint.setLCDRenderText(true);
46 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
fmalita37283c22016-09-13 10:00:23 -070047 fBlob = builder.make();
joshualitt496d29f2015-09-18 12:03:13 -070048 }
49
50 SkISize onISize() override { return SkISize::Make(kWidth, kHeight); }
51
reed374772b2016-10-05 17:33:02 -070052 void drawTestCase(SkCanvas* canvas, SkScalar x, SkScalar y, SkBlendMode mode,
53 SkBlendMode mode2) {
joshualitt496d29f2015-09-18 12:03:13 -070054 const SkColor colors[] {
55 SK_ColorRED,
56 SK_ColorGREEN,
57 SK_ColorBLUE,
58 SK_ColorYELLOW,
59 SK_ColorCYAN,
60 SK_ColorMAGENTA,
61 };
62
joshualitt496d29f2015-09-18 12:03:13 -070063 for (size_t i = 0; i < SK_ARRAY_COUNT(colors); i++) {
64 canvas->save();
65 canvas->translate(x, y);
66 canvas->rotate(360.0f / SK_ARRAY_COUNT(colors) * i);
67 canvas->translate(-fBlob->bounds().width() / 2.0f + 0.5f, 0);
68
69 SkPaint textPaint;
70 textPaint.setColor(colors[i]);
reed374772b2016-10-05 17:33:02 -070071 textPaint.setBlendMode(i % 2 == 0 ? mode : mode2);
joshualitt496d29f2015-09-18 12:03:13 -070072 canvas->drawTextBlob(fBlob, 0, 0, textPaint);
73 canvas->restore();
74 }
75 }
76
77 void onDraw(SkCanvas* canvas) override {
78 SkScalar offsetX = kWidth / 4.0f;
79 SkScalar offsetY = kHeight / 4.0f;
reed374772b2016-10-05 17:33:02 -070080 drawTestCase(canvas, offsetX, offsetY, SkBlendMode::kSrc, SkBlendMode::kSrc);
81 drawTestCase(canvas, 3 * offsetX, offsetY, SkBlendMode::kSrcOver, SkBlendMode::kSrcOver);
82 drawTestCase(canvas, offsetX, 3 * offsetY, SkBlendMode::kHardLight,
83 SkBlendMode::kLuminosity);
84 drawTestCase(canvas, 3 * offsetX, 3 * offsetY, SkBlendMode::kSrcOver, SkBlendMode::kSrc);
joshualitt496d29f2015-09-18 12:03:13 -070085 }
86
87private:
88 SkScalar fTextHeight;
fmalita37283c22016-09-13 10:00:23 -070089 sk_sp<SkTextBlob> fBlob;
joshualitt496d29f2015-09-18 12:03:13 -070090 typedef skiagm::GM INHERITED;
91};
92
93//////////////////////////////////////////////////////////////////////////////
94
95DEF_GM( return new LcdOverlapGM; )
96}