Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions
GradientTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/gpu/mock/GrMockTypes.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/base/SkTLazy.h"
#include "src/gpu/ganesh/GrColorInfo.h"
#include "src/gpu/ganesh/GrFPArgs.h"
#include "src/gpu/ganesh/GrFragmentProcessors.h"
#include "src/shaders/SkShaderBase.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <cstdint>
#include <cstring>
#include <string>

Go to the source code of this file.

Classes

struct  GradRec
 

Typedefs

typedef void(* GradProc) (skiatest::Reporter *reporter, const GradRec &, const GradRec &)
 

Functions

static void test_big_grad (skiatest::Reporter *reporter)
 
static void none_gradproc (skiatest::Reporter *reporter, const GradRec &, const GradRec &)
 
static void color_gradproc (skiatest::Reporter *reporter, const GradRec &rec, const GradRec &)
 
static void linear_gradproc (skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
 
static void radial_gradproc (skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
 
static void sweep_gradproc (skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
 
static void conical_gradproc (skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
 
static void linear_gradproc_matrix (skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
 
static void TestConstantGradient (skiatest::Reporter *)
 
static void TestGradientShaders (skiatest::Reporter *reporter)
 
static void test_nearly_vertical (skiatest::Reporter *reporter)
 
static void test_vertical (skiatest::Reporter *reporter)
 
static void test_linear_fuzz (skiatest::Reporter *reporter)
 
static void test_two_point_conical_zero_radius (skiatest::Reporter *reporter)
 
static void test_clamping_overflow (skiatest::Reporter *)
 
static void test_degenerate_linear (skiatest::Reporter *)
 
static void test_unsorted_degenerate (skiatest::Reporter *r)
 
static void test_linear_fuzzer (skiatest::Reporter *)
 
static void test_sweep_fuzzer (skiatest::Reporter *)
 
void test_sweep_gradient_zero_x (skiatest::Reporter *reporter, SkSurface *surface)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (TestSweepGradientZeroXGanesh, reporter, contextInfo, CtsEnforcement::kNextRelease)
 
 DEF_TEST (Gradient, reporter)
 

Typedef Documentation

◆ GradProc

typedef void(* GradProc) (skiatest::Reporter *reporter, const GradRec &, const GradRec &)

Definition at line 216 of file GradientTest.cpp.

Function Documentation

◆ color_gradproc()

static void color_gradproc ( skiatest::Reporter reporter,
const GradRec rec,
const GradRec  
)
static

Definition at line 119 of file GradientTest.cpp.

119 {
122}
reporter
Definition: FontMgrTest.cpp:39
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
struct MyStruct s
SK_API sk_sp< SkShader > Color(SkColor)
const SkColor * fColors

◆ conical_gradproc()

static void conical_gradproc ( skiatest::Reporter reporter,
const GradRec buildRec,
const GradRec checkRec 
)
static

Definition at line 157 of file GradientTest.cpp.

158 {
160 buildRec.fRadius[0],
161 buildRec.fPoint[1],
162 buildRec.fRadius[1],
163 buildRec.fColors,
164 buildRec.fPos,
165 buildRec.fColorCount,
166 buildRec.fTileMode));
167
169 checkRec.gradCheck(reporter, s, &info, SkShaderBase::GradientType::kConical);
170 REPORTER_ASSERT(reporter, !memcmp(info.fPoint, checkRec.fPoint, 2 * sizeof(SkPoint)));
171 REPORTER_ASSERT(reporter, !memcmp(info.fRadius, checkRec.fRadius, 2 * sizeof(SkScalar)));
172}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static sk_sp< SkShader > MakeTwoPointConical(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
float SkScalar
Definition: extension.cpp:12
int fColorCount
const SkPoint * fPoint
const SkScalar * fRadius
void gradCheck(skiatest::Reporter *reporter, const sk_sp< SkShader > &shader, SkShaderBase::GradientInfo *info, SkShaderBase::GradientType gt, const SkMatrix &localMatrix=SkMatrix::I()) const
const SkScalar * fPos
SkTileMode fTileMode

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( TestSweepGradientZeroXGanesh  ,
reporter  ,
contextInfo  ,
CtsEnforcement::kNextRelease   
)

Definition at line 579 of file GradientTest.cpp.

582 {
586 GrDirectContext* context = contextInfo.directContext();
589}
void test_sweep_gradient_zero_x(skiatest::Reporter *reporter, SkSurface *surface)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_TEST()

DEF_TEST ( Gradient  ,
reporter   
)

Definition at line 605 of file GradientTest.cpp.

605 {
618}
static void TestConstantGradient(skiatest::Reporter *)
static void test_nearly_vertical(skiatest::Reporter *reporter)
static void test_degenerate_linear(skiatest::Reporter *)
static void test_linear_fuzz(skiatest::Reporter *reporter)
static void test_vertical(skiatest::Reporter *reporter)
static void TestGradientShaders(skiatest::Reporter *reporter)
static void test_unsorted_degenerate(skiatest::Reporter *r)
static void test_sweep_fuzzer(skiatest::Reporter *)
static void test_two_point_conical_zero_radius(skiatest::Reporter *reporter)
static void test_clamping_overflow(skiatest::Reporter *)
static void test_big_grad(skiatest::Reporter *reporter)
static void test_linear_fuzzer(skiatest::Reporter *)

◆ linear_gradproc()

static void linear_gradproc ( skiatest::Reporter reporter,
const GradRec buildRec,
const GradRec checkRec 
)
static

Definition at line 124 of file GradientTest.cpp.

125 {
127 buildRec.fColorCount, buildRec.fTileMode));
128
131 REPORTER_ASSERT(reporter, !memcmp(info.fPoint, checkRec.fPoint, 2 * sizeof(SkPoint)));
132}
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static constexpr skcms_TransferFunction kLinear
Definition: SkColorSpace.h:51

◆ linear_gradproc_matrix()

static void linear_gradproc_matrix ( skiatest::Reporter reporter,
const GradRec buildRec,
const GradRec checkRec 
)
static

Definition at line 174 of file GradientTest.cpp.

175 {
176 SkMatrix localMatrix = SkMatrix::RotateDeg(45, {100, 100});
178 buildRec.fColorCount, buildRec.fTileMode,
179 /*flags=*/0,
180 &localMatrix));
181
184 REPORTER_ASSERT(reporter, !memcmp(info.fPoint, checkRec.fPoint, 2 * sizeof(SkPoint)));
185
186 // Same but using a local matrix wrapper.
187 s = SkGradientShader::MakeLinear(buildRec.fPoint, buildRec.fColors, buildRec.fPos,
188 buildRec.fColorCount, buildRec.fTileMode);
189 s = s->makeWithLocalMatrix(localMatrix);
191 REPORTER_ASSERT(reporter, !memcmp(info.fPoint, checkRec.fPoint, 2 * sizeof(SkPoint)));
192}
static SkMatrix RotateDeg(SkScalar deg)
Definition: SkMatrix.h:104

