-
Notifications
You must be signed in to change notification settings - Fork 54
/
display_item.rs
1541 lines (1372 loc) · 51.7 KB
/
display_item.rs
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use euclid::SideOffsets2D;
use peek_poke::PeekPoke;
use std::ops::Not;
// local imports
use crate::font;
use crate::api::{PipelineId, PropertyBinding};
use crate::color::ColorF;
use crate::image::{ColorDepth, ImageKey};
use crate::units::*;
// ******************************************************************
// * NOTE: some of these structs have an "IMPLICIT" comment. *
// * This indicates that the BuiltDisplayList will have serialized *
// * a list of values nearby that this item consumes. The traversal *
// * iterator should handle finding these. DebugDisplayItem should *
// * make them explicit. *
// ******************************************************************
/// A tag that can be used to identify items during hit testing. If the tag
/// is missing then the item doesn't take part in hit testing at all. This
/// is composed of two numbers. In Servo, the first is an identifier while the
/// second is used to select the cursor that should be used during mouse
/// movement. In Gecko, the first is a scrollframe identifier, while the second
/// is used to store various flags that APZ needs to properly process input
/// events.
pub type ItemTag = (u64, u16);
/// An identifier used to refer to previously sent display items. Currently it
/// refers to individual display items, but this may change later.
pub type ItemKey = u16;
bitflags! {
#[repr(C)]
#[derive(Deserialize, MallocSizeOf, Serialize, PeekPoke)]
pub struct PrimitiveFlags: u8 {
/// The CSS backface-visibility property (yes, it can be really granular)
const IS_BACKFACE_VISIBLE = 1 << 0;
/// If set, this primitive represents a scroll bar container
const IS_SCROLLBAR_CONTAINER = 1 << 1;
/// If set, this primitive represents a scroll bar thumb
const IS_SCROLLBAR_THUMB = 1 << 2;
/// This is used as a performance hint - this primitive may be promoted to a native
/// compositor surface under certain (implementation specific) conditions. This
/// is typically used for large videos, and canvas elements.
const PREFER_COMPOSITOR_SURFACE = 1 << 3;
}
}
impl Default for PrimitiveFlags {
fn default() -> Self {
PrimitiveFlags::IS_BACKFACE_VISIBLE
}
}
/// A grouping of fields a lot of display items need, just to avoid
/// repeating these over and over in this file.
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct CommonItemProperties {
/// Bounds of the display item to clip to. Many items are logically
/// infinite, and rely on this clip_rect to define their bounds
/// (solid colors, background-images, gradients, etc).
pub clip_rect: LayoutRect,
/// Additional clips
pub clip_id: ClipId,
/// The coordinate-space the item is in (yes, it can be really granular)
pub spatial_id: SpatialId,
/// Opaque bits for our clients to use for hit-testing. This is the most
/// dubious "common" field, but because it's an Option, it usually only
/// wastes a single byte (for None).
pub hit_info: Option<ItemTag>,
/// Various flags describing properties of this primitive.
pub flags: PrimitiveFlags,
}
impl CommonItemProperties {
/// Convenience for tests.
pub fn new(
clip_rect: LayoutRect,
space_and_clip: SpaceAndClipInfo,
) -> Self {
Self {
clip_rect,
spatial_id: space_and_clip.spatial_id,
clip_id: space_and_clip.clip_id,
hit_info: None,
flags: PrimitiveFlags::default(),
}
}
}
/// Per-primitive information about the nodes in the clip tree and
/// the spatial tree that the primitive belongs to.
///
/// Note: this is a separate struct from `PrimitiveInfo` because
/// it needs indirectional mapping during the DL flattening phase,
/// turning into `ScrollNodeAndClipChain`.
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct SpaceAndClipInfo {
pub spatial_id: SpatialId,
pub clip_id: ClipId,
}
impl SpaceAndClipInfo {
/// Create a new space/clip info associated with the root
/// scroll frame.
pub fn root_scroll(pipeline_id: PipelineId) -> Self {
SpaceAndClipInfo {
spatial_id: SpatialId::root_scroll_node(pipeline_id),
clip_id: ClipId::root(pipeline_id),
}
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
pub enum DisplayItem {
// These are the "real content" display items
Rectangle(RectangleDisplayItem),
ClearRectangle(ClearRectangleDisplayItem),
HitTest(HitTestDisplayItem),
Text(TextDisplayItem),
Line(LineDisplayItem),
Border(BorderDisplayItem),
BoxShadow(BoxShadowDisplayItem),
PushShadow(PushShadowDisplayItem),
Gradient(GradientDisplayItem),
RadialGradient(RadialGradientDisplayItem),
ConicGradient(ConicGradientDisplayItem),
Image(ImageDisplayItem),
RepeatingImage(RepeatingImageDisplayItem),
YuvImage(YuvImageDisplayItem),
BackdropFilter(BackdropFilterDisplayItem),
// Clips
Clip(ClipDisplayItem),
ClipChain(ClipChainItem),
// Spaces and Frames that content can be scoped under.
ScrollFrame(ScrollFrameDisplayItem),
StickyFrame(StickyFrameDisplayItem),
Iframe(IframeDisplayItem),
PushReferenceFrame(ReferenceFrameDisplayListItem),
PushStackingContext(PushStackingContextDisplayItem),
// These marker items indicate an array of data follows, to be used for the
// next non-marker item.
SetGradientStops,
SetFilterOps,
SetFilterData,
SetFilterPrimitives,
// These marker items terminate a scope introduced by a previous item.
PopReferenceFrame,
PopStackingContext,
PopAllShadows,
ReuseItems(ItemKey),
RetainedItems(ItemKey),
}
/// This is a "complete" version of the DisplayItem, with all implicit trailing
/// arrays included, for debug serialization (captures).
#[cfg(any(feature = "serialize", feature = "deserialize"))]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "deserialize", derive(Deserialize))]
pub enum DebugDisplayItem {
Rectangle(RectangleDisplayItem),
ClearRectangle(ClearRectangleDisplayItem),
HitTest(HitTestDisplayItem),
Text(TextDisplayItem, Vec<font::GlyphInstance>),
Line(LineDisplayItem),
Border(BorderDisplayItem),
BoxShadow(BoxShadowDisplayItem),
PushShadow(PushShadowDisplayItem),
Gradient(GradientDisplayItem),
RadialGradient(RadialGradientDisplayItem),
ConicGradient(ConicGradientDisplayItem),
Image(ImageDisplayItem),
RepeatingImage(RepeatingImageDisplayItem),
YuvImage(YuvImageDisplayItem),
BackdropFilter(BackdropFilterDisplayItem),
Clip(ClipDisplayItem, Vec<ComplexClipRegion>),
ClipChain(ClipChainItem, Vec<ClipId>),
ScrollFrame(ScrollFrameDisplayItem, Vec<ComplexClipRegion>),
StickyFrame(StickyFrameDisplayItem),
Iframe(IframeDisplayItem),
PushReferenceFrame(ReferenceFrameDisplayListItem),
PushStackingContext(PushStackingContextDisplayItem),
SetGradientStops(Vec<GradientStop>),
SetFilterOps(Vec<FilterOp>),
SetFilterData(FilterData),
SetFilterPrimitives(Vec<FilterPrimitive>),
PopReferenceFrame,
PopStackingContext,
PopAllShadows,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ClipDisplayItem {
pub id: ClipId,
pub parent_space_and_clip: SpaceAndClipInfo,
pub clip_rect: LayoutRect,
pub image_mask: Option<ImageMask>,
} // IMPLICIT: complex_clips: Vec<ComplexClipRegion>
/// The minimum and maximum allowable offset for a sticky frame in a single dimension.
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct StickyOffsetBounds {
/// The minimum offset for this frame, typically a negative value, which specifies how
/// far in the negative direction the sticky frame can offset its contents in this
/// dimension.
pub min: f32,
/// The maximum offset for this frame, typically a positive value, which specifies how
/// far in the positive direction the sticky frame can offset its contents in this
/// dimension.
pub max: f32,
}
impl StickyOffsetBounds {
pub fn new(min: f32, max: f32) -> StickyOffsetBounds {
StickyOffsetBounds { min, max }
}
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct StickyFrameDisplayItem {
pub id: SpatialId,
pub parent_spatial_id: SpatialId,
pub bounds: LayoutRect,
/// The margins that should be maintained between the edge of the parent viewport and this
/// sticky frame. A margin of None indicates that the sticky frame should not stick at all
/// to that particular edge of the viewport.
pub margins: SideOffsets2D<Option<f32>, LayoutPixel>,
/// The minimum and maximum vertical offsets for this sticky frame. Ignoring these constraints,
/// the sticky frame will continue to stick to the edge of the viewport as its original
/// position is scrolled out of view. Constraints specify a maximum and minimum offset from the
/// original position relative to non-sticky content within the same scrolling frame.
pub vertical_offset_bounds: StickyOffsetBounds,
/// The minimum and maximum horizontal offsets for this sticky frame. Ignoring these constraints,
/// the sticky frame will continue to stick to the edge of the viewport as its original
/// position is scrolled out of view. Constraints specify a maximum and minimum offset from the
/// original position relative to non-sticky content within the same scrolling frame.
pub horizontal_offset_bounds: StickyOffsetBounds,
/// The amount of offset that has already been applied to the sticky frame. A positive y
/// component this field means that a top-sticky item was in a scrollframe that has been
/// scrolled down, such that the sticky item's position needed to be offset downwards by
/// `previously_applied_offset.y`. A negative y component corresponds to the upward offset
/// applied due to bottom-stickiness. The x-axis works analogously.
pub previously_applied_offset: LayoutVector2D,
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
pub enum ScrollSensitivity {
ScriptAndInputEvents,
Script,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ScrollFrameDisplayItem {
/// The id of the clip this scroll frame creates
pub clip_id: ClipId,
/// The id of the space this scroll frame creates
pub scroll_frame_id: SpatialId,
/// The size of the contents this contains (so the backend knows how far it can scroll).
// FIXME: this can *probably* just be a size? Origin seems to just get thrown out.
pub content_rect: LayoutRect,
pub clip_rect: LayoutRect,
pub parent_space_and_clip: SpaceAndClipInfo,
pub external_id: Option<ExternalScrollId>,
pub image_mask: Option<ImageMask>,
pub scroll_sensitivity: ScrollSensitivity,
/// The amount this scrollframe has already been scrolled by, in the caller.
/// This means that all the display items that are inside the scrollframe
/// will have their coordinates shifted by this amount, and this offset
/// should be added to those display item coordinates in order to get a
/// normalized value that is consistent across display lists.
pub external_scroll_offset: LayoutVector2D,
}
/// A solid or an animating color to draw (may not actually be a rectangle due to complex clips)
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct RectangleDisplayItem {
pub common: CommonItemProperties,
pub bounds: LayoutRect,
pub color: PropertyBinding<ColorF>,
}
/// Clears all colors from the area, making it possible to cut holes in the window.
/// (useful for things like the macos frosted-glass effect).
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ClearRectangleDisplayItem {
pub common: CommonItemProperties,
pub bounds: LayoutRect,
}
/// A minimal hit-testable item for the parent browser's convenience, and is
/// slimmer than a RectangleDisplayItem (no color). The existence of this as a
/// distinct item also makes it easier to inspect/debug display items.
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct HitTestDisplayItem {
pub common: CommonItemProperties,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct LineDisplayItem {
pub common: CommonItemProperties,
/// We need a separate rect from common.clip_rect to encode cute
/// tricks that firefox does to make a series of text-decorations seamlessly
/// line up -- snapping the decorations to a multiple of their period, and
/// then clipping them to their "proper" area. This rect is that "logical"
/// snapped area that may be clipped to the right size by the clip_rect.
pub area: LayoutRect,
/// Whether the rect is interpretted as vertical or horizontal
pub orientation: LineOrientation,
/// This could potentially be implied from area, but we currently prefer
/// that this is the responsibility of the layout engine. Value irrelevant
/// for non-wavy lines.
// FIXME: this was done before we could use tagged unions in enums, but now
// it should just be part of LineStyle::Wavy.
pub wavy_line_thickness: f32,
pub color: ColorF,
pub style: LineStyle,
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, Eq, Hash, PeekPoke)]
pub enum LineOrientation {
Vertical,
Horizontal,
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, Eq, Hash, PeekPoke)]
pub enum LineStyle {
Solid,
Dotted,
Dashed,
Wavy,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct TextDisplayItem {
pub common: CommonItemProperties,
/// The area all the glyphs should be found in. Strictly speaking this isn't
/// necessarily needed, but layout engines should already "know" this, and we
/// use it cull and size things quickly before glyph layout is done. Currently
/// the glyphs *can* be outside these bounds, but that should imply they
/// can be cut off.
// FIXME: these are currently sometimes ignored to keep some old wrench tests
// working, but we should really just fix the tests!
pub bounds: LayoutRect,
pub font_key: font::FontInstanceKey,
pub color: ColorF,
pub glyph_options: Option<font::GlyphOptions>,
} // IMPLICIT: glyphs: Vec<font::GlyphInstance>
#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub struct NormalBorder {
pub left: BorderSide,
pub right: BorderSide,
pub top: BorderSide,
pub bottom: BorderSide,
pub radius: BorderRadius,
/// Whether to apply anti-aliasing on the border corners.
///
/// Note that for this to be `false` and work, this requires the borders to
/// be solid, and no border-radius.
pub do_aa: bool,
}
impl NormalBorder {
fn can_disable_antialiasing(&self) -> bool {
fn is_valid(style: BorderStyle) -> bool {
style == BorderStyle::Solid || style == BorderStyle::None
}
self.radius.is_zero() &&
is_valid(self.top.style) &&
is_valid(self.left.style) &&
is_valid(self.bottom.style) &&
is_valid(self.right.style)
}
/// Normalizes a border so that we don't render disallowed stuff, like inset
/// borders that are less than two pixels wide.
#[inline]
pub fn normalize(&mut self, widths: &LayoutSideOffsets) {
debug_assert!(
self.do_aa || self.can_disable_antialiasing(),
"Unexpected disabled-antialiasing in a border, likely won't work or will be ignored"
);
#[inline]
fn renders_small_border_solid(style: BorderStyle) -> bool {
match style {
BorderStyle::Groove |
BorderStyle::Ridge => true,
_ => false,
}
}
let normalize_side = |side: &mut BorderSide, width: f32| {
if renders_small_border_solid(side.style) && width < 2. {
side.style = BorderStyle::Solid;
}
};
normalize_side(&mut self.left, widths.left);
normalize_side(&mut self.right, widths.right);
normalize_side(&mut self.top, widths.top);
normalize_side(&mut self.bottom, widths.bottom);
}
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, MallocSizeOf, PartialEq, Serialize, Deserialize, Eq, Hash, PeekPoke)]
pub enum RepeatMode {
Stretch,
Repeat,
Round,
Space,
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
pub enum NinePatchBorderSource {
Image(ImageKey),
Gradient(Gradient),
RadialGradient(RadialGradient),
ConicGradient(ConicGradient),
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct NinePatchBorder {
/// Describes what to use as the 9-patch source image. If this is an image,
/// it will be stretched to fill the size given by width x height.
pub source: NinePatchBorderSource,
/// The width of the 9-part image.
pub width: i32,
/// The height of the 9-part image.
pub height: i32,
/// Distances from each edge where the image should be sliced up. These
/// values are in 9-part-image space (the same space as width and height),
/// and the resulting image parts will be used to fill the corresponding
/// parts of the border as given by the border widths. This can lead to
/// stretching.
/// Slices can be overlapping. In that case, the same pixels from the
/// 9-part image will show up in multiple parts of the resulting border.
pub slice: DeviceIntSideOffsets,
/// Controls whether the center of the 9 patch image is rendered or
/// ignored. The center is never rendered if the slices are overlapping.
pub fill: bool,
/// Determines what happens if the horizontal side parts of the 9-part
/// image have a different size than the horizontal parts of the border.
pub repeat_horizontal: RepeatMode,
/// Determines what happens if the vertical side parts of the 9-part
/// image have a different size than the vertical parts of the border.
pub repeat_vertical: RepeatMode,
/// The outset for the border.
/// TODO(mrobinson): This should be removed and handled by the client.
pub outset: LayoutSideOffsets, // TODO: what unit is this in?
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
pub enum BorderDetails {
Normal(NormalBorder),
NinePatch(NinePatchBorder),
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct BorderDisplayItem {
pub common: CommonItemProperties,
pub bounds: LayoutRect,
pub widths: LayoutSideOffsets,
pub details: BorderDetails,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
pub enum BorderRadiusKind {
Uniform,
NonUniform,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub struct BorderRadius {
pub top_left: LayoutSize,
pub top_right: LayoutSize,
pub bottom_left: LayoutSize,
pub bottom_right: LayoutSize,
}
impl Default for BorderRadius {
fn default() -> Self {
BorderRadius {
top_left: LayoutSize::zero(),
top_right: LayoutSize::zero(),
bottom_left: LayoutSize::zero(),
bottom_right: LayoutSize::zero(),
}
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub struct BorderSide {
pub color: ColorF,
pub style: BorderStyle,
}
#[repr(u32)]
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, Hash, Eq, PeekPoke)]
pub enum BorderStyle {
None = 0,
Solid = 1,
Double = 2,
Dotted = 3,
Dashed = 4,
Hidden = 5,
Groove = 6,
Ridge = 7,
Inset = 8,
Outset = 9,
}
impl BorderStyle {
pub fn is_hidden(self) -> bool {
self == BorderStyle::Hidden || self == BorderStyle::None
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub enum BoxShadowClipMode {
Outset = 0,
Inset = 1,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct BoxShadowDisplayItem {
pub common: CommonItemProperties,
pub box_bounds: LayoutRect,
pub offset: LayoutVector2D,
pub color: ColorF,
pub blur_radius: f32,
pub spread_radius: f32,
pub border_radius: BorderRadius,
pub clip_mode: BoxShadowClipMode,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct PushShadowDisplayItem {
pub space_and_clip: SpaceAndClipInfo,
pub shadow: Shadow,
pub should_inflate: bool,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct Shadow {
pub offset: LayoutVector2D,
pub color: ColorF,
pub blur_radius: f32,
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, Hash, Eq, MallocSizeOf, PartialEq, Serialize, Deserialize, Ord, PartialOrd, PeekPoke)]
pub enum ExtendMode {
Clamp,
Repeat,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct Gradient {
pub start_point: LayoutPoint,
pub end_point: LayoutPoint,
pub extend_mode: ExtendMode,
} // IMPLICIT: stops: Vec<GradientStop>
/// The area
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct GradientDisplayItem {
/// NOTE: common.clip_rect is the area the gradient covers
pub common: CommonItemProperties,
/// The area to tile the gradient over (first tile starts at origin of this rect)
// FIXME: this should ideally just be `tile_origin` here, with the clip_rect
// defining the bounds of the item. Needs non-trivial backend changes.
pub bounds: LayoutRect,
/// How big a tile of the of the gradient should be (common case: bounds.size)
pub tile_size: LayoutSize,
/// The space between tiles of the gradient (common case: 0)
pub tile_spacing: LayoutSize,
pub gradient: Gradient,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub struct GradientStop {
pub offset: f32,
pub color: ColorF,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct RadialGradient {
pub center: LayoutPoint,
pub radius: LayoutSize,
pub start_offset: f32,
pub end_offset: f32,
pub extend_mode: ExtendMode,
} // IMPLICIT stops: Vec<GradientStop>
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ConicGradient {
pub center: LayoutPoint,
pub angle: f32,
pub start_offset: f32,
pub end_offset: f32,
pub extend_mode: ExtendMode,
} // IMPLICIT stops: Vec<GradientStop>
/// Just an abstraction for bundling up a bunch of clips into a "super clip".
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ClipChainItem {
pub id: ClipChainId,
pub parent: Option<ClipChainId>,
} // IMPLICIT clip_ids: Vec<ClipId>
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct RadialGradientDisplayItem {
pub common: CommonItemProperties,
/// The area to tile the gradient over (first tile starts at origin of this rect)
// FIXME: this should ideally just be `tile_origin` here, with the clip_rect
// defining the bounds of the item. Needs non-trivial backend changes.
pub bounds: LayoutRect,
pub gradient: RadialGradient,
pub tile_size: LayoutSize,
pub tile_spacing: LayoutSize,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ConicGradientDisplayItem {
pub common: CommonItemProperties,
/// The area to tile the gradient over (first tile starts at origin of this rect)
// FIXME: this should ideally just be `tile_origin` here, with the clip_rect
// defining the bounds of the item. Needs non-trivial backend changes.
pub bounds: LayoutRect,
pub gradient: ConicGradient,
pub tile_size: LayoutSize,
pub tile_spacing: LayoutSize,
}
/// Renders a filtered region of its backdrop
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct BackdropFilterDisplayItem {
pub common: CommonItemProperties,
}
// IMPLICIT: filters: Vec<FilterOp>, filter_datas: Vec<FilterData>, filter_primitives: Vec<FilterPrimitive>
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ReferenceFrameDisplayListItem {
pub origin: LayoutPoint,
pub parent_spatial_id: SpatialId,
pub reference_frame: ReferenceFrame,
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
pub enum ReferenceFrameKind {
Transform,
Perspective {
scrolling_relative_to: Option<ExternalScrollId>,
}
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ReferenceFrame {
pub kind: ReferenceFrameKind,
pub transform_style: TransformStyle,
/// The transform matrix, either the perspective matrix or the transform
/// matrix.
pub transform: PropertyBinding<LayoutTransform>,
pub id: SpatialId,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct PushStackingContextDisplayItem {
pub origin: LayoutPoint,
pub spatial_id: SpatialId,
pub prim_flags: PrimitiveFlags,
pub stacking_context: StackingContext,
}
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct StackingContext {
pub transform_style: TransformStyle,
pub mix_blend_mode: MixBlendMode,
pub clip_id: Option<ClipId>,
pub raster_space: RasterSpace,
/// True if picture caching should be used on this stacking context.
pub cache_tiles: bool,
/// True if this stacking context is a backdrop root.
pub is_backdrop_root: bool,
}
// IMPLICIT: filters: Vec<FilterOp>, filter_datas: Vec<FilterData>, filter_primitives: Vec<FilterPrimitive>
#[repr(u8)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, PeekPoke)]
pub enum TransformStyle {
Flat = 0,
Preserve3D = 1,
}
/// Configure whether the contents of a stacking context
/// should be rasterized in local space or screen space.
/// Local space rasterized pictures are typically used
/// when we want to cache the output, and performance is
/// important. Note that this is a performance hint only,
/// which WR may choose to ignore.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
#[repr(u8)]
pub enum RasterSpace {
// Rasterize in local-space, applying supplied scale to primitives.
// Best performance, but lower quality.
Local(f32),
// Rasterize the picture in screen-space, including rotation / skew etc in
// the rasterized element. Best quality, but slower performance. Note that
// any stacking context with a perspective transform will be rasterized
// in local-space, even if this is set.
Screen,
}
impl RasterSpace {
pub fn local_scale(self) -> Option<f32> {
match self {
RasterSpace::Local(scale) => Some(scale),
RasterSpace::Screen => None,
}
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub enum MixBlendMode {
Normal = 0,
Multiply = 1,
Screen = 2,
Overlay = 3,
Darken = 4,
Lighten = 5,
ColorDodge = 6,
ColorBurn = 7,
HardLight = 8,
SoftLight = 9,
Difference = 10,
Exclusion = 11,
Hue = 12,
Saturation = 13,
Color = 14,
Luminosity = 15,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub enum ColorSpace {
Srgb,
LinearRgb,
}
/// Available composite operoations for the composite filter primitive
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub enum CompositeOperator {
Over,
In,
Atop,
Out,
Xor,
Lighter,
Arithmetic([f32; 4]),
}
impl CompositeOperator {
// This must stay in sync with the composite operator defines in cs_svg_filter.glsl
pub fn as_int(&self) -> u32 {
match self {
CompositeOperator::Over => 0,
CompositeOperator::In => 1,
CompositeOperator::Out => 2,
CompositeOperator::Atop => 3,
CompositeOperator::Xor => 4,
CompositeOperator::Lighter => 5,
CompositeOperator::Arithmetic(..) => 6,
}
}
}
/// An input to a SVG filter primitive.
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, MallocSizeOf, PartialEq, Serialize, PeekPoke)]
pub enum FilterPrimitiveInput {
/// The input is the original graphic that the filter is being applied to.
Original,
/// The input is the output of the previous filter primitive in the filter primitive chain.
Previous,
/// The input is the output of the filter primitive at the given index in the filter primitive chain.
OutputOfPrimitiveIndex(usize),
}
impl FilterPrimitiveInput {
/// Gets the index of the input.
/// Returns `None` if the source graphic is the input.
pub fn to_index(self, cur_index: usize) -> Option<usize> {
match self {
FilterPrimitiveInput::Previous if cur_index > 0 => Some(cur_index - 1),
FilterPrimitiveInput::OutputOfPrimitiveIndex(index) => Some(index),
_ => None,
}
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct BlendPrimitive {
pub input1: FilterPrimitiveInput,
pub input2: FilterPrimitiveInput,
pub mode: MixBlendMode,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct FloodPrimitive {
pub color: ColorF,
}
impl FloodPrimitive {
pub fn sanitize(&mut self) {
self.color.r = self.color.r.min(1.0).max(0.0);
self.color.g = self.color.g.min(1.0).max(0.0);
self.color.b = self.color.b.min(1.0).max(0.0);
self.color.a = self.color.a.min(1.0).max(0.0);
}
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct BlurPrimitive {
pub input: FilterPrimitiveInput,
pub radius: f32,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct OpacityPrimitive {
pub input: FilterPrimitiveInput,
pub opacity: f32,
}
impl OpacityPrimitive {
pub fn sanitize(&mut self) {
self.opacity = self.opacity.min(1.0).max(0.0);
}
}
/// cbindgen:derive-eq=false
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ColorMatrixPrimitive {
pub input: FilterPrimitiveInput,
pub matrix: [f32; 20],
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct DropShadowPrimitive {
pub input: FilterPrimitiveInput,
pub shadow: Shadow,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct ComponentTransferPrimitive {
pub input: FilterPrimitiveInput,
// Component transfer data is stored in FilterData.
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct IdentityPrimitive {
pub input: FilterPrimitiveInput,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct OffsetPrimitive {
pub input: FilterPrimitiveInput,
pub offset: LayoutVector2D,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct CompositePrimitive {
pub input1: FilterPrimitiveInput,
pub input2: FilterPrimitiveInput,
pub operator: CompositeOperator,
}
/// See: https://github.com/eqrion/cbindgen/issues/9
/// cbindgen:derive-eq=false
#[repr(C)]
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize, PeekPoke)]
pub enum FilterPrimitiveKind {
Identity(IdentityPrimitive),
Blend(BlendPrimitive),
Flood(FloodPrimitive),
Blur(BlurPrimitive),
// TODO: Support animated opacity?
Opacity(OpacityPrimitive),
/// cbindgen:derive-eq=false
ColorMatrix(ColorMatrixPrimitive),
DropShadow(DropShadowPrimitive),
ComponentTransfer(ComponentTransferPrimitive),
Offset(OffsetPrimitive),
Composite(CompositePrimitive),
}
impl Default for FilterPrimitiveKind {
fn default() -> Self {
FilterPrimitiveKind::Identity(IdentityPrimitive::default())
}
}
impl FilterPrimitiveKind {
pub fn sanitize(&mut self) {
match self {
FilterPrimitiveKind::Flood(flood) => flood.sanitize(),
FilterPrimitiveKind::Opacity(opacity) => opacity.sanitize(),
// No sanitization needed.
FilterPrimitiveKind::Identity(..) |
FilterPrimitiveKind::Blend(..) |
FilterPrimitiveKind::ColorMatrix(..) |
FilterPrimitiveKind::Offset(..) |
FilterPrimitiveKind::Composite(..) |
FilterPrimitiveKind::Blur(..) |
FilterPrimitiveKind::DropShadow(..) |
// Component transfer's filter data is sanitized separately.
FilterPrimitiveKind::ComponentTransfer(..) => {}
}
}
}
/// SVG Filter Primitive.
/// See: https://github.com/eqrion/cbindgen/issues/9
/// cbindgen:derive-eq=false
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, PeekPoke)]
pub struct FilterPrimitive {
pub kind: FilterPrimitiveKind,
pub color_space: ColorSpace,
}
impl FilterPrimitive {
pub fn sanitize(&mut self) {
self.kind.sanitize();
}
}
/// CSS filter.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Deserialize, Serialize, PeekPoke)]
pub enum FilterOp {
/// Filter that does no transformation of the colors, needed for
/// debug purposes only.
Identity,
Blur(f32),
Brightness(f32),
Contrast(f32),
Grayscale(f32),
HueRotate(f32),