Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
third_party
skia
gm
xfermodes2.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2013 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 "
gm/gm.h
"
9
#include "
include/core/SkBitmap.h
"
10
#include "
include/core/SkBlendMode.h
"
11
#include "
include/core/SkCanvas.h
"
12
#include "
include/core/SkColor.h
"
13
#include "
include/core/SkColorPriv.h
"
14
#include "
include/core/SkFont.h
"
15
#include "
include/core/SkMatrix.h
"
16
#include "
include/core/SkPaint.h
"
17
#include "
include/core/SkRect.h
"
18
#include "
include/core/SkRefCnt.h
"
19
#include "
include/core/SkScalar.h
"
20
#include "
include/core/SkShader.h
"
21
#include "
include/core/SkSize.h
"
22
#include "
include/core/SkString.h
"
23
#include "
include/core/SkTileMode.h
"
24
#include "
include/core/SkTypeface.h
"
25
#include "
include/utils/SkTextUtils.h
"
26
#include "
tools/ToolUtils.h
"
27
#include "
tools/fonts/FontToolUtils.h
"
28
29
#include <stdint.h>
30
#include <string.h>
31
32
namespace
skiagm
{
33
34
class
Xfermodes2GM
:
public
GM
{
35
public
:
36
Xfermodes2GM
(
bool
grayscale) : fGrayscale(grayscale) {}
37
38
protected
:
39
SkString
getName
()
const override
{
40
return
fGrayscale ?
SkString
(
"xfermodes2_gray"
) :
SkString
(
"xfermodes2"
);
41
}
42
43
SkISize
getISize
()
override
{
return
SkISize::Make
(455, 475); }
44
45
void
onDraw
(
SkCanvas
* canvas)
override
{
46
canvas->
translate
(
SkIntToScalar
(10),
SkIntToScalar
(20));
47
48
const
SkScalar
w
=
SkIntToScalar
(kSize);
49
const
SkScalar
h
=
SkIntToScalar
(kSize);
50
51
SkFont
font =
ToolUtils::DefaultPortableFont
();
52
53
const
int
W
= 6;
54
55
SkScalar
x
= 0,
y
= 0;
56
for
(
size_t
m = 0; m <
kSkBlendModeCount
; m++) {
57
SkBlendMode
mode =
static_cast<
SkBlendMode
>
(m);
58
59
canvas->
save
();
60
61
canvas->
translate
(
x
,
y
);
62
SkPaint
p;
63
p.setAntiAlias(
false
);
64
p.setStyle(
SkPaint::kFill_Style
);
65
p.setShader(fBG);
66
SkRect
r =
SkRect::MakeWH
(
w
,
h
);
67
canvas->
drawRect
(r, p);
68
69
canvas->
saveLayer
(&r,
nullptr
);
70
71
p.setShader(fDst);
72
canvas->
drawRect
(r, p);
73
p.setShader(fSrc);
74
p.setBlendMode(mode);
75
canvas->
drawRect
(r, p);
76
77
canvas->
restore
();
78
79
r.
inset
(-
SK_ScalarHalf
, -
SK_ScalarHalf
);
80
p.setStyle(
SkPaint::kStroke_Style
);
81
p.setShader(
nullptr
);
82
p.setBlendMode(
SkBlendMode::kSrcOver
);
83
canvas->
drawRect
(r, p);
84
85
canvas->
restore
();
86
87
#if 1
88
SkTextUtils::DrawString
(canvas,
SkBlendMode_Name
(mode),
x
+
w
/2,
y
- font.getSize()/2, font,
SkPaint
(),
89
SkTextUtils::kCenter_Align
);
90
#endif
91
x
+=
w
+
SkIntToScalar
(10);
92
if
((m %
W
) ==
W
- 1) {
93
x
= 0;
94
y
+=
h
+
SkIntToScalar
(30);
95
}
96
}
97
}
98
99
private
:
100
void
onOnceBeforeDraw
()
override
{
101
const
uint32_t kCheckData[] = {
102
SkPackARGB32
(0xFF, 0x42, 0x41, 0x42),
103
SkPackARGB32
(0xFF, 0xD6, 0xD3, 0xD6),
104
SkPackARGB32
(0xFF, 0xD6, 0xD3, 0xD6),
105
SkPackARGB32
(0xFF, 0x42, 0x41, 0x42)
106
};
107
SkBitmap
bg;
108
bg.
allocN32Pixels
(2, 2,
true
);
109
memcpy(bg.
getPixels
(), kCheckData,
sizeof
(kCheckData));
110
111
SkMatrix
lm;
112
lm.
setScale
(
SkIntToScalar
(16),
SkIntToScalar
(16));
113
fBG = bg.
makeShader
(
SkTileMode::kRepeat
,
SkTileMode::kRepeat
,
SkSamplingOptions
(), lm);
114
115
SkBitmap
srcBmp;
116
srcBmp.
allocN32Pixels
(kSize, kSize);
117
SkPMColor
* pixels =
reinterpret_cast<
SkPMColor
*
>
(srcBmp.
getPixels
());
118
119
for
(
int
y
= 0;
y
< kSize; ++
y
) {
120
int
c =
y
* (1 << kShift);
121
SkPMColor
rowColor = fGrayscale ?
SkPackARGB32
(c, c, c, c) :
SkPackARGB32
(c, c, 0, c/2);
122
for
(
int
x
= 0;
x
< kSize; ++
x
) {
123
pixels[kSize *
y
+
x
] = rowColor;
124
}
125
}
126
fSrc = srcBmp.
makeShader
(
SkSamplingOptions
());
127
SkBitmap
dstBmp;
128
dstBmp.
allocN32Pixels
(kSize, kSize);
129
pixels =
reinterpret_cast<
SkPMColor
*
>
(dstBmp.
getPixels
());
130
131
for
(
int
x
= 0;
x
< kSize; ++
x
) {
132
int
c =
x
* (1 << kShift);
133
SkPMColor
colColor = fGrayscale ?
SkPackARGB32
(c, c, c, c) :
SkPackARGB32
(c, 0, c, c/2);
134
for
(
int
y
= 0;
y
< kSize; ++
y
) {
135
pixels[kSize *
y
+
x
] = colColor;
136
}
137
}
138
fDst = dstBmp.
makeShader
(
SkSamplingOptions
());
139
}
140
141
enum
{
142
kShift = 2,
143
kSize = 256 >> kShift,
144
};
145
146
bool
fGrayscale;
147
sk_sp<SkShader>
fBG;
148
sk_sp<SkShader>
fSrc;
149
sk_sp<SkShader>
fDst;
150
151
using
INHERITED = GM;
152
};
153
154
//////////////////////////////////////////////////////////////////////////////
155
156
DEF_GM
(
return
new
Xfermodes2GM(
false
); )
157
DEF_GM
(
return
new
Xfermodes2GM(
true
); )
158
159
}
// namespace skiagm
FontToolUtils.h
SkBitmap.h
SkBlendMode.h
SkBlendMode_Name
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
Definition
SkBlendMode.cpp:167
kSkBlendModeCount
static constexpr int kSkBlendModeCount
Definition
SkBlendMode.h:76
SkBlendMode
SkBlendMode
Definition
SkBlendMode.h:38
SkBlendMode::kSrcOver
@ kSrcOver
r = s + (1-sa)*d
SkCanvas.h
SkColorPriv.h
SkPackARGB32
static SkPMColor SkPackARGB32(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition
SkColorPriv.h:106
SkColor.h
SkPMColor
uint32_t SkPMColor
Definition
SkColor.h:205
SkFont.h
SkMatrix.h
SkPaint.h
SkRect.h
SkRefCnt.h
SkScalar.h
SK_ScalarHalf
#define SK_ScalarHalf
Definition
SkScalar.h:19
SkIntToScalar
#define SkIntToScalar(x)
Definition
SkScalar.h:57
SkShader.h
SkSize.h
SkString.h
SkTextUtils.h
SkTileMode.h
SkTileMode::kRepeat
@ kRepeat
SkTypeface.h
ToolUtils.h
W
#define W
Definition
aaa.cpp:17
SkBitmap
Definition
SkBitmap.h:59
SkBitmap::getPixels
void * getPixels() const
Definition
SkBitmap.h:283
SkBitmap::makeShader
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition
SkBitmap.cpp:669
SkBitmap::allocN32Pixels
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition
SkBitmap.cpp:232
SkCanvas
Definition
SkCanvas.h:106
SkCanvas::saveLayer
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition
SkCanvas.cpp:500
SkCanvas::drawRect
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition
SkCanvas.cpp:1997
SkCanvas::restore
void restore()
Definition
SkCanvas.cpp:465
SkCanvas::translate
void translate(SkScalar dx, SkScalar dy)
Definition
SkCanvas.cpp:1602
SkCanvas::save
int save()
Definition
SkCanvas.cpp:451
SkFont
Definition
SkFont.h:35
SkMatrix
Definition
SkMatrix.h:54
SkMatrix::setScale
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition
SkMatrix.cpp:296
SkPaint
Definition
SkPaint.h:44
SkPaint::kStroke_Style
@ kStroke_Style
set to stroke geometry
Definition
SkPaint.h:194
SkPaint::kFill_Style
@ kFill_Style
set to fill geometry
Definition
SkPaint.h:193
SkString
Definition
SkString.h:118
SkTextUtils::kCenter_Align
@ kCenter_Align
Definition
SkTextUtils.h:27
SkTextUtils::DrawString
static void DrawString(SkCanvas *canvas, const char text[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint, Align align=kLeft_Align)
Definition
SkTextUtils.h:34
sk_sp
Definition
SkRefCnt.h:220
skiagm::GM
Definition
gm.h:110
skiagm::Xfermodes2GM
Definition
xfermodes2.cpp:34
skiagm::Xfermodes2GM::getISize
SkISize getISize() override
Definition
xfermodes2.cpp:43
skiagm::Xfermodes2GM::Xfermodes2GM
Xfermodes2GM(bool grayscale)
Definition
xfermodes2.cpp:36
skiagm::Xfermodes2GM::onDraw
void onDraw(SkCanvas *canvas) override
Definition
xfermodes2.cpp:45
skiagm::Xfermodes2GM::onOnceBeforeDraw
void onOnceBeforeDraw() override
Definition
xfermodes2.cpp:100
skiagm::Xfermodes2GM::getName
SkString getName() const override
Definition
xfermodes2.cpp:39
SkScalar
float SkScalar
Definition
extension.cpp:12
gm.h
DEF_GM
#define DEF_GM(CODE)
Definition
gm.h:40
y
double y
Definition
mouse-input-test.cc:83
x
double x
Definition
mouse-input-test.cc:82
ToolUtils::DefaultPortableFont
SkFont DefaultPortableFont()
Definition
FontToolUtils.cpp:202
skiagm
Definition
DMSrcSink.h:27
w
SkScalar w
Definition
pictureshadertile.cpp:30
h
SkScalar h
Definition
pictureshadertile.cpp:30
SkISize
Definition
SkSize.h:16
SkISize::Make
static constexpr SkISize Make(int32_t w, int32_t h)
Definition
SkSize.h:20
SkRect
Definition
extension.cpp:13
SkRect::inset
void inset(float dx, float dy)
Definition
SkRect.h:1060
SkRect::MakeWH
static constexpr SkRect MakeWH(float w, float h)
Definition
SkRect.h:609
SkSamplingOptions
Definition
SkSamplingOptions.h:58
Generated on Fri Apr 26 2024 06:16:10 for Flutter Engine by
1.9.8