◆ none_gradproc()

static void none_gradproc ( skiatest::Reporter reporter,
const GradRec ,
const GradRec  
)
static

Definition at line 114 of file GradientTest.cpp.

114 {
117}
SK_API sk_sp< SkShader > Empty()

◆ radial_gradproc()

static void radial_gradproc ( skiatest::Reporter reporter,
const GradRec buildRec,
const GradRec checkRec 
)
static

Definition at line 134 of file GradientTest.cpp.

135 {
137 buildRec.fColors, buildRec.fPos,
138 buildRec.fColorCount, buildRec.fTileMode));
139
141 checkRec.gradCheck(reporter, s, &info, SkShaderBase::GradientType::kRadial);
142 REPORTER_ASSERT(reporter, info.fPoint[0] == checkRec.fPoint[0]);
143 REPORTER_ASSERT(reporter, info.fRadius[0] == checkRec.fRadius[0]);
144}
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)

◆ sweep_gradproc()

static void sweep_gradproc ( skiatest::Reporter reporter,
const GradRec buildRec,
const GradRec checkRec 
)
static

Definition at line 146 of file GradientTest.cpp.

147 {
149 buildRec.fColors, buildRec.fPos,
150 buildRec.fColorCount));
151
153 checkRec.gradCheck(reporter, s, &info, SkShaderBase::GradientType::kSweep);
154 REPORTER_ASSERT(reporter, info.fPoint[0] == checkRec.fPoint[0]);
155}
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165

◆ test_big_grad()

