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 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "Resources.h" | 10 #include "Resources.h" |
11 #include "SkGradientShader.h" | 11 #include "SkGradientShader.h" |
12 #include "SkPM4fPriv.h" | 12 #include "SkPM4fPriv.h" |
| 13 #include "SkPath.h" |
| 14 #include "sk_tool_utils.h" |
13 | 15 |
14 DEF_SIMPLE_GM(gamma, canvas, 560, 200) { | 16 DEF_SIMPLE_GM(gamma, canvas, 560, 200) { |
15 SkPaint p; | 17 SkPaint p; |
16 const SkScalar sz = 50.0f; | 18 const SkScalar sz = 50.0f; |
17 const int szInt = SkScalarTruncToInt(sz); | 19 const int szInt = SkScalarTruncToInt(sz); |
18 const SkScalar tx = sz + 5.0f; | 20 const SkScalar tx = sz + 5.0f; |
19 const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz); | 21 const SkRect r = SkRect::MakeXYWH(0, 0, sz, sz); |
20 SkShader::TileMode rpt = SkShader::kRepeat_TileMode; | 22 SkShader::TileMode rpt = SkShader::kRepeat_TileMode; |
21 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 23 auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
22 | 24 |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 nextXferRect(SK_ColorWHITE, SkXfermode::kSrcIn_Mode, 0x7fff00ff); | 177 nextXferRect(SK_ColorWHITE, SkXfermode::kSrcIn_Mode, 0x7fff00ff); |
176 nextXferRect(0x7fff00ff, SkXfermode::kDstIn_Mode, SK_ColorWHITE); | 178 nextXferRect(0x7fff00ff, SkXfermode::kDstIn_Mode, SK_ColorWHITE); |
177 nextXferRect(sqrtHalfWhite, SkXfermode::kSrcIn_Mode, sqrtHalfAlpha); | 179 nextXferRect(sqrtHalfWhite, SkXfermode::kSrcIn_Mode, sqrtHalfAlpha); |
178 nextXferRect(sqrtHalfAlpha, SkXfermode::kDstIn_Mode, sqrtHalfWhite); | 180 nextXferRect(sqrtHalfAlpha, SkXfermode::kDstIn_Mode, sqrtHalfWhite); |
179 | 181 |
180 nextXferRect(0xff3f3f3f, SkXfermode::kPlus_Mode, 0xff3f3f3f); | 182 nextXferRect(0xff3f3f3f, SkXfermode::kPlus_Mode, 0xff3f3f3f); |
181 nextXferRect(sqrtHalfWhite, SkXfermode::kModulate_Mode, sqrtHalfWhite); | 183 nextXferRect(sqrtHalfWhite, SkXfermode::kModulate_Mode, sqrtHalfWhite); |
182 | 184 |
183 canvas->restore(); | 185 canvas->restore(); |
184 } | 186 } |
| 187 |
| 188 DEF_SIMPLE_GM(gamma1b, canvas, 800, 600) { |
| 189 SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); |
| 190 canvas->getProps(&props); |
| 191 SkPaint bgp; |
| 192 // if (props.isGammaCorrect()) { |
| 193 bgp.setColor(0xFF7f7f7f); |
| 194 // } else { |
| 195 // bgp.setColor(0xFFbcbcbc); |
| 196 // } |
| 197 canvas->drawRect(SkRect::MakeWH(1100, 650), bgp); |
| 198 |
| 199 SkPaint p; |
| 200 |
| 201 // Black -> White gradient, scaled to sample just the middle. |
| 202 // Tests gradient interpolation. |
| 203 SkPoint points[2] = { |
| 204 SkPoint::Make(50, 0), |
| 205 SkPoint::Make(1050, 0) |
| 206 }; |
| 207 SkColor colors[2] = { SK_ColorBLACK, SK_ColorWHITE }; |
| 208 SkColor colors2[2] = { SK_ColorRED, SK_ColorGREEN }; |
| 209 SkColor colors3[2] = { SK_ColorRED, SK_ColorBLUE }; |
| 210 SkColor colors4[2] = { SK_ColorCYAN, SK_ColorYELLOW }; |
| 211 p.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, |
| 212 SkShader::kClamp_TileMode)); |
| 213 canvas->drawRect(SkRect::MakeXYWH(50, 50, 1000, 100), p); |
| 214 |
| 215 p.setShader(SkGradientShader::MakeLinear(points, colors2, nullptr, 2, |
| 216 SkShader::kClamp_TileMode)); |
| 217 canvas->drawRect(SkRect::MakeXYWH(50, 200, 1000, 100), p); |
| 218 |
| 219 p.setShader(SkGradientShader::MakeLinear(points, colors3, nullptr, 2, |
| 220 SkShader::kClamp_TileMode)); |
| 221 canvas->drawRect(SkRect::MakeXYWH(50, 350, 1000, 100), p); |
| 222 |
| 223 p.setShader(SkGradientShader::MakeLinear(points, colors4, nullptr, 2, |
| 224 SkShader::kClamp_TileMode)); |
| 225 canvas->drawRect(SkRect::MakeXYWH(50, 500, 1000, 100), p); |
| 226 } |
| 227 |
| 228 DEF_SIMPLE_GM(gamma2, canvas, 800, 600) { |
| 229 canvas->clear(SK_ColorBLACK); |
| 230 SkBitmap bmp = sk_tool_utils::create_checkerboard_bitmap(400, 400, |
| 231 SK_ColorRED, SK_Col
orGREEN, 1); |
| 232 SkPaint p2; |
| 233 p2.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 234 canvas->drawBitmap(bmp, 50, 50, &p2); |
| 235 } |
| 236 |
| 237 DEF_SIMPLE_GM(gamma3, canvas, 800, 600) { |
| 238 canvas->clear(SK_ColorBLACK); |
| 239 SkBitmap bmp = sk_tool_utils::create_checkerboard_bitmap(400, 400, |
| 240 SK_ColorRED, SK_Col
orGREEN, 1); |
| 241 |
| 242 SkPaint p2; |
| 243 p2.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 244 canvas->drawBitmap(bmp, 50, 50, &p2); |
| 245 |
| 246 SkPaint p; |
| 247 p.setColor(SK_ColorRED); |
| 248 canvas->drawRect(SkRect::MakeXYWH(600, 50, 400, 400), p); |
| 249 p.setColor(0x7f00FF00); |
| 250 canvas->drawRect(SkRect::MakeXYWH(1000, 450, 400, 400), p); |
| 251 } |
| 252 |
| 253 DEF_SIMPLE_GM(gamma4, canvas, 800, 600) { |
| 254 canvas->clear(SK_ColorBLACK); |
| 255 SkBitmap bmp = sk_tool_utils::create_checkerboard_bitmap(400, 400, |
| 256 SK_ColorRED, SK_Col
orGREEN, 1); |
| 257 |
| 258 SkPaint p2; |
| 259 p2.setFilterQuality(SkFilterQuality::kMedium_SkFilterQuality); |
| 260 canvas->drawBitmap(bmp, 50, 50, &p2); |
| 261 |
| 262 SkPaint p; |
| 263 p.setColor(SK_ColorRED); |
| 264 canvas->drawRect(SkRect::MakeXYWH(600, 50, 400, 400), p); |
| 265 p.setColor(0x7f00FF00); |
| 266 canvas->drawRect(SkRect::MakeXYWH(800, 250, 400, 400), p); |
| 267 } |
| 268 |
| 269 DEF_SIMPLE_GM(gamma5, canvas, 500, 200) { |
| 270 SkPaint p; |
| 271 p.setAntiAlias(true); |
| 272 |
| 273 canvas->clear(SK_ColorWHITE); |
| 274 |
| 275 SkPath path; |
| 276 /* path.moveTo(50, 500); |
| 277 path.lineTo(400, 400); |
| 278 path.lineTo(850, 350); |
| 279 path.lineTo(650, 140); |
| 280 path.close(); |
| 281 */ |
| 282 for (int i = 0; i < 12; ++i) { |
| 283 SkScalar r = 2 * SK_ScalarPI * (i / 12.f); |
| 284 auto s = SkScalarSin(r) * 400.f; |
| 285 auto c = SkScalarCos(r) * 700.f; |
| 286 if (i == 0) { |
| 287 path.moveTo(1000.f + c, 500.f + s); |
| 288 } else { |
| 289 path.lineTo(1000.f + c, 500.f + s); |
| 290 } |
| 291 } |
| 292 path.close(); |
| 293 canvas->drawPath(path, p); |
| 294 } |
OLD | NEW |