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

Side by Side Diff: tests/GradientTest.cpp

Issue 1817383002: switch surface 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/GrTextureMipMapInvalidationTest.cpp ('k') | tests/ImageFilterTest.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 2011 Google Inc. 2 * Copyright 2011 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkColorShader.h" 10 #include "SkColorShader.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 sweep_gradproc, 177 sweep_gradproc,
178 conical_gradproc, 178 conical_gradproc,
179 }; 179 };
180 180
181 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) { 181 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) {
182 gProcs[i](reporter, rec); 182 gProcs[i](reporter, rec);
183 } 183 }
184 } 184 }
185 185
186 static void test_nearly_vertical(skiatest::Reporter* reporter) { 186 static void test_nearly_vertical(skiatest::Reporter* reporter) {
187 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(200, 200)); 187 auto surface(SkSurface::MakeRasterN32Premul(200, 200));
188 188
189 const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }}; 189 const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }};
190 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; 190 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE };
191 const SkScalar pos[] = { 0, 1 }; 191 const SkScalar pos[] = { 0, 1 };
192 SkPaint paint; 192 SkPaint paint;
193 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkShader:: kClamp_TileMode)); 193 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 2, SkShader:: kClamp_TileMode));
194 194
195 surface->getCanvas()->drawPaint(paint); 195 surface->getCanvas()->drawPaint(paint);
196 } 196 }
197 197
198 // A linear gradient interval can, due to numerical imprecision (likely in the d ivide) 198 // A linear gradient interval can, due to numerical imprecision (likely in the d ivide)
199 // finish an interval with the final fx not landing outside of [p0...p1]. 199 // finish an interval with the final fx not landing outside of [p0...p1].
200 // The old code had an assert which this test triggered. 200 // The old code had an assert which this test triggered.
201 // We now explicitly clamp the resulting fx value. 201 // We now explicitly clamp the resulting fx value.
202 static void test_linear_fuzz(skiatest::Reporter* reporter) { 202 static void test_linear_fuzz(skiatest::Reporter* reporter) {
203 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1300, 630)); 203 auto surface(SkSurface::MakeRasterN32Premul(1300, 630));
204 204
205 const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }}; 205 const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }};
206 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_C olorWHITE }; 206 const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_C olorWHITE };
207 const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 }; 207 const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 };
208 208
209 SkPaint paint; 209 SkPaint paint;
210 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 4, SkShader:: kClamp_TileMode)); 210 paint.setShader(SkGradientShader::MakeLinear(pts, colors, pos, 4, SkShader:: kClamp_TileMode));
211 211
212 SkRect r = {0, 83, 1254, 620}; 212 SkRect r = {0, 83, 1254, 620};
213 surface->getCanvas()->drawRect(r, paint); 213 surface->getCanvas()->drawRect(r, paint);
214 } 214 }
215 215
216 // https://bugs.chromium.org/p/skia/issues/detail?id=5023 216 // https://bugs.chromium.org/p/skia/issues/detail?id=5023
217 // We should still shade pixels for which the radius is exactly 0. 217 // We should still shade pixels for which the radius is exactly 0.
218 static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) { 218 static void test_two_point_conical_zero_radius(skiatest::Reporter* reporter) {
219 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(5, 5)); 219 auto surface(SkSurface::MakeRasterN32Premul(5, 5));
220 surface->getCanvas()->clear(SK_ColorRED); 220 surface->getCanvas()->clear(SK_ColorRED);
221 221
222 const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE }; 222 const SkColor colors[] = { SK_ColorGREEN, SK_ColorBLUE };
223 SkPaint p; 223 SkPaint p;
224 p.setShader(SkGradientShader::MakeTwoPointConical( 224 p.setShader(SkGradientShader::MakeTwoPointConical(
225 SkPoint::Make(2.5f, 2.5f), 0, 225 SkPoint::Make(2.5f, 2.5f), 0,
226 SkPoint::Make(3.0f, 3.0f), 10, 226 SkPoint::Make(3.0f, 3.0f), 10,
227 colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); 227 colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode));
228 surface->getCanvas()->drawPaint(p); 228 surface->getCanvas()->drawPaint(p);
229 229
230 // r == 0 for the center pixel. 230 // r == 0 for the center pixel.
231 // verify that we draw it (no red bleed) 231 // verify that we draw it (no red bleed)
232 SkPMColor centerPMColor; 232 SkPMColor centerPMColor;
233 surface->readPixels(SkImageInfo::MakeN32Premul(1, 1), &centerPMColor, sizeof (SkPMColor), 2, 2); 233 surface->readPixels(SkImageInfo::MakeN32Premul(1, 1), &centerPMColor, sizeof (SkPMColor), 2, 2);
234 REPORTER_ASSERT(reporter, SkGetPackedR32(centerPMColor) == 0); 234 REPORTER_ASSERT(reporter, SkGetPackedR32(centerPMColor) == 0);
235 } 235 }
236 236
237 DEF_TEST(Gradient, reporter) { 237 DEF_TEST(Gradient, reporter) {
238 TestGradientShaders(reporter); 238 TestGradientShaders(reporter);
239 TestConstantGradient(reporter); 239 TestConstantGradient(reporter);
240 test_big_grad(reporter); 240 test_big_grad(reporter);
241 test_nearly_vertical(reporter); 241 test_nearly_vertical(reporter);
242 test_linear_fuzz(reporter); 242 test_linear_fuzz(reporter);
243 test_two_point_conical_zero_radius(reporter); 243 test_two_point_conical_zero_radius(reporter);
244 } 244 }
OLDNEW
« no previous file with comments | « tests/GrTextureMipMapInvalidationTest.cpp ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698