static void test_big_grad ( skiatest::Reporter reporter)
static

Definition at line 61 of file GradientTest.cpp.

61 {
63 const SkPoint pts[] = {{ 15, 14.7112684f }, { 0.709064007f, 12.6108112f }};
65 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
66
67 SkBitmap bm;
68 bm.allocN32Pixels(2000, 1);
69 SkCanvas c(bm);
70
71 const SkScalar affine[] = {
72 1.06608627e-06f, 4.26434525e-07f, 6.2855f, 2.6611f, 273.4393f, 244.0046f
73 };
75 matrix.setAffine(affine);
76 c.concat(matrix);
77
78 c.drawPaint(paint);
79}
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
const Paint & paint
Definition: color_source.cc:38
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
PODArray< SkColor > colors
Definition: SkRecords.h:276

◆ test_clamping_overflow()

static void test_clamping_overflow ( skiatest::Reporter )
static

Definition at line 314 of file GradientTest.cpp.

314 {
315 SkPaint p;
317 const SkPoint pts1[] = { SkPoint::Make(1001, 1000001), SkPoint::Make(1000.99f, 1000000) };
318
319 p.setShader(SkGradientShader::MakeLinear(pts1, colors, nullptr, 2, SkTileMode::kClamp));
320
322 surface->getCanvas()->scale(100, 100);
323 surface->getCanvas()->drawPaint(p);
324
325 const SkPoint pts2[] = { SkPoint::Make(10000.99f, 1000000), SkPoint::Make(10001, 1000001) };
326 p.setShader(SkGradientShader::MakeLinear(pts2, colors, nullptr, 2, SkTileMode::kClamp));
327 surface->getCanvas()->drawPaint(p);
328
329 // Passes if we don't trigger asserts.
330}
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173

◆ test_degenerate_linear()

static void test_degenerate_linear ( skiatest::Reporter )
static

Definition at line 333 of file GradientTest.cpp.

333 {
334 SkPaint p;
336 const SkPoint pts[] = {
337 SkPoint::Make(-46058024627067344430605278824628224.0f, 0),
339 };
340
341 p.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp));
343 surface->getCanvas()->drawPaint(p);
344
345 // Passes if we don't trigger asserts.
346}
#define SK_ScalarMax
Definition: SkScalar.h:24

◆ test_linear_fuzz()

static void test_linear_fuzz ( skiatest::Reporter reporter)
static

Definition at line 278 of file GradientTest.cpp.

278 {
280
281 const SkPoint pts[] = {{ 179.5f, -179.5f }, { 1074.5f, 715.5f }};
283 const SkScalar pos[] = {0, 0.200000003f, 0.800000012f, 1 };
284
287
288 SkRect r = {0, 83, 1254, 620};
289 surface->getCanvas()->drawRect(r, paint);
290}
SkPoint pos
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122

◆ test_linear_fuzzer()

static void test_linear_fuzzer ( skiatest::Reporter )
static

Definition at line 379 of file GradientTest.cpp.

