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

Side by Side Diff: bench/ImageFilterCollapse.cpp

Issue 1858813002: Update SkColorFilterImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 years, 8 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/ColorFilterBench.cpp ('k') | gm/coloremoji.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 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"
11 #include "SkColorFilterImageFilter.h" 11 #include "SkColorFilterImageFilter.h"
12 #include "SkColorMatrixFilter.h" 12 #include "SkColorMatrixFilter.h"
13 #include "SkGradientShader.h" 13 #include "SkGradientShader.h"
14 #include "SkImageFilter.h" 14 #include "SkImageFilter.h"
15 #include "SkTableColorFilter.h" 15 #include "SkTableColorFilter.h"
16 16
17 // Chains several matrix color filters image filter or several 17 // Chains several matrix color filters image filter or several
18 // table filter image filters and draws a bitmap. 18 // table filter image filters and draws a bitmap.
19 // This bench shows an improvement in performance and memory 19 // This bench shows an improvement in performance and memory
20 // when collapsing matrices or tables is implemented since all 20 // when collapsing matrices or tables is implemented since all
21 // the passes are collapsed in one. 21 // the passes are collapsed in one.
22 22
23 class BaseImageFilterCollapseBench : public Benchmark { 23 class BaseImageFilterCollapseBench : public Benchmark {
24 public: 24 public:
25 BaseImageFilterCollapseBench(): fImageFilter(nullptr) {} 25 BaseImageFilterCollapseBench() {}
26 ~BaseImageFilterCollapseBench() {
27 SkSafeUnref(fImageFilter);
28 }
29 26
30 protected: 27 protected:
31 void doPreDraw(sk_sp<SkColorFilter> colorFilters[], int nFilters) { 28 void doPreDraw(sk_sp<SkColorFilter> colorFilters[], int nFilters) {
29 SkASSERT(!fImageFilter);
30
32 // Create a chain of ImageFilters from colorFilters 31 // Create a chain of ImageFilters from colorFilters
33 fImageFilter = nullptr;
34 for(int i = nFilters; i --> 0;) { 32 for(int i = nFilters; i --> 0;) {
35 SkAutoTUnref<SkImageFilter> filter( 33 fImageFilter = SkColorFilterImageFilter::Make(colorFilters[i], fImag eFilter);
36 SkColorFilterImageFilter::Create(colorFilters[i].get(), fIma geFilter, nullptr)
37 );
38 SkRefCnt_SafeAssign(fImageFilter, filter.get());
39 } 34 }
40 } 35 }
41 36
42 void onDraw(int loops, SkCanvas* canvas) override { 37 void onDraw(int loops, SkCanvas* canvas) override {
43 makeBitmap(); 38 makeBitmap();
44 39
45 for(int i = 0; i < loops; i++) { 40 for(int i = 0; i < loops; i++) {
46 SkPaint paint; 41 SkPaint paint;
47 paint.setImageFilter(fImageFilter); 42 paint.setImageFilter(fImageFilter);
48 canvas->drawBitmap(fBitmap, 0, 0, &paint); 43 canvas->drawBitmap(fBitmap, 0, 0, &paint);
49 } 44 }
50 } 45 }
51 46
52 private: 47 private:
53 SkImageFilter* fImageFilter; 48 sk_sp<SkImageFilter> fImageFilter;
54 SkBitmap fBitmap; 49 SkBitmap fBitmap;
55 50
56 void makeBitmap() { 51 void makeBitmap() {
57 int W = 400; 52 int W = 400;
58 int H = 400; 53 int H = 400;
59 fBitmap.allocN32Pixels(W, H); 54 fBitmap.allocN32Pixels(W, H);
60 fBitmap.eraseColor(SK_ColorTRANSPARENT); 55 fBitmap.eraseColor(SK_ColorTRANSPARENT);
61 56
62 SkCanvas canvas(fBitmap); 57 SkCanvas canvas(fBitmap);
63 SkPaint paint; 58 SkPaint paint;
(...skipping 24 matching lines...) Expand all
88 float fi = i / 255.0f; 83 float fi = i / 255.0f;
89 table3[i] = static_cast<uint8_t>(sqrtf(fi) * 255); 84 table3[i] = static_cast<uint8_t>(sqrtf(fi) * 255);
90 } 85 }
91 86
92 sk_sp<SkColorFilter> colorFilters[] = { 87 sk_sp<SkColorFilter> colorFilters[] = {
93 SkTableColorFilter::Make(table1), 88 SkTableColorFilter::Make(table1),
94 SkTableColorFilter::Make(table2), 89 SkTableColorFilter::Make(table2),
95 SkTableColorFilter::Make(table3), 90 SkTableColorFilter::Make(table3),
96 }; 91 };
97 92
98 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); 93 this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
99 } 94 }
100 95
101 private: 96 private:
102 uint8_t table1[256], table2[256], table3[256]; 97 uint8_t table1[256], table2[256], table3[256];
103 }; 98 };
104 99
105 static sk_sp<SkColorFilter> make_brightness(float amount) { 100 static sk_sp<SkColorFilter> make_brightness(float amount) {
106 SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255)); 101 SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255));
107 SkScalar matrix[20] = { 1, 0, 0, 0, amount255, 102 SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
108 0, 1, 0, 0, amount255, 103 0, 1, 0, 0, amount255,
(...skipping 18 matching lines...) Expand all
127 return "image_filter_collapse_matrix"; 122 return "image_filter_collapse_matrix";
128 } 123 }
129 124
130 void onDelayedSetup() override { 125 void onDelayedSetup() override {
131 sk_sp<SkColorFilter> colorFilters[] = { 126 sk_sp<SkColorFilter> colorFilters[] = {
132 make_brightness(0.1f), 127 make_brightness(0.1f),
133 make_grayscale(), 128 make_grayscale(),
134 make_brightness(-0.1f), 129 make_brightness(-0.1f),
135 }; 130 };
136 131
137 doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters)); 132 this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
138 } 133 }
139 }; 134 };
140 135
141 DEF_BENCH(return new TableCollapseBench;) 136 DEF_BENCH(return new TableCollapseBench;)
142 DEF_BENCH(return new MatrixCollapseBench;) 137 DEF_BENCH(return new MatrixCollapseBench;)
OLDNEW
« no previous file with comments | « bench/ColorFilterBench.cpp ('k') | gm/coloremoji.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698