@@ -16,6 +16,26 @@ use webrender_traits::{AuxiliaryLists, ColorF, ImageKey, ImageRendering};
16
16
use webrender_traits:: { FontRenderMode , WebGLContextId } ;
17
17
use webrender_traits:: { ClipRegion , FontKey , ItemRange , ComplexClipRegion , GlyphKey } ;
18
18
19
+ #[ derive( Clone ) ]
20
+ pub struct TexelRect {
21
+ uv0 : Point2D < f32 > ,
22
+ uv1 : Point2D < f32 > ,
23
+ }
24
+
25
+ pub struct DeferredResolve {
26
+ resource_address : GpuStoreAddress ,
27
+ source_texture : SourceTexture ,
28
+ }
29
+
30
+ impl Default for TexelRect {
31
+ fn default ( ) -> TexelRect {
32
+ TexelRect {
33
+ uv0 : Point2D :: zero ( ) ,
34
+ uv1 : Point2D :: zero ( ) ,
35
+ }
36
+ }
37
+ }
38
+
19
39
#[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
20
40
pub struct SpecificPrimitiveIndex ( pub usize ) ;
21
41
@@ -96,12 +116,11 @@ pub enum ImagePrimitiveKind {
96
116
pub struct ImagePrimitiveCpu {
97
117
pub kind : ImagePrimitiveKind ,
98
118
pub color_texture_id : SourceTexture ,
119
+ pub resource_address : GpuStoreAddress ,
99
120
}
100
121
101
122
#[ derive( Debug , Clone ) ]
102
123
pub struct ImagePrimitiveGpu {
103
- pub uv0 : Point2D < f32 > ,
104
- pub uv1 : Point2D < f32 > ,
105
124
pub stretch_size : Size2D < f32 > ,
106
125
pub tile_spacing : Size2D < f32 > ,
107
126
}
@@ -191,14 +210,13 @@ pub struct TextRunPrimitiveCpu {
191
210
pub color_texture_id : SourceTexture ,
192
211
pub color : ColorF ,
193
212
pub render_mode : FontRenderMode ,
213
+ pub resource_address : GpuStoreAddress ,
194
214
}
195
215
196
216
#[ derive( Debug , Clone ) ]
197
217
struct GlyphPrimitive {
198
218
offset : Point2D < f32 > ,
199
219
padding : Point2D < f32 > ,
200
- uv0 : Point2D < f32 > ,
201
- uv1 : Point2D < f32 > ,
202
220
}
203
221
204
222
#[ derive( Debug , Clone ) ]
@@ -353,6 +371,9 @@ pub struct PrimitiveStore {
353
371
pub gpu_data64 : GpuStore < GpuBlock64 > ,
354
372
pub gpu_data128 : GpuStore < GpuBlock128 > ,
355
373
374
+ // Resolved resource rects.
375
+ pub gpu_resource_rects : GpuStore < TexelRect > ,
376
+
356
377
// General
357
378
device_pixel_ratio : f32 ,
358
379
prims_to_resolve : Vec < PrimitiveIndex > ,
@@ -372,6 +393,7 @@ impl PrimitiveStore {
372
393
gpu_data32 : GpuStore :: new ( ) ,
373
394
gpu_data64 : GpuStore :: new ( ) ,
374
395
gpu_data128 : GpuStore :: new ( ) ,
396
+ gpu_resource_rects : GpuStore :: new ( ) ,
375
397
device_pixel_ratio : device_pixel_ratio,
376
398
prims_to_resolve : Vec :: new ( ) ,
377
399
}
@@ -425,9 +447,10 @@ impl PrimitiveStore {
425
447
426
448
metadata
427
449
}
428
- PrimitiveContainer :: TextRun ( text_cpu, text_gpu) => {
450
+ PrimitiveContainer :: TextRun ( mut text_cpu, text_gpu) => {
429
451
let gpu_address = self . gpu_data16 . push ( text_gpu) ;
430
- let gpu_glyphs_address = self . gpu_data32 . alloc ( text_cpu. glyph_range . length ) ;
452
+ let gpu_glyphs_address = self . gpu_data16 . alloc ( text_cpu. glyph_range . length ) ;
453
+ text_cpu. resource_address = self . gpu_resource_rects . alloc ( text_cpu. glyph_range . length ) ;
431
454
432
455
let metadata = PrimitiveMetadata {
433
456
is_opaque : false ,
@@ -445,8 +468,10 @@ impl PrimitiveStore {
445
468
self . cpu_text_runs . push ( text_cpu) ;
446
469
metadata
447
470
}
448
- PrimitiveContainer :: Image ( image_cpu, image_gpu) => {
449
- let gpu_address = self . gpu_data32 . push ( image_gpu) ;
471
+ PrimitiveContainer :: Image ( mut image_cpu, image_gpu) => {
472
+ image_cpu. resource_address = self . gpu_resource_rects . alloc ( 1 ) ;
473
+
474
+ let gpu_address = self . gpu_data16 . push ( image_gpu) ;
450
475
451
476
let metadata = PrimitiveMetadata {
452
477
is_opaque : false ,
@@ -564,12 +589,14 @@ impl PrimitiveStore {
564
589
PrimitiveIndex ( prim_index)
565
590
}
566
591
567
- pub fn resolve_primitives ( & mut self , resource_cache : & ResourceCache ) {
592
+ pub fn resolve_primitives ( & mut self , resource_cache : & ResourceCache ) -> Vec < DeferredResolve > {
593
+ let mut deferred_resolves = Vec :: new ( ) ;
594
+
568
595
for prim_index in self . prims_to_resolve . drain ( ..) {
569
596
let metadata = & mut self . cpu_metadata [ prim_index. 0 ] ;
570
597
571
598
if let & PrimitiveClipSource :: Region ( ClipRegion { image_mask : Some ( mask) , .. } ) = metadata. clip_source . as_ref ( ) {
572
- let tex_cache = resource_cache. get_image ( mask. image , ImageRendering :: Auto ) ;
599
+ let tex_cache = resource_cache. get_image ( mask. image , ImageRendering :: Auto ) . expect ( "masks shouldn't be external!" ) ;
573
600
metadata. mask_texture_id = tex_cache. texture_id ;
574
601
if let Some ( address) = metadata. clip_index {
575
602
let clip_data = self . gpu_data32 . get_slice_mut ( address, 6 ) ;
@@ -590,44 +617,56 @@ impl PrimitiveStore {
590
617
PrimitiveKind :: TextRun => {
591
618
let text = & mut self . cpu_text_runs [ metadata. cpu_prim_index . 0 ] ;
592
619
593
- let dest_glyphs = self . gpu_data32 . get_slice_mut ( metadata . gpu_data_address ,
594
- text. glyph_range . length ) ;
620
+ let dest_rects = self . gpu_resource_rects . get_slice_mut ( text . resource_address ,
621
+ text. glyph_range . length ) ;
595
622
596
623
let texture_id = resource_cache. get_glyphs ( text. font_key ,
597
624
text. font_size ,
598
625
& text. glyph_indices ,
599
626
text. render_mode , |index, uv0, uv1| {
600
- let dest_glyph = & mut dest_glyphs[ index] ;
601
- let dest: & mut GlyphPrimitive = unsafe {
602
- mem:: transmute ( dest_glyph)
603
- } ;
604
- dest. uv0 = uv0;
605
- dest. uv1 = uv1;
627
+ let dest_rect = & mut dest_rects[ index] ;
628
+ dest_rect. uv0 = uv0;
629
+ dest_rect. uv1 = uv1;
606
630
} ) ;
607
631
608
632
text. color_texture_id = texture_id;
609
633
}
610
634
PrimitiveKind :: Image => {
611
635
let image_cpu = & mut self . cpu_images [ metadata. cpu_prim_index . 0 ] ;
612
- let image_gpu: & mut ImagePrimitiveGpu = unsafe {
613
- mem:: transmute ( self . gpu_data32 . get_mut ( metadata. gpu_prim_index ) )
614
- } ;
615
636
616
- let cache_item = match image_cpu. kind {
637
+ match image_cpu. kind {
617
638
ImagePrimitiveKind :: Image ( image_key, image_rendering, _) => {
618
- resource_cache. get_image ( image_key, image_rendering)
639
+ match resource_cache. get_image ( image_key, image_rendering) {
640
+ Ok ( cache_item) => {
641
+ let resource_rect = self . gpu_resource_rects . get_mut ( image_cpu. resource_address ) ;
642
+ resource_rect. uv0 = cache_item. uv0 ;
643
+ resource_rect. uv1 = cache_item. uv1 ;
644
+ image_cpu. color_texture_id = cache_item. texture_id ;
645
+ }
646
+ Err ( source_texture) => {
647
+ // This is an external texture - we will add it to
648
+ // the deferred resolves list to be patched by
649
+ // the render thread...
650
+ deferred_resolves. push ( DeferredResolve {
651
+ resource_address : image_cpu. resource_address ,
652
+ source_texture : source_texture,
653
+ } ) ;
654
+ }
655
+ }
619
656
}
620
657
ImagePrimitiveKind :: WebGL ( context_id) => {
621
- resource_cache. get_webgl_texture ( & context_id)
658
+ let cache_item = resource_cache. get_webgl_texture ( & context_id) ;
659
+ let resource_rect = self . gpu_resource_rects . get_mut ( image_cpu. resource_address ) ;
660
+ resource_rect. uv0 = cache_item. uv0 ;
661
+ resource_rect. uv1 = cache_item. uv1 ;
662
+ image_cpu. color_texture_id = cache_item. texture_id ;
622
663
}
623
- } ;
624
-
625
- image_cpu. color_texture_id = cache_item. texture_id ;
626
- image_gpu. uv0 = cache_item. uv0 ;
627
- image_gpu. uv1 = cache_item. uv1 ;
664
+ }
628
665
}
629
666
}
630
667
}
668
+
669
+ deferred_resolves
631
670
}
632
671
633
672
pub fn get_bounding_rect ( & self , index : PrimitiveIndex ) -> & Option < DeviceRect > {
@@ -747,7 +786,7 @@ impl PrimitiveStore {
747
786
debug_assert ! ( metadata. gpu_data_count == text. glyph_range. length as i32 ) ;
748
787
debug_assert ! ( text. glyph_indices. is_empty( ) ) ;
749
788
let src_glyphs = auxiliary_lists. glyph_instances ( & text. glyph_range ) ;
750
- let dest_glyphs = self . gpu_data32 . get_slice_mut ( metadata. gpu_data_address ,
789
+ let dest_glyphs = self . gpu_data16 . get_slice_mut ( metadata. gpu_data_address ,
751
790
text. glyph_range . length ) ;
752
791
let mut glyph_key = GlyphKey :: new ( text. font_key ,
753
792
text. font_size ,
@@ -776,9 +815,7 @@ impl PrimitiveStore {
776
815
Size2D :: new ( width, height) ) ;
777
816
local_rect = local_rect. union ( & local_glyph_rect) ;
778
817
779
- dest_glyphs[ actual_glyph_count] = GpuBlock32 :: from ( GlyphPrimitive {
780
- uv0 : Point2D :: zero ( ) ,
781
- uv1 : Point2D :: zero ( ) ,
818
+ dest_glyphs[ actual_glyph_count] = GpuBlock16 :: from ( GlyphPrimitive {
782
819
padding : Point2D :: zero ( ) ,
783
820
offset : local_glyph_rect. origin ,
784
821
} ) ;
@@ -918,6 +955,22 @@ impl From<InstanceRect> for GpuBlock16 {
918
955
}
919
956
}
920
957
958
+ impl From < ImagePrimitiveGpu > for GpuBlock16 {
959
+ fn from ( data : ImagePrimitiveGpu ) -> GpuBlock16 {
960
+ unsafe {
961
+ mem:: transmute :: < ImagePrimitiveGpu , GpuBlock16 > ( data)
962
+ }
963
+ }
964
+ }
965
+
966
+ impl From < GlyphPrimitive > for GpuBlock16 {
967
+ fn from ( data : GlyphPrimitive ) -> GpuBlock16 {
968
+ unsafe {
969
+ mem:: transmute :: < GlyphPrimitive , GpuBlock16 > ( data)
970
+ }
971
+ }
972
+ }
973
+
921
974
#[ derive( Clone ) ]
922
975
pub struct GpuBlock32 {
923
976
data : [ f32 ; 8 ] ,
@@ -947,22 +1000,6 @@ impl From<GradientStop> for GpuBlock32 {
947
1000
}
948
1001
}
949
1002
950
- impl From < GlyphPrimitive > for GpuBlock32 {
951
- fn from ( data : GlyphPrimitive ) -> GpuBlock32 {
952
- unsafe {
953
- mem:: transmute :: < GlyphPrimitive , GpuBlock32 > ( data)
954
- }
955
- }
956
- }
957
-
958
- impl From < ImagePrimitiveGpu > for GpuBlock32 {
959
- fn from ( data : ImagePrimitiveGpu ) -> GpuBlock32 {
960
- unsafe {
961
- mem:: transmute :: < ImagePrimitiveGpu , GpuBlock32 > ( data)
962
- }
963
- }
964
- }
965
-
966
1003
impl From < ClipRect > for GpuBlock32 {
967
1004
fn from ( data : ClipRect ) -> GpuBlock32 {
968
1005
unsafe {
0 commit comments