379 {
380 static const SkColor gColors0[] = { 0x30303030, 0x30303030 };
381 static const SkColor gColors1[] = { 0x30303030, 0x30303030, 0x30303030 };
382
383 static const SkScalar gPos1[] = { 0, 0, 1 };
384
385 static const SkScalar gMatrix0[9] = {
386 6.40969056e-10f, 0 , 6.40969056e-10f,
387 0 , 4.42539023e-39f, 6.40969056e-10f,
388 0 , 0 , 1
389 };
390 static const SkScalar gMatrix1[9] = {
391 -2.75294113f , 6.40969056e-10f, 6.40969056e-10f,
392 6.40969056e-10f, 6.40969056e-10f, -3.32810161e+24f,
393 6.40969056e-10f, 6.40969056e-10f, 0
394 };
395 static const SkScalar gMatrix2[9] = {
396 7.93481258e+17f, 6.40969056e-10f, 6.40969056e-10f,
397 6.40969056e-10f, 6.40969056e-10f, 6.40969056e-10f,
398 6.40969056e-10f, 6.40969056e-10f, 0.688235283f
399 };
400 static const SkScalar gMatrix3[9] = {
401 1.89180674e+11f, 6.40969056e-10f, 6.40969056e-10f,
402 6.40969056e-10f, 6.40969056e-10f, 6.40969056e-10f,
403 6.40969056e-10f, 11276.0469f , 8.12524808e+20f
404 };
405
406 static const struct {
407 SkPoint fPts[2];
408 const SkColor* fColors;
409 const SkScalar* fPos;
410 int fCount;
411 SkTileMode fTileMode;
412 uint32_t fFlags;
413 const SkScalar* fLocalMatrix;
414 const SkScalar* fGlobalMatrix;
415 } gConfigs[] = {
416 {
417 {{0, -2.752941f}, {0, 0}},
418 gColors0,
419 nullptr,
422 0,
423 gMatrix0,
424 nullptr
425 },
426 {
427 {{4.42539023e-39f, -4.42539023e-39f}, {9.78041162e-15f, 4.42539023e-39f}},
428 gColors1,
429 gPos1,
432 0,
433 nullptr,
434 gMatrix1
435 },
436 {
437 {{4.42539023e-39f, 6.40969056e-10f}, {6.40969056e-10f, 1.49237238e-19f}},
438 gColors1,
439 gPos1,
442 0,
443 nullptr,
444 gMatrix2
445 },
446 {
447 {{6.40969056e-10f, 6.40969056e-10f}, {6.40969056e-10f, -0.688235283f}},
448 gColors0,
449 nullptr,
452 0,
453 gMatrix3,
454 nullptr
455 },
456 };
457
459 SkColorSpace* colorSpaces[] = {
460 nullptr, // hits the legacy gradient impl
461 srgb.get(), // triggers 4f/raster-pipeline
462 };
463
465
466 for (const SkColorSpace* colorSpace : colorSpaces) {
468 100, 100, kN32_SkColorType, kPremul_SkAlphaType, sk_ref_sp(colorSpace)));
469 SkCanvas* canvas = surface->getCanvas();
470
471 for (const auto& config : gConfigs) {
472 SkAutoCanvasRestore acr(canvas, false);
473 SkTLazy<SkMatrix> localMatrix;
474 if (config.fLocalMatrix) {
475 localMatrix.init();
476 localMatrix->set9(config.fLocalMatrix);
477 }
478
479 paint.setShader(SkGradientShader::MakeLinear(config.fPts,
480 config.fColors,
481 config.fPos,
482 config.fCount,
483 config.fTileMode,
484 config.fFlags,
485 localMatrix.getMaybeNull()));
486 if (config.fGlobalMatrix) {
487 SkMatrix m;
488 m.set9(config.fGlobalMatrix);
489 canvas->save();
490 canvas->concat(m);
491 }
492
493 canvas->drawPaint(paint);
494 }
495 }
496}
SkPoint fPts[2]
uint16_t fFlags
Definition: ShapeLayer.cpp:106
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
SkTileMode
Definition: SkTileMode.h:13
static const SkScalar gPos1[]
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
static sk_sp< SkColorSpace > MakeSRGB()
SkMatrix & set9(const SkScalar buffer[9])
Definition: SkMatrix.cpp:51
T * init(Args &&... args)
Definition: SkTLazy.h:45
const T * getMaybeNull() const
Definition: SkTLazy.h:108
T * get() const
Definition: SkRefCnt.h:303
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
const SkColor gColors1[]
const SkColor gColors0[]

◆ test_nearly_vertical()

static void test_nearly_vertical ( skiatest::Reporter reporter)
static

Definition at line 250 of file GradientTest.cpp.

250 {
252
253 const SkPoint pts[] = {{ 100, 50 }, { 100.0001f, 50000 }};
255 const SkScalar pos[] = { 0, 1 };
258
259 surface->getCanvas()->drawPaint(paint);
260}

◆ test_sweep_fuzzer()

static void test_sweep_fuzzer ( skiatest::Reporter )
static

Definition at line 498 of file GradientTest.cpp.

