1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
cc / test / fake_content_layer_client.cc [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/test/fake_content_layer_client.h"
#include <algorithm>
#include <cstddef>
#include "cc/paint/paint_op_buffer.h"
#include "skia/ext/font_utils.h"
#include "third_party/skia/include/core/SkFont.h"
#include "third_party/skia/include/core/SkTextBlob.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/skia_conversions.h"
namespace cc {
FakeContentLayerClient::ImageData::ImageData(PaintImage img,
const gfx::Point& point,
const SkSamplingOptions& sampling,
const PaintFlags& flags)
: image(std::move(img)), point(point), sampling(sampling), flags(flags) {}
FakeContentLayerClient::ImageData::ImageData(PaintImage img,
const gfx::Transform& transform,
const SkSamplingOptions& sampling,
const PaintFlags& flags)
: image(std::move(img)),
transform(transform),
sampling(sampling),
flags(flags) {}
FakeContentLayerClient::ImageData::ImageData(const ImageData& other) = default;
FakeContentLayerClient::ImageData::~ImageData() = default;
FakeContentLayerClient::SkottieData::SkottieData(
scoped_refptr<SkottieWrapper> skottie,
const gfx::Rect& dst,
float t,
SkottieFrameDataMap images,
SkottieColorMap color_map,
SkottieTextPropertyValueMap text_map)
: skottie(std::move(skottie)),
dst(dst),
t(t),
images(std::move(images)),
color_map(std::move(color_map)),
text_map(std::move(text_map)) {}
FakeContentLayerClient::SkottieData::SkottieData(const SkottieData& other) =
default;
FakeContentLayerClient::SkottieData&
FakeContentLayerClient::SkottieData::operator=(const SkottieData& other) =
default;
FakeContentLayerClient::SkottieData::~SkottieData() = default;
FakeContentLayerClient::FakeContentLayerClient() = default;
FakeContentLayerClient::~FakeContentLayerClient() = default;
scoped_refptr<DisplayItemList>
FakeContentLayerClient::PaintContentsToDisplayList() {
if (display_list_) {
return display_list_;
}
DCHECK(bounds_set_);
gfx::Rect paint_bounds(bounds_);
auto display_list = base::MakeRefCounted<DisplayItemList>();
for (RectPaintVector::const_iterator it = draw_rects_.begin();
it != draw_rects_.end(); ++it) {
const gfx::RectF& draw_rect = it->first;
const PaintFlags& flags = it->second;
display_list->StartPaint();
display_list->push<DrawRectOp>(gfx::RectFToSkRect(draw_rect), flags);
display_list->EndPaintOfUnpaired(ToEnclosingRect(draw_rect));
}
for (ImageVector::const_iterator it = draw_images_.begin();
it != draw_images_.end(); ++it) {
if (!it->transform.IsIdentity()) {
display_list->StartPaint();
display_list->push<SaveOp>();
display_list->push<ConcatOp>(gfx::TransformToSkM44(it->transform));
display_list->EndPaintOfPairedBegin();
}
display_list->StartPaint();
display_list->push<SaveOp>();
display_list->push<ClipRectOp>(gfx::RectToSkRect(paint_bounds),
SkClipOp::kIntersect, false);
display_list->push<DrawImageOp>(
it->image, static_cast<float>(it->point.x()),
static_cast<float>(it->point.y()), it->sampling, &it->flags);
display_list->push<RestoreOp>();
display_list->EndPaintOfUnpaired(paint_bounds);
if (!it->transform.IsIdentity()) {
display_list->StartPaint();
display_list->push<RestoreOp>();
display_list->EndPaintOfPairedEnd();
}
}
for (const SkottieData& skottie_data : skottie_data_) {
display_list->StartPaint();
display_list->push<DrawSkottieOp>(
skottie_data.skottie, gfx::RectToSkRect(skottie_data.dst),
skottie_data.t, skottie_data.images, skottie_data.color_map,
skottie_data.text_map);
display_list->EndPaintOfUnpaired(paint_bounds);
}
if (contains_slow_paths_) {
// Add 6 slow paths, passing the reporting threshold.
SkPath path;
path.addCircle(2, 2, 5);
path.addCircle(3, 4, 2);
display_list->StartPaint();
for (int i = 0; i < 6; ++i) {
display_list->push<ClipPathOp>(path, SkClipOp::kIntersect, true);
}
display_list->EndPaintOfUnpaired(paint_bounds);
}
if (fill_with_nonsolid_color_) {
PaintFlags flags;
flags.setColor(SK_ColorRED);
display_list->StartPaint();
gfx::Rect draw_rect = paint_bounds;
while (!draw_rect.IsEmpty()) {
display_list->push<DrawIRectOp>(gfx::RectToSkIRect(draw_rect), flags);
draw_rect.Inset(1);
}
display_list->EndPaintOfUnpaired(paint_bounds);
}
if (has_non_aa_paint_) {
PaintFlags flags;
flags.setAntiAlias(false);
display_list->StartPaint();
display_list->push<DrawRectOp>(SkRect::MakeWH(10, 10), flags);
display_list->EndPaintOfUnpaired(paint_bounds);
}
if (has_draw_text_op_) {
display_list->StartPaint();
SkFont font = skia::DefaultFont();
display_list->push<DrawTextBlobOp>(SkTextBlob::MakeFromString("any", font),
0.0f, 0.0f, PaintFlags());
display_list->EndPaintOfUnpaired(paint_bounds);
}
display_list->Finalize();
return display_list;
}
bool FakeContentLayerClient::FillsBoundsCompletely() const { return false; }
} // namespace cc