@@ -549,6 +549,7 @@ struct MappedFontKey {
549
549
}
550
550
551
551
struct FontKeyMapLocked {
552
+ namespace : IdNamespace ,
552
553
next_id : u32 ,
553
554
template_map : FastHashMap < FontTemplate , Arc < MappedFontKey > > ,
554
555
key_map : FastHashMap < FontKey , Arc < MappedFontKey > > ,
@@ -561,15 +562,15 @@ struct FontKeyMapLocked {
561
562
/// final shared key. The shared key will stay alive so long as there are
562
563
/// any strong references to the mapping entry. Care must be taken when
563
564
/// clearing namespaces of shared keys as this may trigger shared font keys
564
- /// to expire which require individual processing.
565
+ /// to expire which require individual processing. Shared font keys will be
566
+ /// created within the provided unique namespace.
565
567
#[ derive( Clone ) ]
566
568
pub struct FontKeyMap ( Arc < RwLock < FontKeyMapLocked > > ) ;
567
569
568
570
impl FontKeyMap {
569
- const SHARED_NAMESPACE : IdNamespace = IdNamespace ( 0 ) ;
570
-
571
- pub fn new ( ) -> Self {
571
+ pub fn new ( namespace : IdNamespace ) -> Self {
572
572
FontKeyMap ( Arc :: new ( RwLock :: new ( FontKeyMapLocked {
573
+ namespace,
573
574
next_id : 1 ,
574
575
template_map : FastHashMap :: default ( ) ,
575
576
key_map : FastHashMap :: default ( ) ,
@@ -600,7 +601,7 @@ impl FontKeyMap {
600
601
locked. key_map . insert ( * font_key, mapped) ;
601
602
return None ;
602
603
}
603
- let shared_key = FontKey :: new ( Self :: SHARED_NAMESPACE , locked. next_id ) ;
604
+ let shared_key = FontKey :: new ( locked . namespace , locked. next_id ) ;
604
605
locked. next_id += 1 ;
605
606
let mapped = Arc :: new ( MappedFontKey {
606
607
font_key : shared_key,
@@ -717,6 +718,7 @@ impl FontTemplateMap {
717
718
}
718
719
719
720
struct FontInstanceKeyMapLocked {
721
+ namespace : IdNamespace ,
720
722
next_id : u32 ,
721
723
instances : FastHashSet < Arc < BaseFontInstance > > ,
722
724
key_map : FastHashMap < FontInstanceKey , Weak < BaseFontInstance > > ,
@@ -729,15 +731,15 @@ struct FontInstanceKeyMapLocked {
729
731
/// key to assign to that instance. When the weak count of the mapping is zero,
730
732
/// the entry is allowed to expire. Again, care must be taken when clearing
731
733
/// a namespace within the key map as it may cause shared key expirations that
732
- /// require individual processing.
734
+ /// require individual processing. Shared instance keys will be created within
735
+ /// the provided unique namespace.
733
736
#[ derive( Clone ) ]
734
737
pub struct FontInstanceKeyMap ( Arc < RwLock < FontInstanceKeyMapLocked > > ) ;
735
738
736
739
impl FontInstanceKeyMap {
737
- const SHARED_NAMESPACE : IdNamespace = IdNamespace ( 0 ) ;
738
-
739
- pub fn new ( ) -> Self {
740
+ pub fn new ( namespace : IdNamespace ) -> Self {
740
741
FontInstanceKeyMap ( Arc :: new ( RwLock :: new ( FontInstanceKeyMapLocked {
742
+ namespace,
741
743
next_id : 1 ,
742
744
instances : FastHashSet :: default ( ) ,
743
745
key_map : FastHashMap :: default ( ) ,
@@ -769,7 +771,7 @@ impl FontInstanceKeyMap {
769
771
return None ;
770
772
}
771
773
let unmapped_key = instance. instance_key ;
772
- instance. instance_key = FontInstanceKey :: new ( Self :: SHARED_NAMESPACE , locked. next_id ) ;
774
+ instance. instance_key = FontInstanceKey :: new ( locked . namespace , locked. next_id ) ;
773
775
locked. next_id += 1 ;
774
776
let shared_instance = Arc :: new ( instance) ;
775
777
locked. instances . insert ( shared_instance. clone ( ) ) ;
@@ -911,12 +913,12 @@ pub struct SharedFontResources {
911
913
}
912
914
913
915
impl SharedFontResources {
914
- pub fn new ( ) -> Self {
916
+ pub fn new ( namespace : IdNamespace ) -> Self {
915
917
SharedFontResources {
916
918
templates : FontTemplateMap :: new ( ) ,
917
919
instances : FontInstanceMap :: new ( ) ,
918
- font_keys : FontKeyMap :: new ( ) ,
919
- instance_keys : FontInstanceKeyMap :: new ( ) ,
920
+ font_keys : FontKeyMap :: new ( namespace ) ,
921
+ instance_keys : FontInstanceKeyMap :: new ( namespace ) ,
920
922
}
921
923
}
922
924
}
0 commit comments