498 {
499 static const SkColor gColors0[] = { 0x30303030, 0x30303030, 0x30303030 };
500 static const SkScalar gPos0[] = { -47919293023455565225163489280.0f, 0, 1 };
501 static const SkScalar gMatrix0[9] = {
502 1.12116716e-13f, 0 , 8.50489682e+16f,
503 4.1917041e-41f , 3.51369881e-23f, -2.54344271e-26f,
504 9.61111907e+17f, -3.35263808e-29f, -1.35659403e+14f
505 };
506 static const struct {
507 SkPoint fCenter;
508 const SkColor* fColors;
509 const SkScalar* fPos;
510 int fCount;
511 const SkScalar* fGlobalMatrix;
512 } gConfigs[] = {
513 {
514 { 0, 0 },
515 gColors0,
516 gPos0,
518 gMatrix0
519 },
520 };
521
523 SkCanvas* canvas = surface->getCanvas();
525
526 for (const auto& config : gConfigs) {
527 paint.setShader(SkGradientShader::MakeSweep(config.fCenter.x(),
528 config.fCenter.y(),
529 config.fColors,
530 config.fPos,
531 config.fCount));
532
533 SkAutoCanvasRestore acr(canvas, false);
534 if (config.fGlobalMatrix) {
535 SkMatrix m;
536 m.set9(config.fGlobalMatrix);
537 canvas->save();
538 canvas->concat(m);
539 }
540 canvas->drawPaint(paint);
541 }
542}
static const SkScalar gPos0[]

◆ test_sweep_gradient_zero_x()

void test_sweep_gradient_zero_x ( skiatest::Reporter reporter,
SkSurface surface 
)

Definition at line 548 of file GradientTest.cpp.

548 {
549 // The gradient drawn has yellow for the first half and blue for the second half, using hard
550 // stops and running clockwise from (1, 0), so we should draw a rectangle with a blue top-half
551 // and yellow bottom-half.
552 constexpr float pts[4] = {0.0f, 0.5f, 0.5f, 1.0f};
554 SkCanvas* canvas = surface->getCanvas();
555 canvas->save();
556 canvas->translate(2.5f, 2.5f);
558 paint.setShader(SkGradientShader::MakeSweep(0.0f, 0.0f, colors, pts, 4));
559 canvas->drawRect(SkRect::MakeXYWH(-2.5f, -2.5f, 5.0f, 5.0f), paint);
560 canvas->restore();
561
562 // Read pixels.
564 SkPixmap pixmap;
565 bitmap.allocPixels(surface->imageInfo());
566 SkAssertResult(bitmap.peekPixels(&pixmap));
567 if (!surface->readPixels(pixmap, 0, 0)) {
568 ERRORF(reporter, "readPixels failed");
569 return;
570 }
571
572 // Check the results.
573 SkColor4f topColor = pixmap.getColor4f(2, 0);
574 SkColor4f bottomColor = pixmap.getColor4f(2, 4);
577}
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
#define ERRORF(r,...)
Definition: Test.h:293
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
SkColor4f getColor4f(int x, int y) const
Definition: SkPixmap.cpp:388
constexpr SkColor4f kBlue
Definition: SkColor.h:442
constexpr SkColor4f kYellow
Definition: SkColor.h:443
Definition: bitmap.py:1
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ test_two_point_conical_zero_radius()

static void test_two_point_conical_zero_radius ( skiatest::Reporter reporter)
static

Definition at line 294 of file GradientTest.cpp.

294 {
296 surface->getCanvas()->clear(SK_ColorRED);
297
299 SkPaint p;
301 SkPoint::Make(2.5f, 2.5f), 0,
302 SkPoint::Make(3.0f, 3.0f), 10,
304 surface->getCanvas()->drawPaint(p);
305
306 // r == 0 for the center pixel.
307 // verify that we draw it (no red bleed)
308 SkPMColor centerPMColor;
309 surface->readPixels(SkImageInfo::MakeN32Premul(1, 1), &centerPMColor, sizeof(SkPMColor), 2, 2);
310 REPORTER_ASSERT(reporter, SkGetPackedR32(centerPMColor) == 0);
311}
#define SkGetPackedR32(packed)
Definition: SkColorPriv.h:93
uint32_t SkPMColor
Definition: SkColor.h:205

◆ test_unsorted_degenerate()

static void test_unsorted_degenerate ( skiatest::Reporter r)
static

Definition at line 349 of file GradientTest.cpp.

