@@ -39,7 +39,7 @@ use webrender_traits::{BoxShadowClipMode, PipelineId, ScrollLayerId, WebGLContex
39
39
const FLOATS_PER_RENDER_TASK_INFO : usize = 8 ;
40
40
41
41
trait AlphaBatchHelpers {
42
- fn get_batch_info ( & self , metadata : & PrimitiveMetadata ) -> ( AlphaBatchKind , TextureId , TextureId ) ;
42
+ fn get_batch_kind ( & self , metadata : & PrimitiveMetadata ) -> AlphaBatchKind ;
43
43
fn prim_affects_tile ( & self ,
44
44
prim_index : PrimitiveIndex ,
45
45
tile_rect : & DeviceRect ,
@@ -50,14 +50,12 @@ trait AlphaBatchHelpers {
50
50
batch : & mut PrimitiveBatch ,
51
51
layer_index : StackingContextIndex ,
52
52
task_id : i32 ,
53
- transform_kind : TransformedRectKind ,
54
- needs_blending : bool ,
55
53
render_tasks : & RenderTaskCollection ,
56
54
pass_index : RenderPassIndex ) ;
57
55
}
58
56
59
57
impl AlphaBatchHelpers for PrimitiveStore {
60
- fn get_batch_info ( & self , metadata : & PrimitiveMetadata ) -> ( AlphaBatchKind , TextureId , TextureId ) {
58
+ fn get_batch_kind ( & self , metadata : & PrimitiveMetadata ) -> AlphaBatchKind {
61
59
let batch_kind = match metadata. prim_kind {
62
60
PrimitiveKind :: Border => AlphaBatchKind :: Border ,
63
61
PrimitiveKind :: BoxShadow => AlphaBatchKind :: BoxShadow ,
@@ -77,7 +75,7 @@ impl AlphaBatchHelpers for PrimitiveStore {
77
75
}
78
76
} ;
79
77
80
- ( batch_kind, metadata . color_texture_id , metadata . mask_texture_id )
78
+ batch_kind
81
79
}
82
80
83
81
// Optional narrow phase intersection test, depending on primitive type.
@@ -111,13 +109,8 @@ impl AlphaBatchHelpers for PrimitiveStore {
111
109
batch : & mut PrimitiveBatch ,
112
110
layer_index : StackingContextIndex ,
113
111
task_id : i32 ,
114
- transform_kind : TransformedRectKind ,
115
- needs_blending : bool ,
116
112
render_tasks : & RenderTaskCollection ,
117
113
child_pass_index : RenderPassIndex ) {
118
- debug_assert ! ( transform_kind == batch. transform_kind) ;
119
- debug_assert ! ( needs_blending == batch. blending_enabled) ;
120
-
121
114
let metadata = self . get_metadata ( prim_index) ;
122
115
let layer_index = layer_index. 0 as i32 ;
123
116
let global_prim_id = prim_index. 0 as i32 ;
@@ -370,7 +363,7 @@ impl AlphaBatcher {
370
363
ctx : & RenderTargetContext ,
371
364
render_tasks : & RenderTaskCollection ,
372
365
child_pass_index : RenderPassIndex ) {
373
- let mut batches: Vec < ( AlphaBatchKey , PrimitiveBatch ) > = vec ! [ ] ;
366
+ let mut batches: Vec < PrimitiveBatch > = vec ! [ ] ;
374
367
for task in & mut self . tasks {
375
368
let task_index = render_tasks. get_static_task_index ( & task. task_id ) ;
376
369
let task_index = task_index. 0 as i32 ;
@@ -397,17 +390,16 @@ impl AlphaBatcher {
397
390
let flags = AlphaBatchKeyFlags :: new ( transform_kind,
398
391
needs_blending,
399
392
needs_clipping) ;
400
- let ( batch_kind, color_texture_id, mask_texture_id) = ctx. prim_store
401
- . get_batch_info ( prim_metadata) ;
393
+ let batch_kind = ctx. prim_store . get_batch_kind ( prim_metadata) ;
402
394
batch_key = AlphaBatchKey :: primitive ( batch_kind,
403
395
flags,
404
- color_texture_id,
405
- mask_texture_id) ;
396
+ prim_metadata . color_texture_id ,
397
+ prim_metadata . mask_texture_id ) ;
406
398
}
407
399
}
408
400
409
401
while existing_batch_index < batches. len ( ) &&
410
- !batches[ existing_batch_index] . 0 . is_compatible_with ( & batch_key) {
402
+ !batches[ existing_batch_index] . key . is_compatible_with ( & batch_key) {
411
403
existing_batch_index += 1
412
404
}
413
405
@@ -422,20 +414,14 @@ impl AlphaBatcher {
422
414
AlphaRenderItem :: Primitive ( _, prim_index) => {
423
415
// See if this task fits into the tile UBO
424
416
let prim_metadata = ctx. prim_store . get_metadata ( prim_index) ;
425
- let ( batch_kind, color_texture_id, mask_texture_id) = ctx. prim_store
426
- . get_batch_info ( prim_metadata) ;
427
- PrimitiveBatch :: new ( batch_kind,
428
- batch_key. flags . transform_kind ( ) ,
429
- batch_key. flags . needs_blending ( ) ,
430
- batch_key. flags . needs_clipping ( ) ,
431
- color_texture_id,
432
- mask_texture_id)
417
+ let batch_kind = ctx. prim_store . get_batch_kind ( prim_metadata) ;
418
+ PrimitiveBatch :: new ( batch_kind, batch_key)
433
419
}
434
420
} ;
435
- batches. push ( ( batch_key , new_batch) )
421
+ batches. push ( new_batch)
436
422
}
437
423
438
- let batch = & mut batches[ existing_batch_index] . 1 ;
424
+ let batch = & mut batches[ existing_batch_index] ;
439
425
match item {
440
426
AlphaRenderItem :: Composite ( src0_id, src1_id, info) => {
441
427
let ok = batch. pack_composite ( render_tasks. get_static_task_index ( & src0_id) ,
@@ -455,16 +441,14 @@ impl AlphaBatcher {
455
441
batch,
456
442
sc_index,
457
443
task_index,
458
- batch_key. flags . transform_kind ( ) ,
459
- batch_key. flags . needs_blending ( ) ,
460
444
render_tasks,
461
445
child_pass_index) ;
462
446
}
463
447
}
464
448
}
465
449
}
466
450
467
- self . batches . extend ( batches. into_iter ( ) . map ( | ( _ , batch ) | batch ) )
451
+ self . batches . extend ( batches. into_iter ( ) )
468
452
}
469
453
}
470
454
@@ -818,18 +802,20 @@ enum AlphaBatchKind {
818
802
}
819
803
820
804
#[ derive( Copy , Clone , Debug ) ]
821
- struct AlphaBatchKey {
805
+ pub struct AlphaBatchKey {
822
806
kind : AlphaBatchKind ,
823
- flags : AlphaBatchKeyFlags ,
824
- color_texture_id : TextureId ,
825
- mask_texture_id : TextureId ,
807
+ pub flags : AlphaBatchKeyFlags ,
808
+ pub color_texture_id : TextureId ,
809
+ pub mask_texture_id : TextureId ,
826
810
}
827
811
828
812
impl AlphaBatchKey {
829
813
fn blend ( ) -> AlphaBatchKey {
830
814
AlphaBatchKey {
831
815
kind : AlphaBatchKind :: Blend ,
832
- flags : AlphaBatchKeyFlags ( 0 ) ,
816
+ flags : AlphaBatchKeyFlags :: new ( TransformedRectKind :: AxisAligned ,
817
+ true ,
818
+ false ) ,
833
819
color_texture_id : TextureId :: invalid ( ) ,
834
820
mask_texture_id : TextureId :: invalid ( ) ,
835
821
}
@@ -838,7 +824,9 @@ impl AlphaBatchKey {
838
824
fn composite ( ) -> AlphaBatchKey {
839
825
AlphaBatchKey {
840
826
kind : AlphaBatchKind :: Composite ,
841
- flags : AlphaBatchKeyFlags ( 0 ) ,
827
+ flags : AlphaBatchKeyFlags :: new ( TransformedRectKind :: AxisAligned ,
828
+ true ,
829
+ false ) ,
842
830
color_texture_id : TextureId :: invalid ( ) ,
843
831
mask_texture_id : TextureId :: invalid ( ) ,
844
832
}
@@ -870,7 +858,7 @@ impl AlphaBatchKey {
870
858
// FIXME(gw): Change these to use the bitflags!()
871
859
872
860
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
873
- struct AlphaBatchKeyFlags ( u8 ) ;
861
+ pub struct AlphaBatchKeyFlags ( u8 ) ;
874
862
875
863
impl AlphaBatchKeyFlags {
876
864
fn new ( transform_kind : TransformedRectKind ,
@@ -881,19 +869,19 @@ impl AlphaBatchKeyFlags {
881
869
( ( needs_blending as u8 ) << 0 ) )
882
870
}
883
871
884
- fn transform_kind ( & self ) -> TransformedRectKind {
872
+ pub fn transform_kind ( & self ) -> TransformedRectKind {
885
873
if ( ( self . 0 >> 1 ) & 1 ) == 0 {
886
874
TransformedRectKind :: AxisAligned
887
875
} else {
888
876
TransformedRectKind :: Complex
889
877
}
890
878
}
891
879
892
- fn needs_blending ( & self ) -> bool {
880
+ pub fn needs_blending ( & self ) -> bool {
893
881
( self . 0 & 1 ) != 0
894
882
}
895
883
896
- fn needs_clipping ( & self ) -> bool {
884
+ pub fn needs_clipping ( & self ) -> bool {
897
885
( self . 0 & 4 ) != 0
898
886
}
899
887
}
@@ -948,33 +936,21 @@ pub enum PrimitiveBatchData {
948
936
949
937
#[ derive( Debug ) ]
950
938
pub struct PrimitiveBatch {
951
- pub transform_kind : TransformedRectKind ,
952
- pub has_complex_clip : bool ,
953
- pub color_texture_id : TextureId , // TODO(gw): Expand to sampler array to handle all glyphs!
954
- pub mask_texture_id : TextureId ,
955
- pub blending_enabled : bool ,
939
+ pub key : AlphaBatchKey ,
956
940
pub data : PrimitiveBatchData ,
957
941
}
958
942
959
943
impl PrimitiveBatch {
960
944
fn blend ( ) -> PrimitiveBatch {
961
945
PrimitiveBatch {
962
- color_texture_id : TextureId :: invalid ( ) ,
963
- mask_texture_id : TextureId :: invalid ( ) ,
964
- transform_kind : TransformedRectKind :: AxisAligned ,
965
- has_complex_clip : false ,
966
- blending_enabled : true ,
946
+ key : AlphaBatchKey :: blend ( ) ,
967
947
data : PrimitiveBatchData :: Blend ( Vec :: new ( ) ) ,
968
948
}
969
949
}
970
950
971
951
fn composite ( ) -> PrimitiveBatch {
972
952
PrimitiveBatch {
973
- color_texture_id : TextureId :: invalid ( ) ,
974
- mask_texture_id : TextureId :: invalid ( ) ,
975
- transform_kind : TransformedRectKind :: AxisAligned ,
976
- has_complex_clip : false ,
977
- blending_enabled : true ,
953
+ key : AlphaBatchKey :: composite ( ) ,
978
954
data : PrimitiveBatchData :: Composite ( Vec :: new ( ) ) ,
979
955
}
980
956
}
@@ -1031,11 +1007,7 @@ impl PrimitiveBatch {
1031
1007
}
1032
1008
1033
1009
fn new ( batch_kind : AlphaBatchKind ,
1034
- transform_kind : TransformedRectKind ,
1035
- blending_enabled : bool ,
1036
- has_complex_clip : bool ,
1037
- color_texture_id : TextureId ,
1038
- mask_texture_id : TextureId ) -> PrimitiveBatch {
1010
+ key : AlphaBatchKey ) -> PrimitiveBatch {
1039
1011
let data = match batch_kind {
1040
1012
AlphaBatchKind :: Rectangle => PrimitiveBatchData :: Rectangles ( Vec :: new ( ) ) ,
1041
1013
AlphaBatchKind :: TextRun => PrimitiveBatchData :: TextRun ( Vec :: new ( ) ) ,
@@ -1048,11 +1020,7 @@ impl PrimitiveBatch {
1048
1020
} ;
1049
1021
1050
1022
PrimitiveBatch {
1051
- color_texture_id : color_texture_id,
1052
- mask_texture_id : mask_texture_id,
1053
- transform_kind : transform_kind,
1054
- blending_enabled : blending_enabled,
1055
- has_complex_clip : has_complex_clip,
1023
+ key : key,
1056
1024
data : data,
1057
1025
}
1058
1026
}
0 commit comments