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

Side by Side Diff: gm/lcdblendmodes.cpp

Issue 1313623002: Add support for blending of LCD for all blend modes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | include/gpu/effects/GrPorterDuffXferProcessor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
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 text rendering with LCD and the various blend modes.
11 */
12
13 #include "gm.h"
14 #include "SkCanvas.h"
15 #include "SkGradientShader.h"
16
17 namespace skiagm {
18
19 static const int kColWidth = 180;
20 static const int kNumCols = 4;
21 static const int kWidth = kColWidth * kNumCols;
22 static const int kHeight = 750;
23
24 static SkShader* make_shader(const SkRect& bounds) {
25 const SkPoint pts[] = {
26 { bounds.left(), bounds.top() },
27 { bounds.right(), bounds.bottom() },
28 };
29 const SkColor colors[] = {
30 SK_ColorRED, SK_ColorGREEN,
31 };
32 return SkGradientShader::CreateLinear(pts,
33 colors, nullptr, SK_ARRAY_COUNT(colors ),
34 SkShader::kRepeat_TileMode);
35 }
36
37 class LcdBlendGM : public skiagm::GM {
38 public:
39 LcdBlendGM() {
40 const int kPointSize = 25;
41 fTextHeight = SkIntToScalar(kPointSize);
42 }
43
44 protected:
45 SkString onShortName() override {
46 SkString name("lcdblendmodes");
47 name.append(sk_tool_utils::major_platform_os_name());
48 return name;
49 }
50
51 SkISize onISize() override { return SkISize::Make(kWidth, kHeight); }
52
53 void onDraw(SkCanvas* canvas) override {
54 this->drawColumn(canvas, SK_ColorBLACK, SK_ColorWHITE, false);
55 canvas->translate(SkIntToScalar(kColWidth), 0);
56 this->drawColumn(canvas, SK_ColorWHITE, SK_ColorBLACK, false);
57 canvas->translate(SkIntToScalar(kColWidth), 0);
58 this->drawColumn(canvas, SK_ColorGREEN, SK_ColorMAGENTA, false);
59 canvas->translate(SkIntToScalar(kColWidth), 0);
60 this->drawColumn(canvas, SK_ColorCYAN, SK_ColorMAGENTA, true);
61 }
62
63 void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor , bool useGrad) {
64 const struct {
65 SkXfermode::Mode fMode;
66 const char* fLabel;
67 } gModes[] = {
68 { SkXfermode::kClear_Mode, "Clear" },
69 { SkXfermode::kSrc_Mode, "Src" },
70 { SkXfermode::kDst_Mode, "Dst" },
71 { SkXfermode::kSrcOver_Mode, "SrcOver" },
72 { SkXfermode::kDstOver_Mode, "DstOver" },
73 { SkXfermode::kSrcIn_Mode, "SrcIn" },
74 { SkXfermode::kDstIn_Mode, "DstIn" },
75 { SkXfermode::kSrcOut_Mode, "SrcOut" },
76 { SkXfermode::kDstOut_Mode, "DstOut" },
77 { SkXfermode::kSrcATop_Mode, "SrcATop" },
78 { SkXfermode::kDstATop_Mode, "DstATop" },
79 { SkXfermode::kXor_Mode, "Xor" },
80 { SkXfermode::kPlus_Mode, "Plus" },
81 { SkXfermode::kModulate_Mode, "Modulate" },
82 { SkXfermode::kScreen_Mode, "Screen" },
83 { SkXfermode::kOverlay_Mode, "Overlay" },
84 { SkXfermode::kDarken_Mode, "Darken" },
85 { SkXfermode::kLighten_Mode, "Lighten" },
86 { SkXfermode::kColorDodge_Mode, "ColorDodge" },
87 { SkXfermode::kColorBurn_Mode, "ColorBurn" },
88 { SkXfermode::kHardLight_Mode, "HardLight" },
89 { SkXfermode::kSoftLight_Mode, "SoftLight" },
90 { SkXfermode::kDifference_Mode, "Difference" },
91 { SkXfermode::kExclusion_Mode, "Exclusion" },
92 { SkXfermode::kMultiply_Mode, "Multiply" },
93 { SkXfermode::kHue_Mode, "Hue" },
94 { SkXfermode::kSaturation_Mode, "Saturation" },
95 { SkXfermode::kColor_Mode, "Color" },
96 { SkXfermode::kLuminosity_Mode, "Luminosity" },
97 };
98 // Draw background rect
99 SkPaint backgroundPaint;
100 backgroundPaint.setColor(backgroundColor);
101 canvas->drawRectCoords(0, 0, SkIntToScalar(kColWidth), SkIntToScalar(kHe ight),
102 backgroundPaint);
103 SkScalar y = fTextHeight;
104 for (size_t m = 0; m < SK_ARRAY_COUNT(gModes); m++) {
105 SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(gModes[m].fMode ));
106 SkPaint paint;
107 paint.setColor(textColor);
108 paint.setAntiAlias(true);
109 paint.setSubpixelText(true);
110 paint.setLCDRenderText(true);
111 paint.setTextSize(fTextHeight);
112 paint.setXfermode(xfermode);
113 sk_tool_utils::set_portable_typeface(&paint);
114 if (useGrad) {
115 SkRect r;
116 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei ght);
117 paint.setShader(make_shader(r))->unref();
118 }
119 SkString string(gModes[m].fLabel);
120 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint);
121 y+=fTextHeight;
122 }
123 }
124
125 private:
126 SkScalar fTextHeight;
127 typedef skiagm::GM INHERITED;
128 };
129
130 //////////////////////////////////////////////////////////////////////////////
131
132 DEF_GM( return new LcdBlendGM; )
133 }
OLDNEW
« no previous file with comments | « no previous file | include/gpu/effects/GrPorterDuffXferProcessor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698