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

Side by Side Diff: tests/SkColor4fTest.cpp

Issue 1822623002: switch colorfilters to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase 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 | « tests/SerializationTest.cpp ('k') | tools/android/SkAndroidSDKCanvas.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 2016 Google Inc. 2 * Copyright 2016 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 "SkColor.h" 8 #include "SkColor.h"
9 #include "SkColorMatrixFilter.h" 9 #include "SkColorMatrixFilter.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 pm4 = c4.premul(); 71 pm4 = c4.premul();
72 REPORTER_ASSERT(reporter, pm4.fVec[SK_A_INDEX] == c4.fA); 72 REPORTER_ASSERT(reporter, pm4.fVec[SK_A_INDEX] == c4.fA);
73 REPORTER_ASSERT(reporter, nearly_equal(pm4.r(), c4.fA * c4.fR)); 73 REPORTER_ASSERT(reporter, nearly_equal(pm4.r(), c4.fA * c4.fR));
74 REPORTER_ASSERT(reporter, nearly_equal(pm4.g(), c4.fA * c4.fG)); 74 REPORTER_ASSERT(reporter, nearly_equal(pm4.g(), c4.fA * c4.fG));
75 REPORTER_ASSERT(reporter, nearly_equal(pm4.b(), c4.fA * c4.fB)); 75 REPORTER_ASSERT(reporter, nearly_equal(pm4.b(), c4.fA * c4.fB));
76 } 76 }
77 } 77 }
78 78
79 //////////////////////////////////////////////////////////////////////////////// ////////////////// 79 //////////////////////////////////////////////////////////////////////////////// //////////////////
80 80
81 static SkColorFilter* make_mode_cf() { 81 static sk_sp<SkColorFilter> make_mode_cf() {
82 return SkColorFilter::CreateModeFilter(0xFFBB8855, SkXfermode::kPlus_Mode); 82 return SkColorFilter::MakeModeFilter(0xFFBB8855, SkXfermode::kPlus_Mode);
83 } 83 }
84 84
85 static SkColorFilter* make_mx_cf() { 85 static sk_sp<SkColorFilter> make_mx_cf() {
86 const float mx[] = { 86 const float mx[] = {
87 0.5f, 0, 0, 0, 0.1f, 87 0.5f, 0, 0, 0, 0.1f,
88 0, 0.5f, 0, 0, 0.2f, 88 0, 0.5f, 0, 0, 0.2f,
89 0, 0, 1, 0, -0.1f, 89 0, 0, 1, 0, -0.1f,
90 0, 0, 0, 1, 0, 90 0, 0, 0, 1, 0,
91 }; 91 };
92 return SkColorMatrixFilter::Create(mx); 92 return SkColorFilter::MakeMatrixFilterRowMajor255(mx);
93 } 93 }
94 94
95 static SkColorFilter* make_compose_cf() { 95 static sk_sp<SkColorFilter> make_compose_cf() {
96 SkAutoTUnref<SkColorFilter> cf0(make_mode_cf()); 96 return SkColorFilter::MakeComposeFilter(make_mode_cf(), make_mx_cf());
97 SkAutoTUnref<SkColorFilter> cf1(make_mx_cf());
98 return SkColorFilter::CreateComposeFilter(cf0, cf1);
99 } 97 }
100 98
101 static sk_sp<SkShader> make_color_sh() { return SkShader::MakeColorShader(0xFFBB 8855); } 99 static sk_sp<SkShader> make_color_sh() { return SkShader::MakeColorShader(0xFFBB 8855); }
102 100
103 static sk_sp<SkShader> make_image_sh() { 101 static sk_sp<SkShader> make_image_sh() {
104 const SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); 102 const SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
105 const SkPMColor pixels[] { 103 const SkPMColor pixels[] {
106 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 104 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
107 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 105 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
108 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 106 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
109 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55), 107 SkPackARGB32(0xFF, 0xBB, 0x88, 0x55),
110 }; 108 };
111 sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(info, pixels, sizeof(S kPMColor) * 2))); 109 sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(info, pixels, sizeof(S kPMColor) * 2)));
112 return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMod e); 110 return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMod e);
113 } 111 }
114 112
115 static sk_sp<SkShader> make_grad_sh() { 113 static sk_sp<SkShader> make_grad_sh() {
116 #if 0 114 #if 0
117 const SkPoint pts[] {{ 0, 0 }, { 100, 100 }}; 115 const SkPoint pts[] {{ 0, 0 }, { 100, 100 }};
118 const SkColor colors[] { SK_ColorRED, SK_ColorBLUE }; 116 const SkColor colors[] { SK_ColorRED, SK_ColorBLUE };
119 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode); 117 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, SkShader::kCl amp_TileMode);
120 #else 118 #else
121 // TODO: need to convert new gradient code to enforce PM4f --> RGBA order 119 // TODO: need to convert new gradient code to enforce PM4f --> RGBA order
122 return make_color_sh(); 120 return make_color_sh();
123 #endif 121 #endif
124 } 122 }
125 123
126 static sk_sp<SkShader> make_cf_sh() { 124 static sk_sp<SkShader> make_cf_sh() {
127 SkAutoTUnref<SkColorFilter> filter(make_mx_cf()); 125 return make_color_sh()->makeWithColorFilter(make_mx_cf());
128 return make_color_sh()->makeWithColorFilter(filter);
129 } 126 }
130 127
131 static bool compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int c ount, 128 static bool compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int c ount,
132 float tolerance = 1.0f/255) { 129 float tolerance = 1.0f/255) {
133 for (int i = 0; i < count; ++i) { 130 for (int i = 0; i < count; ++i) {
134 SkPM4f c0 = SkPM4f::FromPMColor(span4b[i]); 131 SkPM4f c0 = SkPM4f::FromPMColor(span4b[i]);
135 SkPM4f c1 = span4f[i]; 132 SkPM4f c1 = span4f[i];
136 if (!nearly_equal(c0, c1, tolerance)) { 133 if (!nearly_equal(c0, c1, tolerance)) {
137 return false; 134 return false;
138 } 135 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 SkPMColor buffer4b[N]; 168 SkPMColor buffer4b[N];
172 ctx->shadeSpan(0, 0, buffer4b, N); 169 ctx->shadeSpan(0, 0, buffer4b, N);
173 REPORTER_ASSERT(reporter, compare_spans(buffer4f, buffer4b, N, rec.f Tolerance)); 170 REPORTER_ASSERT(reporter, compare_spans(buffer4f, buffer4b, N, rec.f Tolerance));
174 } 171 }
175 ctx->~Context(); 172 ctx->~Context();
176 } 173 }
177 } 174 }
178 175
179 DEF_TEST(Color4f_colorfilter, reporter) { 176 DEF_TEST(Color4f_colorfilter, reporter) {
180 struct { 177 struct {
181 SkColorFilter* (*fFact)(); 178 sk_sp<SkColorFilter> (*fFact)();
182 bool fSupports4f; 179 bool fSupports4f;
183 const char* fName; 180 const char* fName;
184 } recs[] = { 181 } recs[] = {
185 { make_mode_cf, true, "mode" }, 182 { make_mode_cf, true, "mode" },
186 { make_mx_cf, true, "matrix" }, 183 { make_mx_cf, true, "matrix" },
187 { make_compose_cf, true, "compose" }, 184 { make_compose_cf, true, "compose" },
188 }; 185 };
189 186
190 // prepare the src 187 // prepare the src
191 const int N = 100; 188 const int N = 100;
192 SkPMColor src4b[N]; 189 SkPMColor src4b[N];
193 SkPM4f src4f[N]; 190 SkPM4f src4f[N];
194 SkRandom rand; 191 SkRandom rand;
195 for (int i = 0; i < N; ++i) { 192 for (int i = 0; i < N; ++i) {
196 src4b[i] = SkPreMultiplyColor(rand.nextU()); 193 src4b[i] = SkPreMultiplyColor(rand.nextU());
197 src4f[i] = SkPM4f::FromPMColor(src4b[i]); 194 src4f[i] = SkPM4f::FromPMColor(src4b[i]);
198 } 195 }
199 // confirm that our srcs are (nearly) equal 196 // confirm that our srcs are (nearly) equal
200 REPORTER_ASSERT(reporter, compare_spans(src4f, src4b, N)); 197 REPORTER_ASSERT(reporter, compare_spans(src4f, src4b, N));
201 198
202 for (const auto& rec : recs) { 199 for (const auto& rec : recs) {
203 SkAutoTUnref<SkColorFilter> filter(rec.fFact()); 200 auto filter(rec.fFact());
204 SkPMColor dst4b[N]; 201 SkPMColor dst4b[N];
205 filter->filterSpan(src4b, N, dst4b); 202 filter->filterSpan(src4b, N, dst4b);
206 SkPM4f dst4f[N]; 203 SkPM4f dst4f[N];
207 filter->filterSpan4f(src4f, N, dst4f); 204 filter->filterSpan4f(src4f, N, dst4f);
208 REPORTER_ASSERT(reporter, compare_spans(dst4f, dst4b, N)); 205 REPORTER_ASSERT(reporter, compare_spans(dst4f, dst4b, N));
209 } 206 }
210 } 207 }
211 208
212 //////////////////////////////////////////////////////////////////////////////// /////////////////// 209 //////////////////////////////////////////////////////////////////////////////// ///////////////////
213 210
(...skipping 29 matching lines...) Expand all
243 // 240 //
244 DEF_TEST(Color4f_xfermode_proc4f, reporter) { 241 DEF_TEST(Color4f_xfermode_proc4f, reporter) {
245 // TODO: extend xfermodes so that all cases can be tested. 242 // TODO: extend xfermodes so that all cases can be tested.
246 // 243 //
247 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; + +mode) { 244 for (int mode = SkXfermode::kClear_Mode; mode <= SkXfermode::kScreen_Mode; + +mode) {
248 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode); 245 SkXfermodeProc proc32 = SkXfermode::GetProc((SkXfermode::Mode)mode);
249 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode); 246 SkXfermodeProc4f proc4f = SkXfermode::GetProc4f((SkXfermode::Mode)mode);
250 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f)); 247 REPORTER_ASSERT(reporter, compare_procs(proc32, proc4f));
251 } 248 }
252 } 249 }
OLDNEW
« no previous file with comments | « tests/SerializationTest.cpp ('k') | tools/android/SkAndroidSDKCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698