Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
bench
Sk4fBench.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2015 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 "
bench/Benchmark.h
"
9
#include "
include/core/SkColor.h
"
10
#include "
src/base/SkVx.h
"
11
12
// Writing into this array prevents the loops from being compiled away.
13
static
volatile
float
blackhole
[4];
14
15
template
<
typename
T>
16
struct
Sk4fRoundtripBench
:
public
Benchmark
{
17
Sk4fRoundtripBench
() {}
18
19
const
char
*
onGetName
()
override
{
20
switch
(
sizeof
(
T
)) {
21
case
1:
return
"Sk4f_roundtrip_u8"
;
22
case
2:
return
"Sk4f_roundtrip_u16"
;
23
case
4:
return
"Sk4f_roundtrip_int"
;
24
}
25
SkASSERT
(
false
);
26
return
""
;
27
}
28
29
bool
isSuitableFor
(
Backend
backend)
override
{
return
backend
==
Backend::kNonRendering
; }
30
31
void
onDraw
(
int
loops,
SkCanvas
* canvas)
override
{
32
skvx::float4
fs(1,2,3,4);
33
while
(loops --> 0) {
34
fs = skvx::cast<float>(skvx::cast<T>(fs));
35
}
36
fs.
store
(
const_cast<
float
*
>
(
blackhole
));
37
}
38
};
39
DEF_BENCH
(
return
new
Sk4fRoundtripBench<uint8_t>
;)
40
DEF_BENCH
(
return
new
Sk4fRoundtripBench<uint16_t>
;)
41
DEF_BENCH
(
return
new
Sk4fRoundtripBench<int>
;)
42
43
struct
Sk4fFloorBench
: public
Benchmark
{
44
Sk4fFloorBench
() {}
45
46
const
char
*
onGetName
()
override
{
return
"Sk4f_floor"
; }
47
bool
isSuitableFor
(
Backend
backend)
override
{
return
backend
== Backend::kNonRendering; }
48
49
void
onDraw
(
int
loops,
SkCanvas
* canvas)
override
{
50
skvx::float4
fs(1,2,3,4);
51
while
(loops --> 0) {
52
fs = floor(fs);
53
}
54
fs.
store
(
const_cast<
float
*
>
(
blackhole
));
55
}
56
};
57
DEF_BENCH
(
return
new
Sk4fFloorBench
;)
58
59
struct
Sk4fGradientBench
: public
Benchmark
{
60
const char* onGetName() override { return
"Sk4f_gradient"
; }
61
bool
isSuitableFor
(
Backend
backend)
override
{
return
backend
== Backend::kNonRendering; }
62
63
SkPMColor
fDevice[100];
64
void
onDraw
(
int
loops,
SkCanvas
*)
override
{
65
skvx::float4
c0(0,0,255,255),
66
c1(255,0,0,255),
67
dc = c1 - c0,
68
fx(0.1f),
69
dx(0.002f),
70
dcdx(dc*dx),
71
dcdx4(dcdx+dcdx+dcdx+dcdx);
72
73
for
(
int
n = 0; n < loops; n++) {
74
auto
a
= c0 + dc*fx + 0.5f,
// add an extra 0.5f to get rounding for free.
75
b
=
a
+ dcdx,
76
c =
b
+ dcdx,
77
d
= c + dcdx;
78
for
(
size_t
i = 0; i < std::size(fDevice); i += 4) {
79
skvx::cast<uint8_t>(
a
).store(fDevice + i + 0);
80
skvx::cast<uint8_t>(
b
).store(fDevice + i + 1);
81
skvx::cast<uint8_t>(c).store(fDevice + i + 2);
82
skvx::cast<uint8_t>(
d
).store(fDevice + i + 3);
83
a
=
a
+ dcdx4;
84
b
=
b
+ dcdx4;
85
c = c + dcdx4;
86
d
=
d
+ dcdx4;
87
}
88
}
89
}
90
};
91
DEF_BENCH
(
return
new
Sk4fGradientBench
;)
Benchmark.h
DEF_BENCH
#define DEF_BENCH(code)
Definition
Benchmark.h:20
backend
const char * backend
Definition
CommonFlagsConfig.cpp:42
blackhole
static volatile float blackhole[4]
Definition
Sk4fBench.cpp:13
SkASSERT
#define SkASSERT(cond)
Definition
SkAssert.h:116
SkColor.h
SkPMColor
uint32_t SkPMColor
Definition
SkColor.h:205
SkVx.h
Benchmark
Definition
Benchmark.h:36
Benchmark::Backend
Backend
Definition
Benchmark.h:44
Benchmark::Backend::kNonRendering
@ kNonRendering
SkCanvas
Definition
SkCanvas.h:106
d
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition
main.cc:19
b
static bool b
Definition
ffi_native_test_module.c:74
a
struct MyStruct a[10]
T
#define T
Definition
precompiler.cc:65
Sk4fFloorBench
Definition
Sk4fBench.cpp:43
Sk4fFloorBench::onGetName
const char * onGetName() override
Definition
Sk4fBench.cpp:46
Sk4fFloorBench::onDraw
void onDraw(int loops, SkCanvas *canvas) override
Definition
Sk4fBench.cpp:49
Sk4fFloorBench::isSuitableFor
bool isSuitableFor(Backend backend) override
Definition
Sk4fBench.cpp:47
Sk4fGradientBench
Definition
Sk4fBench.cpp:59
Sk4fGradientBench::onDraw
void onDraw(int loops, SkCanvas *) override
Definition
Sk4fBench.cpp:64
Sk4fGradientBench::isSuitableFor
bool isSuitableFor(Backend backend) override
Definition
Sk4fBench.cpp:61
Sk4fRoundtripBench
Definition
Sk4fBench.cpp:16
Sk4fRoundtripBench::Sk4fRoundtripBench
Sk4fRoundtripBench()
Definition
Sk4fBench.cpp:17
Sk4fRoundtripBench::onGetName
const char * onGetName() override
Definition
Sk4fBench.cpp:19
Sk4fRoundtripBench::onDraw
void onDraw(int loops, SkCanvas *canvas) override
Definition
Sk4fBench.cpp:31
Sk4fRoundtripBench::isSuitableFor
bool isSuitableFor(Backend backend) override
Definition
Sk4fBench.cpp:29
skvx::Vec
Definition
SkVx.h:83
skvx::Vec::store
SKVX_ALWAYS_INLINE void store(void *ptr) const
Definition
SkVx.h:112
Generated on Fri Apr 26 2024 06:15:27 for Flutter Engine by
1.9.8