Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1095)

Side by Side Diff: bench/ColorCubeBench.cpp

Issue 1820303002: Revert of switch colorfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/BlurRoundRectBench.cpp ('k') | bench/ColorFilterBench.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 sk_sp<SkData> fCubeData; 16 SkData* fCubeData;
17 SkBitmap fBitmap; 17 SkBitmap fBitmap;
18 18
19 public: 19 public:
20 ColorCubeBench() : fCubeDimension(0) { 20 ColorCubeBench()
21 : fCubeDimension(0)
22 , fCubeData(nullptr) {
21 fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution 23 fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution
22 } 24 }
23 25
26 ~ColorCubeBench() {
27 SkSafeUnref(fCubeData);
28 }
29
24 protected: 30 protected:
25 const char* onGetName() override { 31 const char* onGetName() override {
26 return "colorcube"; 32 return "colorcube";
27 } 33 }
28 34
29 void onDelayedSetup() override { 35 void onDelayedSetup() override {
30 if (!SkToBool(fCubeData)) { 36 if (!SkToBool(fCubeData)) {
31 this->makeCubeData(); 37 this->makeCubeData();
32 this->make_bitmap(); 38 this->make_bitmap();
33 } 39 }
(...skipping 24 matching lines...) Expand all
58 canvas.clear(0x00000000); 64 canvas.clear(0x00000000);
59 SkPaint paint; 65 SkPaint paint;
60 paint.setAntiAlias(true); 66 paint.setAntiAlias(true);
61 paint.setShader(MakeLinear(fSize)); 67 paint.setShader(MakeLinear(fSize));
62 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei ght()) }; 68 SkRect r = { 0, 0, SkIntToScalar(fSize.width()), SkIntToScalar(fSize.hei ght()) };
63 canvas.drawRect(r, paint); 69 canvas.drawRect(r, paint);
64 } 70 }
65 71
66 void makeCubeData() { 72 void makeCubeData() {
67 fCubeDimension = 32; 73 fCubeDimension = 32;
68 fCubeData = SkData::MakeUninitialized(sizeof(SkColor) * 74 fCubeData = SkData::NewUninitialized(sizeof(SkColor) *
69 fCubeDimension * fCubeDimension * fCubeDimension); 75 fCubeDimension * fCubeDimension * fCubeDimension);
70 SkColor* pixels = (SkColor*)(fCubeData->writable_data()); 76 SkColor* pixels = (SkColor*)(fCubeData->writable_data());
71 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension); 77 SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension);
72 uint8_t* lut = lutMemory.get(); 78 uint8_t* lut = lutMemory.get();
73 const int maxIndex = fCubeDimension - 1; 79 const int maxIndex = fCubeDimension - 1;
74 for (int i = 0; i < fCubeDimension; ++i) { 80 for (int i = 0; i < fCubeDimension; ++i) {
75 // Make an invert lut, but the content of 81 // Make an invert lut, but the content of
76 // the lut shouldn't affect performance. 82 // the lut shouldn't affect performance.
77 lut[i] = ((maxIndex - i) * 255) / maxIndex; 83 lut[i] = ((maxIndex - i) * 255) / maxIndex;
78 } 84 }
79 for (int r = 0; r < fCubeDimension; ++r) { 85 for (int r = 0; r < fCubeDimension; ++r) {
80 for (int g = 0; g < fCubeDimension; ++g) { 86 for (int g = 0; g < fCubeDimension; ++g) {
81 for (int b = 0; b < fCubeDimension; ++b) { 87 for (int b = 0; b < fCubeDimension; ++b) {
82 pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] = 88 pixels[(fCubeDimension * ((fCubeDimension * b) + g)) + r] =
83 SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]); 89 SkColorSetARGB(0xFF, lut[r], lut[g], lut[b]);
84 } 90 }
85 } 91 }
86 } 92 }
87 } 93 }
88 94
89 void test(int loops, SkCanvas* canvas) { 95 void test(int loops, SkCanvas* canvas) {
90 SkPaint paint; 96 SkPaint paint;
91 for (int i = 0; i < loops; i++) { 97 for (int i = 0; i < loops; i++) {
92 paint.setColorFilter(SkColorCubeFilter::Make(fCubeData, fCubeDimensi on)); 98 SkAutoTUnref<SkColorFilter> colorCube(
99 SkColorCubeFilter::Create(fCubeData, fCubeDimension));
100 paint.setColorFilter(colorCube);
93 canvas->drawBitmap(fBitmap, 0, 0, &paint); 101 canvas->drawBitmap(fBitmap, 0, 0, &paint);
94 } 102 }
95 } 103 }
96 104
97 typedef Benchmark INHERITED; 105 typedef Benchmark INHERITED;
98 }; 106 };
99 107
100 /////////////////////////////////////////////////////////////////////////////// 108 ///////////////////////////////////////////////////////////////////////////////
101 109
102 DEF_BENCH( return new ColorCubeBench(); ) 110 DEF_BENCH( return new ColorCubeBench(); )
OLDNEW
« no previous file with comments | « bench/BlurRoundRectBench.cpp ('k') | bench/ColorFilterBench.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698