blob: ffb6cd74441a2e5de76247cbe192ffbf6fc37b2b [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"
Mike Klein33d20552017-03-22 13:47:51 -040014#include "sk_tool_utils.h"
joshualitt496d29f2015-09-18 12:03:13 -070015#include "SkCanvas.h"
16#include "SkSurface.h"
17#include "SkTextBlob.h"
18
19namespace skiagm {
20
mtkleindbfd7ab2016-09-01 11:24:54 -070021constexpr int kWidth = 750;
22constexpr int kHeight = 750;
joshualitt496d29f2015-09-18 12:03:13 -070023
24class LcdOverlapGM : public skiagm::GM {
25public:
26 LcdOverlapGM() {
27 const int kPointSize = 25;
28 fTextHeight = SkIntToScalar(kPointSize);
29 }
30
31protected:
32 SkString onShortName() override {
33 return SkString("lcdoverlap");
34 }
35
36 void onOnceBeforeDraw() override {
37 // build text blob
38 SkTextBlobBuilder builder;
39
40 SkPaint paint;
41 sk_tool_utils::set_portable_typeface(&paint);
42 paint.setTextSize(32);
43 const char* text = "able was I ere I saw elba";
44 paint.setAntiAlias(true);
45 paint.setSubpixelText(true);
46 paint.setLCDRenderText(true);
47 sk_tool_utils::add_to_text_blob(&builder, text, paint, 0, 0);
fmalita37283c22016-09-13 10:00:23 -070048 fBlob = builder.make();
joshualitt496d29f2015-09-18 12:03:13 -070049 }
50
51 SkISize onISize() override { return SkISize::Make(kWidth, kHeight); }
52
reed374772b2016-10-05 17:33:02 -070053 void drawTestCase(SkCanvas* canvas, SkScalar x, SkScalar y, SkBlendMode mode,
54 SkBlendMode mode2) {
joshualitt496d29f2015-09-18 12:03:13 -070055 const SkColor colors[] {
56 SK_ColorRED,
57 SK_ColorGREEN,
58 SK_ColorBLUE,
59 SK_ColorYELLOW,
60 SK_ColorCYAN,
61 SK_ColorMAGENTA,
62 };
63
joshualitt496d29f2015-09-18 12:03:13 -070064 for (size_t i = 0; i < SK_ARRAY_COUNT(colors); i++) {
65 canvas->save();
66 canvas->translate(x, y);
67 canvas->rotate(360.0f / SK_ARRAY_COUNT(colors) * i);
68 canvas->translate(-fBlob->bounds().width() / 2.0f + 0.5f, 0);
69
70 SkPaint textPaint;
71 textPaint.setColor(colors[i]);
reed374772b2016-10-05 17:33:02 -070072 textPaint.setBlendMode(i % 2 == 0 ? mode : mode2);
joshualitt496d29f2015-09-18 12:03:13 -070073 canvas->drawTextBlob(fBlob, 0, 0, textPaint);
74 canvas->restore();
75 }
76 }
77
78 void onDraw(SkCanvas* canvas) override {
79 SkScalar offsetX = kWidth / 4.0f;
80 SkScalar offsetY = kHeight / 4.0f;
reed374772b2016-10-05 17:33:02 -070081 drawTestCase(canvas, offsetX, offsetY, SkBlendMode::kSrc, SkBlendMode::kSrc);
82 drawTestCase(canvas, 3 * offsetX, offsetY, SkBlendMode::kSrcOver, SkBlendMode::kSrcOver);
83 drawTestCase(canvas, offsetX, 3 * offsetY, SkBlendMode::kHardLight,
84 SkBlendMode::kLuminosity);
85 drawTestCase(canvas, 3 * offsetX, 3 * offsetY, SkBlendMode::kSrcOver, SkBlendMode::kSrc);
joshualitt496d29f2015-09-18 12:03:13 -070086 }
87
88private:
89 SkScalar fTextHeight;
fmalita37283c22016-09-13 10:00:23 -070090 sk_sp<SkTextBlob> fBlob;
joshualitt496d29f2015-09-18 12:03:13 -070091 typedef skiagm::GM INHERITED;
92};
93
94//////////////////////////////////////////////////////////////////////////////
95
96DEF_GM( return new LcdOverlapGM; )
97}