OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 /* | 9 /* |
10 * Tests text rendering with LCD and the various blend modes. | 10 * Tests text rendering with LCD and the various blend modes. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 SkCanvas* surfCanvas = surface->getCanvas(); | 69 SkCanvas* surfCanvas = surface->getCanvas(); |
70 this->drawColumn(surfCanvas, SK_ColorBLACK, SK_ColorWHITE, false); | 70 this->drawColumn(surfCanvas, SK_ColorBLACK, SK_ColorWHITE, false); |
71 surfCanvas->translate(SkIntToScalar(kColWidth), 0); | 71 surfCanvas->translate(SkIntToScalar(kColWidth), 0); |
72 this->drawColumn(surfCanvas, SK_ColorWHITE, SK_ColorBLACK, false); | 72 this->drawColumn(surfCanvas, SK_ColorWHITE, SK_ColorBLACK, false); |
73 surfCanvas->translate(SkIntToScalar(kColWidth), 0); | 73 surfCanvas->translate(SkIntToScalar(kColWidth), 0); |
74 this->drawColumn(surfCanvas, SK_ColorGREEN, SK_ColorMAGENTA, false); | 74 this->drawColumn(surfCanvas, SK_ColorGREEN, SK_ColorMAGENTA, false); |
75 surfCanvas->translate(SkIntToScalar(kColWidth), 0); | 75 surfCanvas->translate(SkIntToScalar(kColWidth), 0); |
76 this->drawColumn(surfCanvas, SK_ColorCYAN, SK_ColorMAGENTA, true); | 76 this->drawColumn(surfCanvas, SK_ColorCYAN, SK_ColorMAGENTA, true); |
77 | 77 |
78 SkPaint surfPaint; | 78 SkPaint surfPaint; |
79 SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(SkXfermode::kSrcOve
r_Mode)); | 79 surfPaint.setXfermode(SkXfermode::Make(SkXfermode::kSrcOver_Mode)); |
80 surfPaint.setXfermode(xfermode); | |
81 surface->draw(canvas, 0, 0, &surfPaint); | 80 surface->draw(canvas, 0, 0, &surfPaint); |
82 } | 81 } |
83 | 82 |
84 void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor
, bool useGrad) { | 83 void drawColumn(SkCanvas* canvas, SkColor backgroundColor, SkColor textColor
, bool useGrad) { |
85 const struct { | 84 const struct { |
86 SkXfermode::Mode fMode; | 85 SkXfermode::Mode fMode; |
87 const char* fLabel; | 86 const char* fLabel; |
88 } gModes[] = { | 87 } gModes[] = { |
89 { SkXfermode::kClear_Mode, "Clear" }, | 88 { SkXfermode::kClear_Mode, "Clear" }, |
90 { SkXfermode::kSrc_Mode, "Src" }, | 89 { SkXfermode::kSrc_Mode, "Src" }, |
(...skipping 25 matching lines...) Expand all Loading... |
116 { SkXfermode::kColor_Mode, "Color" }, | 115 { SkXfermode::kColor_Mode, "Color" }, |
117 { SkXfermode::kLuminosity_Mode, "Luminosity" }, | 116 { SkXfermode::kLuminosity_Mode, "Luminosity" }, |
118 }; | 117 }; |
119 // Draw background rect | 118 // Draw background rect |
120 SkPaint backgroundPaint; | 119 SkPaint backgroundPaint; |
121 backgroundPaint.setColor(backgroundColor); | 120 backgroundPaint.setColor(backgroundColor); |
122 canvas->drawRectCoords(0, 0, SkIntToScalar(kColWidth), SkIntToScalar(kHe
ight), | 121 canvas->drawRectCoords(0, 0, SkIntToScalar(kColWidth), SkIntToScalar(kHe
ight), |
123 backgroundPaint); | 122 backgroundPaint); |
124 SkScalar y = fTextHeight; | 123 SkScalar y = fTextHeight; |
125 for (size_t m = 0; m < SK_ARRAY_COUNT(gModes); m++) { | 124 for (size_t m = 0; m < SK_ARRAY_COUNT(gModes); m++) { |
126 SkAutoTUnref<SkXfermode> xfermode(SkXfermode::Create(gModes[m].fMode
)); | |
127 SkPaint paint; | 125 SkPaint paint; |
128 paint.setColor(textColor); | 126 paint.setColor(textColor); |
129 paint.setAntiAlias(true); | 127 paint.setAntiAlias(true); |
130 paint.setSubpixelText(true); | 128 paint.setSubpixelText(true); |
131 paint.setLCDRenderText(true); | 129 paint.setLCDRenderText(true); |
132 paint.setTextSize(fTextHeight); | 130 paint.setTextSize(fTextHeight); |
133 paint.setXfermode(xfermode); | 131 paint.setXfermode(SkXfermode::Make(gModes[m].fMode)); |
134 sk_tool_utils::set_portable_typeface(&paint); | 132 sk_tool_utils::set_portable_typeface(&paint); |
135 if (useGrad) { | 133 if (useGrad) { |
136 SkRect r; | 134 SkRect r; |
137 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei
ght); | 135 r.setXYWH(0, y - fTextHeight, SkIntToScalar(kColWidth), fTextHei
ght); |
138 paint.setShader(make_shader(r)); | 136 paint.setShader(make_shader(r)); |
139 } | 137 } |
140 SkString string(gModes[m].fLabel); | 138 SkString string(gModes[m].fLabel); |
141 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); | 139 canvas->drawText(gModes[m].fLabel, string.size(), 0, y, paint); |
142 y+=fTextHeight; | 140 y+=fTextHeight; |
143 } | 141 } |
144 } | 142 } |
145 | 143 |
146 private: | 144 private: |
147 SkScalar fTextHeight; | 145 SkScalar fTextHeight; |
148 sk_sp<SkShader> fCheckerboard; | 146 sk_sp<SkShader> fCheckerboard; |
149 typedef skiagm::GM INHERITED; | 147 typedef skiagm::GM INHERITED; |
150 }; | 148 }; |
151 | 149 |
152 ////////////////////////////////////////////////////////////////////////////// | 150 ////////////////////////////////////////////////////////////////////////////// |
153 | 151 |
154 DEF_GM( return new LcdBlendGM; ) | 152 DEF_GM( return new LcdBlendGM; ) |
155 } | 153 } |
OLD | NEW |