Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
ShaderOpacityTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkTileMode.h"
#include "include/effects/SkGradientShader.h"
#include "src/shaders/SkShaderBase.h"
#include "tests/Test.h"

Go to the source code of this file.

Functions

static void test_bitmap (skiatest::Reporter *reporter)
 
static void test_gradient (skiatest::Reporter *reporter)
 
static void test_color (skiatest::Reporter *reporter)
 
static void test_matrix (skiatest::Reporter *reporter)
 
 DEF_TEST (ShaderOpacity, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( ShaderOpacity  ,
reporter   
)

Definition at line 120 of file ShaderOpacityTest.cpp.

120 {
125}
reporter
static void test_gradient(skiatest::Reporter *reporter)
static void test_matrix(skiatest::Reporter *reporter)
static void test_color(skiatest::Reporter *reporter)
static void test_bitmap(skiatest::Reporter *reporter)

◆ test_bitmap()

static void test_bitmap ( skiatest::Reporter reporter)
static

Definition at line 22 of file ShaderOpacityTest.cpp.

22 {
24
25 SkBitmap bmp;
26 bmp.setInfo(info);
27
28 // test 1: bitmap without pixel data
29 auto shader = bmp.makeShader(SkSamplingOptions());
31 REPORTER_ASSERT(reporter, !shader->isOpaque());
32
33 // From this point on, we have pixels
34 bmp.allocPixels(info);
35
36 // test 2: not opaque by default
37 shader = bmp.makeShader(SkSamplingOptions());
39 REPORTER_ASSERT(reporter, !shader->isOpaque());
40
41 // test 3: explicitly opaque
43 shader = bmp.makeShader(SkSamplingOptions());
45 REPORTER_ASSERT(reporter, shader->isOpaque());
46
47 // test 4: explicitly not opaque
49 shader = bmp.makeShader(SkSamplingOptions());
51 REPORTER_ASSERT(reporter, !shader->isOpaque());
52}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition SkBitmap.cpp:258
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkBitmap.cpp:669
bool setInfo(const SkImageInfo &imageInfo, size_t rowBytes=0)
Definition SkBitmap.cpp:114
bool setAlphaType(SkAlphaType alphaType)
Definition SkBitmap.cpp:148
static SkImageInfo MakeN32Premul(int width, int height)

◆ test_color()

static void test_color ( skiatest::Reporter reporter)
static

Definition at line 92 of file ShaderOpacityTest.cpp.

92 {
93 sk_sp<SkShader> colorShader1 = SkShaders::Color(SkColorSetARGB(0,0,0,0));
94 REPORTER_ASSERT(reporter, !colorShader1->isOpaque());
95 sk_sp<SkShader> colorShader2 = SkShaders::Color(SkColorSetARGB(0xFF,0,0,0));
96 REPORTER_ASSERT(reporter, colorShader2->isOpaque());
97 sk_sp<SkShader> colorShader3 = SkShaders::Color(SkColorSetARGB(0x7F,0,0,0));
98 REPORTER_ASSERT(reporter, !colorShader3->isOpaque());
99}
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49

◆ test_gradient()

static void test_gradient ( skiatest::Reporter reporter)
static

Definition at line 54 of file ShaderOpacityTest.cpp.

54 {
55 SkPoint pts[2];
56 pts[0].iset(0, 0);
57 pts[1].iset(1, 0);
58 SkColor colors[2];
60 int count = 2;
62
63 // test 1: all opaque
64 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
65 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
66 auto grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
68 REPORTER_ASSERT(reporter, grad->isOpaque());
69
70 // test 2: all 0 alpha
71 colors[0] = SkColorSetARGB(0, 0, 0, 0);
72 colors[1] = SkColorSetARGB(0, 0, 0, 0);
73 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
75 REPORTER_ASSERT(reporter, !grad->isOpaque());
76
77 // test 3: one opaque, one transparent
78 colors[0] = SkColorSetARGB(0xFF, 0, 0, 0);
79 colors[1] = SkColorSetARGB(0x40, 0, 0, 0);
80 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
82 REPORTER_ASSERT(reporter, !grad->isOpaque());
83
84 // test 4: test 3, swapped
85 colors[0] = SkColorSetARGB(0x40, 0, 0, 0);
86 colors[1] = SkColorSetARGB(0xFF, 0, 0, 0);
87 grad = SkGradientShader::MakeLinear(pts, colors, pos, count, mode);
89 REPORTER_ASSERT(reporter, !grad->isOpaque());
90}
int count
SkPoint pos
uint32_t SkColor
Definition SkColor.h:37
#define SkIntToScalar(x)
Definition SkScalar.h:57
SkTileMode
Definition SkTileMode.h:13
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)
float SkScalar
Definition extension.cpp:12
PODArray< SkColor > colors
Definition SkRecords.h:276
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 mode
Definition switches.h:228
void iset(int32_t x, int32_t y)

◆ test_matrix()

static void test_matrix ( skiatest::Reporter reporter)
static

Definition at line 101 of file ShaderOpacityTest.cpp.

101 {
102 sk_sp<SkShader> colorShader1 = SkShaders::Color(SkColorSetARGB(0,0,0,0));
103 REPORTER_ASSERT(reporter, !colorShader1->isOpaque());
104 sk_sp<SkShader> colorShader2 = SkShaders::Color(SkColorSetARGB(0xFF,0,0,0));
105 REPORTER_ASSERT(reporter, colorShader2->isOpaque());
106
107 static const SkMatrix kMatrix = SkMatrix::Scale(1, 1);
108
109 sk_sp<SkShader> lm1 = colorShader1->makeWithLocalMatrix(kMatrix);
110 REPORTER_ASSERT(reporter, !lm1->isOpaque());
111 sk_sp<SkShader> lm2 = colorShader2->makeWithLocalMatrix(kMatrix);
112 REPORTER_ASSERT(reporter, lm2->isOpaque());
113
114 sk_sp<SkShader> ctm1 = as_SB(colorShader1)->makeWithCTM(kMatrix);
115 REPORTER_ASSERT(reporter, !ctm1->isOpaque());
116 sk_sp<SkShader> ctm2 = as_SB(colorShader2)->makeWithCTM(kMatrix);
117 REPORTER_ASSERT(reporter, ctm2->isOpaque());
118}
SkShaderBase * as_SB(SkShader *shader)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
sk_sp< SkShader > makeWithCTM(const SkMatrix &) const