OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "Benchmark.h" | 7 #include "Benchmark.h" |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkColorCubeFilter.h" | 9 #include "SkColorCubeFilter.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
11 #include "SkTemplates.h" | 11 #include "SkTemplates.h" |
12 | 12 |
13 class ColorCubeBench : public Benchmark { | 13 class ColorCubeBench : public Benchmark { |
14 SkISize fSize; | 14 SkISize fSize; |
15 int fCubeDimension; | 15 int fCubeDimension; |
16 SkData* fCubeData; | 16 sk_sp<SkData> fCubeData; |
17 SkBitmap fBitmap; | 17 SkBitmap fBitmap; |
18 | 18 |
19 public: | 19 public: |
20 ColorCubeBench() | 20 ColorCubeBench() : fCubeDimension(0) { |
21 : fCubeDimension(0) | |
22 , fCubeData(nullptr) { | |
23 fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution | 21 fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution |
24 } | 22 } |
25 | 23 |
26 ~ColorCubeBench() { | |
27 SkSafeUnref(fCubeData); | |
28 } | |
29 | |
30 protected: | 24 protected: |
31 const char* onGetName() override { | 25 const char* onGetName() override { |
32 return "colorcube"; | 26 return "colorcube"; |
33 } | 27 } |
34 | 28 |
35 void onDelayedSetup() override { | 29 void onDelayedSetup() override { |
36 if (!SkToBool(fCubeData)) { | 30 if (!SkToBool(fCubeData)) { |
37 this->makeCubeData(); | 31 this->makeCubeData(); |
38 this->make_bitmap(); | 32 this->make_bitmap(); |
39 } | 33 } |
(...skipping 24 matching lines...) Expand all Loading... |
64 canvas.clear(0x00000000); | 58 canvas.clear(0x00000000); |
65 SkPaint paint; | 59 SkPaint paint; |
66 paint.setAntiAlias(true); | 60 paint.setAntiAlias(true); |
67 paint.setShader(MakeLinear(fSize)); | 61 paint.setShader(MakeLinear(fSize)); |
68 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei
ght()) }; | 62 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei
ght()) }; |
69 canvas.drawRect(r, paint); | 63 canvas.drawRect(r, paint); |
70 } | 64 } |
71 | 65 |
72 void makeCubeData() { | 66 void makeCubeData() { |
73 fCubeDimension = 32; | 67 fCubeDimension = 32; |
74 fCubeData = SkData::NewUninitialized(sizeof(SkColor) * | 68 fCubeData = SkData::MakeUninitialized(sizeof(SkColor) * |
75 fCubeDimension * fCubeDimension * fCubeDimension); | 69 fCubeDimension * fCubeDimension * fCubeDimension); |
76 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); | 70 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); |
77 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); | 71 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); |
78 uint8_t* lut = lutMemory.get(); | 72 uint8_t* lut = lutMemory.get(); |
79 const int maxIndex = fCubeDimension - 1; | 73 const int maxIndex = fCubeDimension - 1; |
80 for (int i = 0; i < fCubeDimension; ++i) { | 74 for (int i = 0; i < fCubeDimension; ++i) { |
81 // Make an invert lut, but the content of | 75 // Make an invert lut, but the content of |
82 // the lut shouldn't affect performance. | 76 // the lut shouldn't affect performance. |
83 lut[i] = ((maxIndex - i) * 255) / maxIndex; | 77 lut[i] = ((maxIndex - i) * 255) / maxIndex; |
84 } | 78 } |
85 for (int r = 0; r < fCubeDimension; ++r) { | 79 for (int r = 0; r < fCubeDimension; ++r) { |
86 for (int g = 0; g < fCubeDimension; ++g) { | 80 for (int g = 0; g < fCubeDimension; ++g) { |
87 for (int b = 0; b < fCubeDimension; ++b) { | 81 for (int b = 0; b < fCubeDimension; ++b) { |
88 pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = | 82 pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = |
89 SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]); | 83 SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]); |
90 } | 84 } |
91 } | 85 } |
92 } | 86 } |
93 } | 87 } |
94 | 88 |
95 void test(int loops, SkCanvas* canvas) { | 89 void test(int loops, SkCanvas* canvas) { |
96 SkPaint paint; | 90 SkPaint paint; |
97 for (int i = 0; i < loops; i++) { | 91 for (int i = 0; i < loops; i++) { |
98 SkAutoTUnref<SkColorFilter> colorCube( | 92 paint.setColorFilter(SkColorCubeFilter::Make(fCubeData, fCubeDimensi
on)); |
99 SkColorCubeFilter::Create(fCubeData, fCubeDimension)); | |
100 paint.setColorFilter(colorCube); | |
101 canvas->drawBitmap(fBitmap, 0, 0, &paint); | 93 canvas->drawBitmap(fBitmap, 0, 0, &paint); |
102 } | 94 } |
103 } | 95 } |
104 | 96 |
105 typedef Benchmark INHERITED; | 97 typedef Benchmark INHERITED; |
106 }; | 98 }; |
107 | 99 |
108 /////////////////////////////////////////////////////////////////////////////// | 100 /////////////////////////////////////////////////////////////////////////////// |
109 | 101 |
110 DEF_BENCH( return new ColorCubeBench(); ) | 102 DEF_BENCH( return new ColorCubeBench(); ) |
OLD | NEW |