Flutter Engine
The Flutter Engine
ShaderOpacityTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
20#include "tests/Test.h"
21
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}
53
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);
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);
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);
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);
89 REPORTER_ASSERT(reporter, !grad->isOpaque());
90}
91
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}
100
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);
111 sk_sp<SkShader> lm2 = colorShader2->makeWithLocalMatrix(kMatrix);
113
114 sk_sp<SkShader> ctm1 = as_SB(colorShader1)->makeWithCTM(kMatrix);
116 sk_sp<SkShader> ctm2 = as_SB(colorShader2)->makeWithCTM(kMatrix);
118}
119
120DEF_TEST(ShaderOpacity, reporter) {
125}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
int count
Definition: FontMgrTest.cpp:50
SkPoint pos
static void test_gradient(skiatest::Reporter *reporter)
static void test_matrix(skiatest::Reporter *reporter)
DEF_TEST(ShaderOpacity, reporter)
static void test_color(skiatest::Reporter *reporter)
static void test_bitmap(skiatest::Reporter *reporter)
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
uint32_t SkColor
Definition: SkColor.h:37
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
SkTileMode
Definition: SkTileMode.h:13
#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 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 SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
sk_sp< SkShader > makeWithCTM(const SkMatrix &) const
sk_sp< SkShader > makeWithLocalMatrix(const SkMatrix &) const
Definition: SkShader.cpp:26
virtual bool isOpaque() const
Definition: SkShader.h:44
float SkScalar
Definition: extension.cpp:12
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkShader > Color(SkColor)
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
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo MakeN32Premul(int width, int height)
void iset(int32_t x, int32_t y)
Definition: SkPoint_impl.h:214