-
Notifications
You must be signed in to change notification settings - Fork 6k
/
display_list_unittests.cc
5949 lines (5196 loc) · 213 KB
/
display_list_unittests.cc
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/dl_blend_mode.h"
#include "flutter/display_list/dl_builder.h"
#include "flutter/display_list/dl_paint.h"
#include "flutter/display_list/geometry/dl_rtree.h"
#include "flutter/display_list/skia/dl_sk_dispatcher.h"
#include "flutter/display_list/testing/dl_test_snippets.h"
#include "flutter/display_list/utils/dl_receiver_utils.h"
#include "flutter/fml/logging.h"
#include "flutter/fml/math.h"
#include "flutter/impeller/typographer/backends/skia/text_frame_skia.h"
#include "flutter/testing/assertions_skia.h"
#include "flutter/testing/display_list_testing.h"
#include "flutter/testing/testing.h"
#include "third_party/skia/include/core/SkBBHFactory.h"
#include "third_party/skia/include/core/SkColorFilter.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
#include "third_party/skia/include/core/SkRSXform.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace flutter {
DlOpReceiver& DisplayListBuilderTestingAccessor(DisplayListBuilder& builder) {
return builder.asReceiver();
}
DlPaint DisplayListBuilderTestingAttributes(DisplayListBuilder& builder) {
return builder.CurrentAttributes();
}
int DisplayListBuilderTestingLastOpIndex(DisplayListBuilder& builder) {
return builder.LastOpIndex();
}
namespace testing {
static std::vector<testing::DisplayListInvocationGroup> allGroups =
CreateAllGroups();
using ClipOp = DlCanvas::ClipOp;
using PointMode = DlCanvas::PointMode;
template <typename BaseT>
class DisplayListTestBase : public BaseT {
public:
DisplayListTestBase() = default;
static DlOpReceiver& ToReceiver(DisplayListBuilder& builder) {
return DisplayListBuilderTestingAccessor(builder);
}
static sk_sp<DisplayList> Build(DisplayListInvocation& invocation) {
DisplayListBuilder builder;
invocation.Invoke(ToReceiver(builder));
return builder.Build();
}
static sk_sp<DisplayList> Build(size_t g_index, size_t v_index) {
DisplayListBuilder builder;
DlOpReceiver& receiver =
DisplayListTestBase<::testing::Test>::ToReceiver(builder);
uint32_t op_count = 0u;
size_t byte_count = 0u;
uint32_t depth = 0u;
uint32_t render_op_depth_cost = 1u;
for (size_t i = 0; i < allGroups.size(); i++) {
DisplayListInvocationGroup& group = allGroups[i];
size_t j = (i == g_index ? v_index : 0);
if (j >= group.variants.size()) {
continue;
}
DisplayListInvocation& invocation = group.variants[j];
op_count += invocation.op_count();
byte_count += invocation.raw_byte_count();
depth += invocation.depth_accumulated(render_op_depth_cost);
invocation.Invoke(receiver);
render_op_depth_cost =
invocation.adjust_render_op_depth_cost(render_op_depth_cost);
}
sk_sp<DisplayList> dl = builder.Build();
std::string name;
if (g_index >= allGroups.size()) {
name = "Default";
} else {
name = allGroups[g_index].op_name;
if (v_index >= allGroups[g_index].variants.size()) {
name += " skipped";
} else {
name += " variant " + std::to_string(v_index + 1);
}
}
EXPECT_EQ(dl->op_count(false), op_count) << name;
EXPECT_EQ(dl->bytes(false), byte_count + sizeof(DisplayList)) << name;
EXPECT_EQ(dl->total_depth(), depth) << name;
return dl;
}
static void check_defaults(
DisplayListBuilder& builder,
const SkRect& cull_rect = DisplayListBuilder::kMaxCullRect) {
DlPaint builder_paint = DisplayListBuilderTestingAttributes(builder);
DlPaint defaults;
EXPECT_EQ(builder_paint.isAntiAlias(), defaults.isAntiAlias());
EXPECT_EQ(builder_paint.isInvertColors(), defaults.isInvertColors());
EXPECT_EQ(builder_paint.getColor(), defaults.getColor());
EXPECT_EQ(builder_paint.getBlendMode(), defaults.getBlendMode());
EXPECT_EQ(builder_paint.getDrawStyle(), defaults.getDrawStyle());
EXPECT_EQ(builder_paint.getStrokeWidth(), defaults.getStrokeWidth());
EXPECT_EQ(builder_paint.getStrokeMiter(), defaults.getStrokeMiter());
EXPECT_EQ(builder_paint.getStrokeCap(), defaults.getStrokeCap());
EXPECT_EQ(builder_paint.getStrokeJoin(), defaults.getStrokeJoin());
EXPECT_EQ(builder_paint.getColorSource(), defaults.getColorSource());
EXPECT_EQ(builder_paint.getColorFilter(), defaults.getColorFilter());
EXPECT_EQ(builder_paint.getImageFilter(), defaults.getImageFilter());
EXPECT_EQ(builder_paint.getMaskFilter(), defaults.getMaskFilter());
EXPECT_EQ(builder_paint, defaults);
EXPECT_TRUE(builder_paint.isDefault());
EXPECT_EQ(builder.GetTransform(), SkMatrix());
EXPECT_EQ(builder.GetTransformFullPerspective(), SkM44());
EXPECT_EQ(builder.GetLocalClipBounds(), cull_rect);
EXPECT_EQ(builder.GetDestinationClipBounds(), cull_rect);
EXPECT_EQ(builder.GetSaveCount(), 1);
}
typedef const std::function<void(DlCanvas&)> DlSetup;
typedef const std::function<void(DlCanvas&, DlPaint&, SkRect& rect)>
DlRenderer;
static void verify_inverted_bounds(DlSetup& setup,
DlRenderer& renderer,
DlPaint paint,
SkRect render_rect,
SkRect expected_bounds,
const std::string& desc) {
DisplayListBuilder builder;
setup(builder);
renderer(builder, paint, render_rect);
auto dl = builder.Build();
EXPECT_EQ(dl->op_count(), 1u) << desc;
EXPECT_EQ(dl->bounds(), expected_bounds) << desc;
}
static void check_inverted_bounds(DlRenderer& renderer,
const std::string& desc) {
SkRect rect = SkRect::MakeLTRB(0.0f, 0.0f, 10.0f, 10.0f);
SkRect invertedLR = SkRect::MakeLTRB(rect.fRight, rect.fTop, //
rect.fLeft, rect.fBottom);
SkRect invertedTB = SkRect::MakeLTRB(rect.fLeft, rect.fBottom, //
rect.fRight, rect.fTop);
SkRect invertedLTRB = SkRect::MakeLTRB(rect.fRight, rect.fBottom, //
rect.fLeft, rect.fTop);
auto empty_setup = [](DlCanvas&) {};
ASSERT_TRUE(rect.fLeft < rect.fRight);
ASSERT_TRUE(rect.fTop < rect.fBottom);
ASSERT_FALSE(rect.isEmpty());
ASSERT_TRUE(invertedLR.fLeft > invertedLR.fRight);
ASSERT_TRUE(invertedLR.isEmpty());
ASSERT_TRUE(invertedTB.fTop > invertedTB.fBottom);
ASSERT_TRUE(invertedTB.isEmpty());
ASSERT_TRUE(invertedLTRB.fLeft > invertedLTRB.fRight);
ASSERT_TRUE(invertedLTRB.fTop > invertedLTRB.fBottom);
ASSERT_TRUE(invertedLTRB.isEmpty());
DlPaint ref_paint = DlPaint();
SkRect ref_bounds = rect;
verify_inverted_bounds(empty_setup, renderer, ref_paint, invertedLR,
ref_bounds, desc + " LR swapped");
verify_inverted_bounds(empty_setup, renderer, ref_paint, invertedTB,
ref_bounds, desc + " TB swapped");
verify_inverted_bounds(empty_setup, renderer, ref_paint, invertedLTRB,
ref_bounds, desc + " LR&TB swapped");
// Round joins are used because miter joins greatly pad the bounds,
// but only on paths. So we use round joins for consistency there.
// We aren't fully testing all stroke-related bounds computations here,
// those are more fully tested in the render tests. We are simply
// checking that they are applied to the ordered bounds.
DlPaint stroke_paint = DlPaint() //
.setDrawStyle(DlDrawStyle::kStroke) //
.setStrokeJoin(DlStrokeJoin::kRound) //
.setStrokeWidth(2.0f);
SkRect stroke_bounds = rect.makeOutset(1.0f, 1.0f);
verify_inverted_bounds(empty_setup, renderer, stroke_paint, invertedLR,
stroke_bounds, desc + " LR swapped, sw 2");
verify_inverted_bounds(empty_setup, renderer, stroke_paint, invertedTB,
stroke_bounds, desc + " TB swapped, sw 2");
verify_inverted_bounds(empty_setup, renderer, stroke_paint, invertedLTRB,
stroke_bounds, desc + " LR&TB swapped, sw 2");
DlBlurMaskFilter mask_filter(DlBlurStyle::kNormal, 2.0f);
DlPaint maskblur_paint = DlPaint() //
.setMaskFilter(&mask_filter);
SkRect maskblur_bounds = rect.makeOutset(6.0f, 6.0f);
verify_inverted_bounds(empty_setup, renderer, maskblur_paint, invertedLR,
maskblur_bounds, desc + " LR swapped, mask 2");
verify_inverted_bounds(empty_setup, renderer, maskblur_paint, invertedTB,
maskblur_bounds, desc + " TB swapped, mask 2");
verify_inverted_bounds(empty_setup, renderer, maskblur_paint, invertedLTRB,
maskblur_bounds, desc + " LR&TB swapped, mask 2");
DlErodeImageFilter erode_filter(2.0f, 2.0f);
DlPaint erode_paint = DlPaint() //
.setImageFilter(&erode_filter);
SkRect erode_bounds = rect.makeInset(2.0f, 2.0f);
verify_inverted_bounds(empty_setup, renderer, erode_paint, invertedLR,
erode_bounds, desc + " LR swapped, erode 2");
verify_inverted_bounds(empty_setup, renderer, erode_paint, invertedTB,
erode_bounds, desc + " TB swapped, erode 2");
verify_inverted_bounds(empty_setup, renderer, erode_paint, invertedLTRB,
erode_bounds, desc + " LR&TB swapped, erode 2");
}
private:
FML_DISALLOW_COPY_AND_ASSIGN(DisplayListTestBase);
};
using DisplayListTest = DisplayListTestBase<::testing::Test>;
TEST_F(DisplayListTest, Defaults) {
DisplayListBuilder builder;
check_defaults(builder);
}
TEST_F(DisplayListTest, EmptyBuild) {
DisplayListBuilder builder;
auto dl = builder.Build();
EXPECT_EQ(dl->op_count(), 0u);
EXPECT_EQ(dl->bytes(), sizeof(DisplayList));
EXPECT_EQ(dl->total_depth(), 0u);
}
TEST_F(DisplayListTest, EmptyRebuild) {
DisplayListBuilder builder;
auto dl1 = builder.Build();
auto dl2 = builder.Build();
auto dl3 = builder.Build();
ASSERT_TRUE(dl1->Equals(dl2));
ASSERT_TRUE(dl2->Equals(dl3));
}
TEST_F(DisplayListTest, NopReusedBuildIsReallyEmpty) {
DisplayListBuilder builder;
builder.DrawRect(DlRect::MakeLTRB(0.0f, 0.0f, 10.0f, 10.0f), DlPaint());
{
auto dl1 = builder.Build();
EXPECT_EQ(dl1->op_count(), 1u);
EXPECT_GT(dl1->bytes(), sizeof(DisplayList));
EXPECT_EQ(dl1->GetBounds(), DlRect::MakeLTRB(0.0f, 0.0f, 10.0f, 10.0f));
}
{
auto dl2 = builder.Build();
EXPECT_EQ(dl2->op_count(), 0u);
EXPECT_EQ(dl2->bytes(), sizeof(DisplayList));
EXPECT_EQ(dl2->GetBounds(), DlRect());
}
}
TEST_F(DisplayListTest, GeneralReceiverInitialValues) {
DisplayListGeneralReceiver receiver;
EXPECT_EQ(receiver.GetOpsReceived(), 0u);
auto max_type = static_cast<int>(DisplayListOpType::kMaxOp);
for (int i = 0; i <= max_type; i++) {
DisplayListOpType type = static_cast<DisplayListOpType>(i);
EXPECT_EQ(receiver.GetOpsReceived(type), 0u) << type;
}
auto max_category = static_cast<int>(DisplayListOpCategory::kMaxCategory);
for (int i = 0; i <= max_category; i++) {
DisplayListOpCategory category = static_cast<DisplayListOpCategory>(i);
EXPECT_EQ(receiver.GetOpsReceived(category), 0u) << category;
}
}
TEST_F(DisplayListTest, Iteration) {
DisplayListBuilder builder;
builder.DrawRect(SkRect{10, 10, 20, 20}, DlPaint());
auto dl = builder.Build();
for (DlIndex i : *dl) {
EXPECT_EQ(dl->GetOpType(i), DisplayListOpType::kDrawRect) //
<< "at " << i;
EXPECT_EQ(dl->GetOpCategory(i), DisplayListOpCategory::kRendering)
<< "at " << i;
}
}
TEST_F(DisplayListTest, InvalidIndices) {
DisplayListBuilder builder;
builder.DrawRect(kTestSkBounds, DlPaint());
auto dl = builder.Build();
DisplayListGeneralReceiver receiver;
EXPECT_FALSE(dl->Dispatch(receiver, -1));
EXPECT_FALSE(dl->Dispatch(receiver, dl->GetRecordCount()));
EXPECT_EQ(dl->GetOpType(-1), DisplayListOpType::kInvalidOp);
EXPECT_EQ(dl->GetOpType(dl->GetRecordCount()), DisplayListOpType::kInvalidOp);
EXPECT_EQ(dl->GetOpCategory(-1), DisplayListOpCategory::kInvalidCategory);
EXPECT_EQ(dl->GetOpCategory(dl->GetRecordCount()),
DisplayListOpCategory::kInvalidCategory);
EXPECT_EQ(dl->GetOpCategory(-1), DisplayListOpCategory::kInvalidCategory);
EXPECT_EQ(dl->GetOpCategory(DisplayListOpType::kInvalidOp),
DisplayListOpCategory::kInvalidCategory);
EXPECT_EQ(dl->GetOpCategory(DisplayListOpType::kMaxOp),
DisplayListOpCategory::kInvalidCategory);
EXPECT_EQ(receiver.GetOpsReceived(), 0u);
}
TEST_F(DisplayListTest, ValidIndices) {
DisplayListBuilder builder;
builder.DrawRect(kTestSkBounds, DlPaint());
auto dl = builder.Build();
DisplayListGeneralReceiver receiver;
EXPECT_EQ(dl->GetRecordCount(), 1u);
EXPECT_TRUE(dl->Dispatch(receiver, 0u));
EXPECT_EQ(dl->GetOpType(0u), DisplayListOpType::kDrawRect);
EXPECT_EQ(dl->GetOpCategory(0u), DisplayListOpCategory::kRendering);
EXPECT_EQ(receiver.GetOpsReceived(), 1u);
}
TEST_F(DisplayListTest, BuilderCanBeReused) {
DisplayListBuilder builder(kTestSkBounds);
builder.DrawRect(kTestSkBounds, DlPaint());
auto dl = builder.Build();
builder.DrawRect(kTestSkBounds, DlPaint());
auto dl2 = builder.Build();
ASSERT_TRUE(dl->Equals(dl2));
}
TEST_F(DisplayListTest, SaveRestoreRestoresTransform) {
SkRect cull_rect = SkRect::MakeLTRB(-10.0f, -10.0f, 500.0f, 500.0f);
DisplayListBuilder builder(cull_rect);
builder.Save();
builder.Translate(10.0f, 10.0f);
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.Scale(10.0f, 10.0f);
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.Skew(0.1f, 0.1f);
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.Rotate(45.0f);
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.Transform(SkMatrix::Scale(10.0f, 10.0f));
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.Transform2DAffine(1.0f, 0.0f, 12.0f, //
0.0f, 1.0f, 35.0f);
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.Transform(SkM44(SkMatrix::Scale(10.0f, 10.0f)));
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.TransformFullPerspective(1.0f, 0.0f, 0.0f, 12.0f, //
0.0f, 1.0f, 0.0f, 35.0f, //
0.0f, 0.0f, 1.0f, 5.0f, //
0.0f, 0.0f, 0.0f, 1.0f);
builder.Restore();
check_defaults(builder, cull_rect);
}
TEST_F(DisplayListTest, BuildRestoresTransform) {
SkRect cull_rect = SkRect::MakeLTRB(-10.0f, -10.0f, 500.0f, 500.0f);
DisplayListBuilder builder(cull_rect);
builder.Translate(10.0f, 10.0f);
builder.Build();
check_defaults(builder, cull_rect);
builder.Scale(10.0f, 10.0f);
builder.Build();
check_defaults(builder, cull_rect);
builder.Skew(0.1f, 0.1f);
builder.Build();
check_defaults(builder, cull_rect);
builder.Rotate(45.0f);
builder.Build();
check_defaults(builder, cull_rect);
builder.Transform(SkMatrix::Scale(10.0f, 10.0f));
builder.Build();
check_defaults(builder, cull_rect);
builder.Transform2DAffine(1.0f, 0.0f, 12.0f, //
0.0f, 1.0f, 35.0f);
builder.Build();
check_defaults(builder, cull_rect);
builder.Transform(SkM44(SkMatrix::Scale(10.0f, 10.0f)));
builder.Build();
check_defaults(builder, cull_rect);
builder.TransformFullPerspective(1.0f, 0.0f, 0.0f, 12.0f, //
0.0f, 1.0f, 0.0f, 35.0f, //
0.0f, 0.0f, 1.0f, 5.0f, //
0.0f, 0.0f, 0.0f, 1.0f);
builder.Build();
check_defaults(builder, cull_rect);
}
TEST_F(DisplayListTest, SaveRestoreRestoresClip) {
SkRect cull_rect = SkRect::MakeLTRB(-10.0f, -10.0f, 500.0f, 500.0f);
DisplayListBuilder builder(cull_rect);
builder.Save();
builder.ClipRect(SkRect{0.0f, 0.0f, 10.0f, 10.0f});
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.ClipRRect(SkRRect::MakeRectXY({0.0f, 0.0f, 5.0f, 5.0f}, 2.0f, 2.0f));
builder.Restore();
check_defaults(builder, cull_rect);
builder.Save();
builder.ClipPath(SkPath().addOval({0.0f, 0.0f, 10.0f, 10.0f}));
builder.Restore();
check_defaults(builder, cull_rect);
}
TEST_F(DisplayListTest, BuildRestoresClip) {
SkRect cull_rect = SkRect::MakeLTRB(-10.0f, -10.0f, 500.0f, 500.0f);
DisplayListBuilder builder(cull_rect);
builder.ClipRect(SkRect{0.0f, 0.0f, 10.0f, 10.0f});
builder.Build();
check_defaults(builder, cull_rect);
builder.ClipRRect(SkRRect::MakeRectXY({0.0f, 0.0f, 5.0f, 5.0f}, 2.0f, 2.0f));
builder.Build();
check_defaults(builder, cull_rect);
builder.ClipPath(SkPath().addOval({0.0f, 0.0f, 10.0f, 10.0f}));
builder.Build();
check_defaults(builder, cull_rect);
}
TEST_F(DisplayListTest, BuildRestoresAttributes) {
SkRect cull_rect = SkRect::MakeLTRB(-10.0f, -10.0f, 500.0f, 500.0f);
DisplayListBuilder builder(cull_rect);
DlOpReceiver& receiver = ToReceiver(builder);
receiver.setAntiAlias(true);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setInvertColors(true);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setColor(DlColor::kRed());
builder.Build();
check_defaults(builder, cull_rect);
receiver.setBlendMode(DlBlendMode::kColorBurn);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setDrawStyle(DlDrawStyle::kStrokeAndFill);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setStrokeWidth(300.0f);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setStrokeMiter(300.0f);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setStrokeCap(DlStrokeCap::kRound);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setStrokeJoin(DlStrokeJoin::kRound);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setColorSource(&kTestSource1);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setColorFilter(&kTestMatrixColorFilter1);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setImageFilter(&kTestBlurImageFilter1);
builder.Build();
check_defaults(builder, cull_rect);
receiver.setMaskFilter(&kTestMaskFilter1);
builder.Build();
check_defaults(builder, cull_rect);
}
TEST_F(DisplayListTest, BuilderBoundsTransformComparedToSkia) {
const SkRect frame_rect = SkRect::MakeLTRB(10, 10, 100, 100);
DisplayListBuilder builder(frame_rect);
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(frame_rect);
ASSERT_EQ(builder.GetDestinationClipBounds(),
SkRect::Make(canvas->getDeviceClipBounds()));
ASSERT_EQ(builder.GetLocalClipBounds().makeOutset(1, 1),
canvas->getLocalClipBounds());
ASSERT_EQ(builder.GetTransform(), canvas->getTotalMatrix());
}
TEST_F(DisplayListTest, BuilderInitialClipBounds) {
SkRect cull_rect = SkRect::MakeWH(100, 100);
SkRect clip_bounds = SkRect::MakeWH(100, 100);
DisplayListBuilder builder(cull_rect);
ASSERT_EQ(builder.GetDestinationClipBounds(), clip_bounds);
}
TEST_F(DisplayListTest, BuilderInitialClipBoundsNaN) {
SkRect cull_rect = SkRect::MakeWH(SK_ScalarNaN, SK_ScalarNaN);
SkRect clip_bounds = SkRect::MakeEmpty();
DisplayListBuilder builder(cull_rect);
ASSERT_EQ(builder.GetDestinationClipBounds(), clip_bounds);
}
TEST_F(DisplayListTest, BuilderClipBoundsAfterClipRect) {
SkRect cull_rect = SkRect::MakeWH(100, 100);
SkRect clip_rect = SkRect::MakeLTRB(10, 10, 20, 20);
SkRect clip_bounds = SkRect::MakeLTRB(10, 10, 20, 20);
DisplayListBuilder builder(cull_rect);
builder.ClipRect(clip_rect, ClipOp::kIntersect, false);
ASSERT_EQ(builder.GetDestinationClipBounds(), clip_bounds);
}
TEST_F(DisplayListTest, BuilderClipBoundsAfterClipRRect) {
SkRect cull_rect = SkRect::MakeWH(100, 100);
SkRect clip_rect = SkRect::MakeLTRB(10, 10, 20, 20);
SkRRect clip_rrect = SkRRect::MakeRectXY(clip_rect, 2, 2);
SkRect clip_bounds = SkRect::MakeLTRB(10, 10, 20, 20);
DisplayListBuilder builder(cull_rect);
builder.ClipRRect(clip_rrect, ClipOp::kIntersect, false);
ASSERT_EQ(builder.GetDestinationClipBounds(), clip_bounds);
}
TEST_F(DisplayListTest, BuilderClipBoundsAfterClipPath) {
SkRect cull_rect = SkRect::MakeWH(100, 100);
SkPath clip_path = SkPath().addRect(10, 10, 15, 15).addRect(15, 15, 20, 20);
SkRect clip_bounds = SkRect::MakeLTRB(10, 10, 20, 20);
DisplayListBuilder builder(cull_rect);
builder.ClipPath(clip_path, ClipOp::kIntersect, false);
ASSERT_EQ(builder.GetDestinationClipBounds(), clip_bounds);
}
TEST_F(DisplayListTest, BuilderInitialClipBoundsNonZero) {
SkRect cull_rect = SkRect::MakeLTRB(10, 10, 100, 100);
SkRect clip_bounds = SkRect::MakeLTRB(10, 10, 100, 100);
DisplayListBuilder builder(cull_rect);
ASSERT_EQ(builder.GetDestinationClipBounds(), clip_bounds);
}
TEST_F(DisplayListTest, UnclippedSaveLayerContentAccountsForFilter) {
SkRect cull_rect = SkRect::MakeLTRB(0.0f, 0.0f, 300.0f, 300.0f);
SkRect clip_rect = SkRect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
SkRect draw_rect = SkRect::MakeLTRB(50.0f, 140.0f, 101.0f, 160.0f);
auto filter = DlBlurImageFilter::Make(10.0f, 10.0f, DlTileMode::kDecal);
DlPaint layer_paint = DlPaint().setImageFilter(filter);
ASSERT_TRUE(clip_rect.intersects(draw_rect));
ASSERT_TRUE(cull_rect.contains(clip_rect));
ASSERT_TRUE(cull_rect.contains(draw_rect));
DisplayListBuilder builder;
builder.Save();
{
builder.ClipRect(clip_rect, ClipOp::kIntersect, false);
builder.SaveLayer(&cull_rect, &layer_paint);
{ //
builder.DrawRect(draw_rect, DlPaint());
}
builder.Restore();
}
builder.Restore();
auto display_list = builder.Build();
EXPECT_EQ(display_list->op_count(), 6u);
EXPECT_EQ(display_list->total_depth(), 2u);
SkRect result_rect = draw_rect.makeOutset(30.0f, 30.0f);
ASSERT_TRUE(result_rect.intersect(clip_rect));
ASSERT_EQ(result_rect, SkRect::MakeLTRB(100.0f, 110.0f, 131.0f, 190.0f));
EXPECT_EQ(display_list->bounds(), result_rect);
}
TEST_F(DisplayListTest, ClippedSaveLayerContentAccountsForFilter) {
SkRect cull_rect = SkRect::MakeLTRB(0.0f, 0.0f, 300.0f, 300.0f);
SkRect clip_rect = SkRect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
SkRect draw_rect = SkRect::MakeLTRB(50.0f, 140.0f, 99.0f, 160.0f);
auto filter = DlBlurImageFilter::Make(10.0f, 10.0f, DlTileMode::kDecal);
DlPaint layer_paint = DlPaint().setImageFilter(filter);
ASSERT_FALSE(clip_rect.intersects(draw_rect));
ASSERT_TRUE(cull_rect.contains(clip_rect));
ASSERT_TRUE(cull_rect.contains(draw_rect));
DisplayListBuilder builder;
builder.Save();
{
builder.ClipRect(clip_rect, ClipOp::kIntersect, false);
builder.SaveLayer(&cull_rect, &layer_paint);
{ //
builder.DrawRect(draw_rect, DlPaint());
}
builder.Restore();
}
builder.Restore();
auto display_list = builder.Build();
EXPECT_EQ(display_list->op_count(), 6u);
EXPECT_EQ(display_list->total_depth(), 2u);
SkRect result_rect = draw_rect.makeOutset(30.0f, 30.0f);
ASSERT_TRUE(result_rect.intersect(clip_rect));
ASSERT_EQ(result_rect, SkRect::MakeLTRB(100.0f, 110.0f, 129.0f, 190.0f));
EXPECT_EQ(display_list->bounds(), result_rect);
}
TEST_F(DisplayListTest, OOBSaveLayerContentCulledWithBlurFilter) {
SkRect cull_rect = SkRect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
SkRect draw_rect = SkRect::MakeLTRB(25.0f, 25.0f, 99.0f, 75.0f);
auto filter = DlBlurImageFilter::Make(10.0f, 10.0f, DlTileMode::kDecal);
DlPaint layer_paint = DlPaint().setImageFilter(filter);
// We want a draw rect that is outside the layer bounds even though its
// filtered output might be inside. The drawn rect should be culled by
// the expectations of the layer bounds even though it is close enough
// to be visible due to filtering.
ASSERT_FALSE(cull_rect.intersects(draw_rect));
SkRect mapped_rect;
ASSERT_TRUE(filter->map_local_bounds(draw_rect, mapped_rect));
ASSERT_TRUE(mapped_rect.intersects(cull_rect));
DisplayListBuilder builder;
builder.SaveLayer(&cull_rect, &layer_paint);
{ //
builder.DrawRect(draw_rect, DlPaint());
}
builder.Restore();
auto display_list = builder.Build();
EXPECT_EQ(display_list->op_count(), 2u);
EXPECT_EQ(display_list->total_depth(), 1u);
EXPECT_TRUE(display_list->bounds().isEmpty()) << display_list->bounds();
}
TEST_F(DisplayListTest, OOBSaveLayerContentCulledWithMatrixFilter) {
SkRect cull_rect = SkRect::MakeLTRB(100.0f, 100.0f, 200.0f, 200.0f);
SkRect draw_rect = SkRect::MakeLTRB(25.0f, 125.0f, 75.0f, 175.0f);
auto filter = DlMatrixImageFilter::Make(SkMatrix::Translate(100.0f, 0.0f),
DlImageSampling::kLinear);
DlPaint layer_paint = DlPaint().setImageFilter(filter);
// We want a draw rect that is outside the layer bounds even though its
// filtered output might be inside. The drawn rect should be culled by
// the expectations of the layer bounds even though it is close enough
// to be visible due to filtering.
ASSERT_FALSE(cull_rect.intersects(draw_rect));
SkRect mapped_rect;
ASSERT_TRUE(filter->map_local_bounds(draw_rect, mapped_rect));
ASSERT_TRUE(mapped_rect.intersects(cull_rect));
DisplayListBuilder builder;
builder.SaveLayer(&cull_rect, &layer_paint);
{ //
builder.DrawRect(draw_rect, DlPaint());
}
builder.Restore();
auto display_list = builder.Build();
EXPECT_EQ(display_list->op_count(), 2u);
EXPECT_EQ(display_list->total_depth(), 1u);
EXPECT_TRUE(display_list->bounds().isEmpty()) << display_list->bounds();
}
TEST_F(DisplayListTest, SingleOpSizes) {
for (auto& group : allGroups) {
for (size_t i = 0; i < group.variants.size(); i++) {
auto& invocation = group.variants[i];
sk_sp<DisplayList> dl = Build(invocation);
auto desc = group.op_name + "(variant " + std::to_string(i + 1) + ")";
EXPECT_EQ(dl->op_count(false), invocation.op_count()) << desc;
EXPECT_EQ(dl->bytes(false), invocation.byte_count()) << desc;
EXPECT_EQ(dl->total_depth(), invocation.depth_accumulated()) << desc;
}
}
}
TEST_F(DisplayListTest, SingleOpDisplayListsNotEqualEmpty) {
sk_sp<DisplayList> empty = DisplayListBuilder().Build();
for (auto& group : allGroups) {
for (size_t i = 0; i < group.variants.size(); i++) {
sk_sp<DisplayList> dl = Build(group.variants[i]);
auto desc =
group.op_name + "(variant " + std::to_string(i + 1) + " != empty)";
if (group.variants[i].is_empty()) {
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, empty));
ASSERT_TRUE(empty->Equals(*dl)) << desc;
} else {
ASSERT_TRUE(DisplayListsNE_Verbose(dl, empty));
ASSERT_FALSE(empty->Equals(*dl)) << desc;
}
}
}
}
TEST_F(DisplayListTest, SingleOpDisplayListsRecapturedAreEqual) {
for (auto& group : allGroups) {
for (size_t i = 0; i < group.variants.size(); i++) {
sk_sp<DisplayList> dl = Build(group.variants[i]);
// Verify recapturing the replay of the display list is Equals()
// when dispatching directly from the DL to another builder
DisplayListBuilder copy_builder;
DlOpReceiver& r = ToReceiver(copy_builder);
dl->Dispatch(r);
sk_sp<DisplayList> copy = copy_builder.Build();
auto desc =
group.op_name + "(variant " + std::to_string(i + 1) + " == copy)";
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, copy));
ASSERT_EQ(copy->op_count(false), dl->op_count(false)) << desc;
ASSERT_EQ(copy->GetRecordCount(), dl->GetRecordCount());
ASSERT_EQ(copy->bytes(false), dl->bytes(false)) << desc;
ASSERT_EQ(copy->op_count(true), dl->op_count(true)) << desc;
ASSERT_EQ(copy->bytes(true), dl->bytes(true)) << desc;
ASSERT_EQ(copy->total_depth(), dl->total_depth()) << desc;
ASSERT_EQ(copy->bounds(), dl->bounds()) << desc;
ASSERT_TRUE(copy->Equals(*dl)) << desc;
ASSERT_TRUE(dl->Equals(*copy)) << desc;
}
}
}
TEST_F(DisplayListTest, SingleOpDisplayListsRecapturedByIndexAreEqual) {
for (auto& group : allGroups) {
for (size_t i = 0; i < group.variants.size(); i++) {
sk_sp<DisplayList> dl = Build(group.variants[i]);
// Verify recapturing the replay of the display list is Equals()
// when dispatching directly from the DL to another builder
DisplayListBuilder copy_builder;
DlOpReceiver& r = ToReceiver(copy_builder);
for (DlIndex i = 0; i < dl->GetRecordCount(); i++) {
EXPECT_NE(dl->GetOpType(i), DisplayListOpType::kInvalidOp);
EXPECT_NE(dl->GetOpCategory(i),
DisplayListOpCategory::kInvalidCategory);
EXPECT_TRUE(dl->Dispatch(r, i));
}
sk_sp<DisplayList> copy = copy_builder.Build();
auto desc =
group.op_name + "(variant " + std::to_string(i + 1) + " == copy)";
ASSERT_TRUE(DisplayListsEQ_Verbose(dl, copy));
ASSERT_EQ(copy->op_count(false), dl->op_count(false)) << desc;
ASSERT_EQ(copy->GetRecordCount(), dl->GetRecordCount());
ASSERT_EQ(copy->bytes(false), dl->bytes(false)) << desc;
ASSERT_EQ(copy->op_count(true), dl->op_count(true)) << desc;
ASSERT_EQ(copy->bytes(true), dl->bytes(true)) << desc;
ASSERT_EQ(copy->total_depth(), dl->total_depth()) << desc;
ASSERT_EQ(copy->bounds(), dl->bounds()) << desc;
ASSERT_TRUE(copy->Equals(*dl)) << desc;
ASSERT_TRUE(dl->Equals(*copy)) << desc;
}
}
}
TEST_F(DisplayListTest, SingleOpDisplayListsCompareToEachOther) {
for (auto& group : allGroups) {
std::vector<sk_sp<DisplayList>> lists_a;
std::vector<sk_sp<DisplayList>> lists_b;
for (size_t i = 0; i < group.variants.size(); i++) {
lists_a.push_back(Build(group.variants[i]));
lists_b.push_back(Build(group.variants[i]));
}
for (size_t i = 0; i < lists_a.size(); i++) {
sk_sp<DisplayList> listA = lists_a[i];
for (size_t j = 0; j < lists_b.size(); j++) {
sk_sp<DisplayList> listB = lists_b[j];
auto desc = group.op_name + "(variant " + std::to_string(i + 1) +
" ==? variant " + std::to_string(j + 1) + ")";
if (i == j ||
(group.variants[i].is_empty() && group.variants[j].is_empty())) {
// They are the same variant, or both variants are NOPs
ASSERT_EQ(listA->op_count(false), listB->op_count(false)) << desc;
ASSERT_EQ(listA->bytes(false), listB->bytes(false)) << desc;
ASSERT_EQ(listA->op_count(true), listB->op_count(true)) << desc;
ASSERT_EQ(listA->bytes(true), listB->bytes(true)) << desc;
EXPECT_EQ(listA->total_depth(), listB->total_depth()) << desc;
ASSERT_EQ(listA->bounds(), listB->bounds()) << desc;
ASSERT_TRUE(listA->Equals(*listB)) << desc;
ASSERT_TRUE(listB->Equals(*listA)) << desc;
} else {
// No assertion on op/byte counts or bounds
// they may or may not be equal between variants
ASSERT_FALSE(listA->Equals(*listB)) << desc;
ASSERT_FALSE(listB->Equals(*listA)) << desc;
}
}
}
}
}
TEST_F(DisplayListTest, SingleOpDisplayListsAreEqualWithOrWithoutRtree) {
for (auto& group : allGroups) {
for (size_t i = 0; i < group.variants.size(); i++) {
DisplayListBuilder builder1(/*prepare_rtree=*/false);
DisplayListBuilder builder2(/*prepare_rtree=*/true);
group.variants[i].Invoke(ToReceiver(builder1));
group.variants[i].Invoke(ToReceiver(builder2));
sk_sp<DisplayList> dl1 = builder1.Build();
sk_sp<DisplayList> dl2 = builder2.Build();
auto desc = group.op_name + "(variant " + std::to_string(i + 1) + " )";
ASSERT_EQ(dl1->op_count(false), dl2->op_count(false)) << desc;
ASSERT_EQ(dl1->bytes(false), dl2->bytes(false)) << desc;
ASSERT_EQ(dl1->op_count(true), dl2->op_count(true)) << desc;
ASSERT_EQ(dl1->bytes(true), dl2->bytes(true)) << desc;
EXPECT_EQ(dl1->total_depth(), dl2->total_depth()) << desc;
ASSERT_EQ(dl1->bounds(), dl2->bounds()) << desc;
ASSERT_EQ(dl1->total_depth(), dl2->total_depth()) << desc;
ASSERT_TRUE(DisplayListsEQ_Verbose(dl1, dl2)) << desc;
ASSERT_TRUE(DisplayListsEQ_Verbose(dl2, dl2)) << desc;
ASSERT_EQ(dl1->rtree().get(), nullptr) << desc;
ASSERT_NE(dl2->rtree().get(), nullptr) << desc;
}
}
}
TEST_F(DisplayListTest, FullRotationsAreNop) {
DisplayListBuilder builder;
builder.Rotate(0);
builder.Rotate(360);
builder.Rotate(720);
builder.Rotate(1080);
builder.Rotate(1440);
sk_sp<DisplayList> dl = builder.Build();
ASSERT_EQ(dl->bytes(false), sizeof(DisplayList));
ASSERT_EQ(dl->bytes(true), sizeof(DisplayList));
ASSERT_EQ(dl->op_count(false), 0u);
ASSERT_EQ(dl->op_count(true), 0u);
EXPECT_EQ(dl->total_depth(), 0u);
}
TEST_F(DisplayListTest, AllBlendModeNops) {
DisplayListBuilder builder;
DlOpReceiver& receiver = ToReceiver(builder);
receiver.setBlendMode(DlBlendMode::kSrcOver);
sk_sp<DisplayList> dl = builder.Build();
ASSERT_EQ(dl->bytes(false), sizeof(DisplayList));
ASSERT_EQ(dl->bytes(true), sizeof(DisplayList));
ASSERT_EQ(dl->op_count(false), 0u);
ASSERT_EQ(dl->op_count(true), 0u);
EXPECT_EQ(dl->total_depth(), 0u);
}
TEST_F(DisplayListTest, DisplayListsWithVaryingOpComparisons) {
sk_sp<DisplayList> default_dl = Build(allGroups.size(), 0);
ASSERT_TRUE(default_dl->Equals(*default_dl)) << "Default == itself";
for (size_t gi = 0; gi < allGroups.size(); gi++) {
DisplayListInvocationGroup& group = allGroups[gi];
sk_sp<DisplayList> missing_dl = Build(gi, group.variants.size());
auto desc = "[Group " + group.op_name + " omitted]";
ASSERT_TRUE(missing_dl->Equals(*missing_dl)) << desc << " == itself";
ASSERT_FALSE(missing_dl->Equals(*default_dl)) << desc << " != Default";
ASSERT_FALSE(default_dl->Equals(*missing_dl)) << "Default != " << desc;
for (size_t vi = 0; vi < group.variants.size(); vi++) {
auto desc = "[Group " + group.op_name + " variant " +
std::to_string(vi + 1) + "]";
sk_sp<DisplayList> variant_dl = Build(gi, vi);
ASSERT_TRUE(variant_dl->Equals(*variant_dl)) << desc << " == itself";
if (vi == 0) {
ASSERT_TRUE(variant_dl->Equals(*default_dl)) << desc << " == Default";
ASSERT_TRUE(default_dl->Equals(*variant_dl)) << "Default == " << desc;
} else {
ASSERT_FALSE(variant_dl->Equals(*default_dl)) << desc << " != Default";
ASSERT_FALSE(default_dl->Equals(*variant_dl)) << "Default != " << desc;
}
if (group.variants[vi].is_empty()) {
ASSERT_TRUE(variant_dl->Equals(*missing_dl)) << desc << " != omitted";
ASSERT_TRUE(missing_dl->Equals(*variant_dl)) << "omitted != " << desc;
} else {
ASSERT_FALSE(variant_dl->Equals(*missing_dl)) << desc << " != omitted";
ASSERT_FALSE(missing_dl->Equals(*variant_dl)) << "omitted != " << desc;
}
}
}
}
TEST_F(DisplayListTest, DisplayListSaveLayerBoundsWithAlphaFilter) {
SkRect build_bounds = SkRect::MakeLTRB(-100, -100, 200, 200);
SkRect save_bounds = SkRect::MakeWH(100, 100);
SkRect rect = SkRect::MakeLTRB(30, 30, 70, 70);
// clang-format off
const float color_matrix[] = {
0, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0,
};
// clang-format on
DlMatrixColorFilter base_color_filter(color_matrix);
// clang-format off
const float alpha_matrix[] = {
0, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 0, 1,
};
// clang-format on
DlMatrixColorFilter alpha_color_filter(alpha_matrix);
sk_sp<SkColorFilter> sk_alpha_color_filter =
SkColorFilters::Matrix(alpha_matrix);
{
// No tricky stuff, just verifying drawing a rect produces rect bounds
DisplayListBuilder builder(build_bounds);
builder.SaveLayer(&save_bounds, nullptr);
builder.DrawRect(rect, DlPaint());
builder.Restore();
sk_sp<DisplayList> display_list = builder.Build();
ASSERT_EQ(display_list->bounds(), rect);
}
{
// Now checking that a normal color filter still produces rect bounds
DisplayListBuilder builder(build_bounds);
DlPaint save_paint;
save_paint.setColorFilter(&base_color_filter);
builder.SaveLayer(&save_bounds, &save_paint);
builder.DrawRect(rect, DlPaint());
builder.Restore();
sk_sp<DisplayList> display_list = builder.Build();
ASSERT_EQ(display_list->bounds(), rect);
}
{
// Now checking how SkPictureRecorder deals with a color filter
// that modifies alpha channels (save layer bounds are meaningless
// under those circumstances)
SkPictureRecorder recorder;
SkRTreeFactory rtree_factory;
SkCanvas* canvas = recorder.beginRecording(build_bounds, &rtree_factory);
SkPaint p1;
p1.setColorFilter(sk_alpha_color_filter);
canvas->saveLayer(save_bounds, &p1);
SkPaint p2;
canvas->drawRect(rect, p2);
canvas->restore();
sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
ASSERT_EQ(picture->cullRect(), build_bounds);
}
{
// Now checking that DisplayList has the same behavior that we
// saw in the SkPictureRecorder example above - returning the
// cull rect of the DisplayListBuilder when it encounters a
// save layer that modifies an unbounded region
DisplayListBuilder builder(build_bounds);
DlPaint save_paint;