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

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