349 {
350 // Passes if a valid solid color is computed for the degenerate gradient
351 // (unsorted positions are fixed during regular gradient construction, so this ensures the
352 // same fixing happens for degenerate gradients as well). If they aren't fixed, this test
353 // case produces a negative alpha, which asserts during SkPMColor4f::isOpaque().
354 const SkColor4f colors[] = { {0.f, 0.f, 0.f, 0.f},
355 {0.00784314f, 0.f, 0.f, 0.0627451f},
356 {0.f, 0.00392157f, 0.f, 0.f} };
357 const SkScalar positions[] = {0.00753367f, 8.54792e-44f, 1.46955e-39f};
358
359 const SkPoint points[] { { 0.f, 0.f }, { 1e-20f, -1e-8f }}; // must be degenerate
360 // Use kMirror to go through average color stop calculation, vs. kClamp which would pick a color
361 sk_sp<SkShader> gradient = SkGradientShader::MakeLinear(points, colors, nullptr, positions, 3,
363
364 // The degenerate gradient shouldn't be null
365 REPORTER_ASSERT(r, SkToBool(gradient));
366 // And it shouldn't crash when creating a fragment processor
367
370 SkSurfaceProps props;
372 auto context = GrDirectContext::MakeMock(&options);
373
374 GrFPArgs args(context.get(), &dstColorInfo, props, GrFPArgs::Scope::kDefault);
376}
const char * options
static const int points[]
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
static sk_sp< GrDirectContext > MakeMock(const GrMockOptions *, const GrContextOptions &)
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
std::unique_ptr< GrFragmentProcessor > Make(const SkMaskFilter *maskfilter, const GrFPArgs &args, const SkMatrix &ctm)

◆ test_vertical()

static void test_vertical ( skiatest::Reporter reporter)
static

Definition at line 262 of file GradientTest.cpp.

262 {
264
265 const SkPoint pts[] = {{ 100, 50 }, { 100, 50 }};
267 const SkScalar pos[] = { 0, 1 };
270
271 surface->getCanvas()->drawPaint(paint);
272}

◆ TestConstantGradient()

static void TestConstantGradient ( skiatest::Reporter )
static

Definition at line 195 of file GradientTest.cpp.

195 {
196 const SkPoint pts[] = {
197 { 0, 0 },
198 { SkIntToScalar(10), 0 }
199 };
201 const SkScalar pos[] = { 0, SK_Scalar1 };
204 SkBitmap outBitmap;
205 outBitmap.allocN32Pixels(10, 1);
206 SkCanvas canvas(outBitmap);
207 canvas.drawPaint(paint);
208 for (int i = 0; i < 10; i++) {
209 // The following is commented out because it currently fails
210 // Related bug: https://code.google.com/p/skia/issues/detail?id=1098
211
212 // REPORTER_ASSERT(reporter, SK_ColorBLUE == outBitmap.getColor(i, 0));
213 }
214}
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57

◆ TestGradientShaders()

static void TestGradientShaders ( skiatest::Reporter reporter)
static

Definition at line 218 of file GradientTest.cpp.

218 {
220 static const SkScalar gPos[] = { 0, SK_ScalarHalf, SK_Scalar1 };
221 static const SkPoint gPts[] = {
222 { 0, 0 },
223 { SkIntToScalar(10), SkIntToScalar(20) }
224 };
225 static const SkScalar gRad[] = { SkIntToScalar(1), SkIntToScalar(2) };
226
227 GradRec rec;
229 rec.fColors = gColors;
230 rec.fPos = gPos;
231 rec.fPoint = gPts;
232 rec.fRadius = gRad;
234
235 static const GradProc gProcs[] = {
243 };
244
245 for (size_t i = 0; i < std::size(gProcs); ++i) {
246 gProcs[i](reporter, rec, rec);
247 }
248}
static const SkScalar gPos[]
static const SkColor gColors[]
static void linear_gradproc(skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
void(* GradProc)(skiatest::Reporter *reporter, const GradRec &, const GradRec &)
static void radial_gradproc(skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
static void conical_gradproc(skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
static void color_gradproc(skiatest::Reporter *reporter, const GradRec &rec, const GradRec &)
static void none_gradproc(skiatest::Reporter *reporter, const GradRec &, const GradRec &)
static void sweep_gradproc(skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
static void linear_gradproc_matrix(skiatest::Reporter *reporter, const GradRec &buildRec, const GradRec &checkRec)
#define SK_ScalarHalf
Definition: SkScalar.h:19
const ImageMakerProc gProcs[]