OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "Benchmark.h" | 8 #include "Benchmark.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 32 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, | 33 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, |
34 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 1
0 lines, 50 colors | 34 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK, // 1
0 lines, 50 colors |
35 }; | 35 }; |
36 | 36 |
37 static const SkColor gShallowColors[] = { 0xFF555555, 0xFF444444 }; | 37 static const SkColor gShallowColors[] = { 0xFF555555, 0xFF444444 }; |
38 | 38 |
39 // We have several special-cases depending on the number (and spacing) of colors
, so | 39 // We have several special-cases depending on the number (and spacing) of colors
, so |
40 // try to exercise those here. | 40 // try to exercise those here. |
41 static const GradData gGradData[] = { | 41 static const GradData gGradData[] = { |
42 { 2, gColors, NULL, "" }, | 42 { 2, gColors, nullptr, "" }, |
43 { 50, gColors, NULL, "_hicolor" }, // many color gradient | 43 { 50, gColors, nullptr, "_hicolor" }, // many color gradient |
44 { 3, gColors, NULL, "_3color" }, | 44 { 3, gColors, nullptr, "_3color" }, |
45 { 2, gShallowColors, NULL, "_shallow" }, | 45 { 2, gShallowColors, nullptr, "_shallow" }, |
46 }; | 46 }; |
47 | 47 |
48 /// Ignores scale | 48 /// Ignores scale |
49 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, | 49 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
50 SkShader::TileMode tm, float scale) { | 50 SkShader::TileMode tm, float scale) { |
51 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo
unt, tm); | 51 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo
unt, tm); |
52 } | 52 } |
53 | 53 |
54 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, | 54 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
55 SkShader::TileMode tm, float scale) { | 55 SkShader::TileMode tm, float scale) { |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 { SkIntToScalar(100), SkIntToScalar(100) }, | 347 { SkIntToScalar(100), SkIntToScalar(100) }, |
348 }; | 348 }; |
349 | 349 |
350 for (int i = 0; i < loops; i++) { | 350 for (int i = 0; i < loops; i++) { |
351 const int gray = i % 256; | 351 const int gray = i % 256; |
352 const int alpha = fHasAlpha ? gray : 0xFF; | 352 const int alpha = fHasAlpha ? gray : 0xFF; |
353 SkColor colors[] = { | 353 SkColor colors[] = { |
354 SK_ColorBLACK, | 354 SK_ColorBLACK, |
355 SkColorSetARGB(alpha, gray, gray, gray), | 355 SkColorSetARGB(alpha, gray, gray, gray), |
356 SK_ColorWHITE }; | 356 SK_ColorWHITE }; |
357 SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, | 357 SkShader* s = SkGradientShader::CreateLinear(pts, colors, nullptr, |
358 SK_ARRAY_COUNT(colors), | 358 SK_ARRAY_COUNT(colors), |
359 SkShader::kClamp_TileMo
de); | 359 SkShader::kClamp_TileMo
de); |
360 paint.setShader(s)->unref(); | 360 paint.setShader(s)->unref(); |
361 canvas->drawRect(r, paint); | 361 canvas->drawRect(r, paint); |
362 } | 362 } |
363 } | 363 } |
364 | 364 |
365 private: | 365 private: |
366 typedef Benchmark INHERITED; | 366 typedef Benchmark INHERITED; |
367 }; | 367 }; |
368 | 368 |
369 DEF_BENCH( return new Gradient2Bench(false); ) | 369 DEF_BENCH( return new Gradient2Bench(false); ) |
370 DEF_BENCH( return new Gradient2Bench(true); ) | 370 DEF_BENCH( return new Gradient2Bench(true); ) |
OLD | NEW |