Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
tests
HighContrastFilterTest.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2017 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
8
#include "
include/core/SkColor.h
"
9
#include "
include/core/SkColorFilter.h
"
10
#include "
include/core/SkPaint.h
"
11
#include "
include/core/SkRefCnt.h
"
12
#include "
include/effects/SkHighContrastFilter.h
"
13
#include "
tests/Test.h
"
14
15
#include <initializer_list>
16
17
DEF_TEST
(HighContrastFilter_SmokeTest,
reporter
) {
18
SkHighContrastConfig
config;
19
config.
fInvertStyle
= SkHighContrastConfig::InvertStyle::kInvertLightness;
20
sk_sp<SkColorFilter>
filter =
SkHighContrastFilter::Make
(config);
21
REPORTER_ASSERT
(
reporter
, filter->isAlphaUnchanged());
22
23
SkColorSpace
* cs =
nullptr
;
24
SkColor4f
white_inverted = filter->filterColor4f(
SkColors::kWhite
, cs, cs);
25
REPORTER_ASSERT
(
reporter
, white_inverted ==
SkColors::kBlack
);
26
27
SkColor4f
black_inverted = filter->filterColor4f(
SkColors::kBlack
, cs, cs);
28
REPORTER_ASSERT
(
reporter
, black_inverted ==
SkColors::kWhite
);
29
}
30
31
DEF_TEST
(HighContrastFilter_InvalidInputs,
reporter
) {
32
SkHighContrastConfig
config;
33
REPORTER_ASSERT
(
reporter
, config.
isValid
());
34
35
// Valid invert style
36
config.
fInvertStyle
= SkHighContrastConfig::InvertStyle::kInvertBrightness;
37
REPORTER_ASSERT
(
reporter
, config.
isValid
());
38
config.
fInvertStyle
= SkHighContrastConfig::InvertStyle::kInvertLightness;
39
REPORTER_ASSERT
(
reporter
, config.
isValid
());
40
sk_sp<SkColorFilter>
filter =
SkHighContrastFilter::Make
(config);
41
REPORTER_ASSERT
(
reporter
, filter);
42
43
// Invalid invert style
44
config.
fInvertStyle
=
static_cast<
SkHighContrastConfig::InvertStyle
>
(999);
45
REPORTER_ASSERT
(
reporter
, !config.
isValid
());
46
filter =
SkHighContrastFilter::Make
(config);
47
REPORTER_ASSERT
(
reporter
, !filter);
48
49
// Valid contrast
50
for
(
float
contrast : {0.5f, +1.0f, -1.0f}) {
51
config.
fInvertStyle
= SkHighContrastConfig::InvertStyle::kInvertBrightness;
52
config.
fContrast
= contrast;
53
REPORTER_ASSERT
(
reporter
, config.
isValid
());
54
filter =
SkHighContrastFilter::Make
(config);
55
REPORTER_ASSERT
(
reporter
, filter);
56
}
57
58
// Invalid contrast
59
config.
fContrast
= 1.1f;
60
REPORTER_ASSERT
(
reporter
, !config.
isValid
());
61
filter =
SkHighContrastFilter::Make
(config);
62
REPORTER_ASSERT
(
reporter
, !filter);
63
}
reporter
reporter
Definition
FontMgrTest.cpp:39
SkColorFilter.h
SkColor.h
SkHighContrastFilter.h
SkPaint.h
SkRefCnt.h
Test.h
DEF_TEST
#define DEF_TEST(name, reporter)
Definition
Test.h:312
REPORTER_ASSERT
#define REPORTER_ASSERT(r, cond,...)
Definition
Test.h:286
SkColorSpace
Definition
SkColorSpace.h:107
sk_sp
Definition
SkRefCnt.h:220
SkColors::kWhite
constexpr SkColor4f kWhite
Definition
SkColor.h:439
SkColors::kBlack
constexpr SkColor4f kBlack
Definition
SkColor.h:435
SkColor4f
SkHighContrastConfig
Definition
SkHighContrastFilter.h:22
SkHighContrastConfig::fContrast
SkScalar fContrast
Definition
SkHighContrastFilter.h:60
SkHighContrastConfig::isValid
bool isValid() const
Definition
SkHighContrastFilter.h:45
SkHighContrastConfig::fInvertStyle
InvertStyle fInvertStyle
Definition
SkHighContrastFilter.h:56
SkHighContrastConfig::InvertStyle
InvertStyle
Definition
SkHighContrastFilter.h:23
SkHighContrastFilter::Make
static sk_sp< SkColorFilter > Make(const SkHighContrastConfig &config)
Definition
SkHighContrastFilter.cpp:24
Generated on Fri Apr 26 2024 06:17:45 for Flutter Engine by
1.9.8