OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 | 109 |
110 static void set_face(SkPaint* paint) { | 110 static void set_face(SkPaint* paint) { |
111 SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic); | 111 SkTypeface* face = SkTypeface::CreateFromName("serif", SkTypeface::kItalic); |
112 SkSafeUnref(paint->setTypeface(face)); | 112 SkSafeUnref(paint->setTypeface(face)); |
113 } | 113 } |
114 | 114 |
115 static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& s
hader) { | 115 static void draw_pair(SkCanvas* canvas, SkPaint* paint, const sk_sp<SkShader>& s
hader) { |
116 const char text[] = "Now is the time for all good"; | 116 const char text[] = "Now is the time for all good"; |
117 const size_t len = strlen(text); | 117 const size_t len = strlen(text); |
118 | 118 |
119 paint->setShader(nullptr); | 119 paint->setShader(nullptr); |
120 canvas->drawText(text, len, 10, 20, *paint); | 120 canvas->drawText(text, len, 10, 20, *paint); |
121 paint->setShader(SkShader::MakeColorShader(paint->getColor())); | 121 paint->setShader(SkShader::MakeColorShader(paint->getColor())); |
122 canvas->drawText(text, len, 10, 40, *paint); | 122 canvas->drawText(text, len, 10, 40, *paint); |
123 paint->setShader(shader); | 123 paint->setShader(shader); |
124 canvas->drawText(text, len, 10, 60, *paint); | 124 canvas->drawText(text, len, 10, 60, *paint); |
125 } | 125 } |
126 | 126 |
127 class GammaShaderTextGM : public skiagm::GM { | 127 class GammaShaderTextGM : public skiagm::GM { |
128 sk_sp<SkShader> fShaders[3]; | 128 sk_sp<SkShader> fShaders[3]; |
129 SkColor fColors[3]; | 129 SkColor fColors[3]; |
130 | 130 |
131 public: | 131 public: |
132 GammaShaderTextGM() { | 132 GammaShaderTextGM() { |
133 const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE }; | 133 const SkColor colors[] = { SK_ColorBLACK, SK_ColorRED, SK_ColorBLUE }; |
134 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { | 134 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
135 fColors[i] = colors[i]; | 135 fColors[i] = colors[i]; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 protected: | 139 protected: |
140 SkString onShortName() override { | 140 SkString onShortName() override { |
141 return SkString("gammagradienttext"); | 141 return SkString("gammagradienttext"); |
142 } | 142 } |
143 | 143 |
144 SkISize onISize() override { | 144 SkISize onISize() override { |
145 return SkISize::Make(300, 300); | 145 return SkISize::Make(300, 300); |
146 } | 146 } |
147 | 147 |
148 void onOnceBeforeDraw() override { | 148 void onOnceBeforeDraw() override { |
149 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { | 149 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
150 fShaders[i] = make_gradient(fColors[i]); | 150 fShaders[i] = make_gradient(fColors[i]); |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 void onDraw(SkCanvas* canvas) override { | 154 void onDraw(SkCanvas* canvas) override { |
155 SkPaint paint; | 155 SkPaint paint; |
156 paint.setAntiAlias(true); | 156 paint.setAntiAlias(true); |
157 paint.setLCDRenderText(true); | 157 paint.setLCDRenderText(true); |
158 paint.setTextSize(18); | 158 paint.setTextSize(18); |
159 set_face(&paint); | 159 set_face(&paint); |
160 | 160 |
161 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { | 161 for (size_t i = 0; i < SK_ARRAY_COUNT(fShaders); ++i) { |
162 paint.setColor(fColors[i]); | 162 paint.setColor(fColors[i]); |
163 draw_pair(canvas, &paint, fShaders[i]); | 163 draw_pair(canvas, &paint, fShaders[i]); |
164 canvas->translate(0, 80); | 164 canvas->translate(0, 80); |
165 } | 165 } |
166 } | 166 } |
167 | 167 |
168 private: | 168 private: |
169 typedef skiagm::GM INHERITED; | 169 typedef skiagm::GM INHERITED; |
170 }; | 170 }; |
171 | 171 |
172 DEF_GM( return new GammaShaderTextGM; ) | 172 DEF_GM( return new GammaShaderTextGM; ) |
173 | |
OLD | NEW |