@@ -6,17 +6,11 @@ use core_types::table::TableRow;
66use raster_types:: CPU ;
77use raster_types:: Raster ;
88use std:: collections:: HashMap ;
9- use std:: hash:: Hash ;
10- use std:: hash:: Hasher ;
11- use std:: sync:: atomic:: { AtomicU64 , Ordering } ;
129use std:: sync:: { Arc , Mutex } ;
1310
1411// TODO: This is a temporary hack, be sure to not reuse this when the brush system is replaced/rewritten.
15- static NEXT_BRUSH_CACHE_IMPL_ID : AtomicU64 = AtomicU64 :: new ( 0 ) ;
16-
17- #[ derive( Clone , Debug ) ]
12+ #[ derive( Clone , Debug , Default ) ]
1813struct BrushCacheImpl {
19- unique_id : u64 ,
2014 // The full previous input that was cached.
2115 prev_input : Vec < BrushStroke > ,
2216
@@ -89,35 +83,6 @@ impl BrushCacheImpl {
8983 }
9084}
9185
92- impl Default for BrushCacheImpl {
93- fn default ( ) -> Self {
94- Self {
95- unique_id : new_unique_id ( ) ,
96- prev_input : Vec :: new ( ) ,
97- background : Default :: default ( ) ,
98- blended_image : Default :: default ( ) ,
99- last_stroke_texture : Default :: default ( ) ,
100- brush_texture_cache : HashMap :: new ( ) ,
101- }
102- }
103- }
104-
105- impl PartialEq for BrushCacheImpl {
106- fn eq ( & self , other : & Self ) -> bool {
107- self . unique_id == other. unique_id
108- }
109- }
110-
111- impl Hash for BrushCacheImpl {
112- fn hash < H : Hasher > ( & self , state : & mut H ) {
113- self . unique_id . hash ( state) ;
114- }
115- }
116-
117- fn new_unique_id ( ) -> u64 {
118- NEXT_BRUSH_CACHE_IMPL_ID . fetch_add ( 1 , Ordering :: SeqCst )
119- }
120-
12186#[ derive( Clone , Debug , Default ) ]
12287pub struct BrushPlan {
12388 pub strokes : Vec < BrushStroke > ,
@@ -126,43 +91,9 @@ pub struct BrushPlan {
12691 pub first_stroke_point_skip : usize ,
12792}
12893
129- #[ derive( Debug , Default ) ]
94+ #[ derive( Debug , Default , Clone ) ]
13095pub struct BrushCache ( Arc < Mutex < BrushCacheImpl > > ) ;
13196
132- // A bit of a cursed implementation to work around the current node system.
133- // The original object is a 'prototype' that when cloned gives you a independent
134- // new object. Any further clones however are all the same underlying cache object.
135- impl Clone for BrushCache {
136- fn clone ( & self ) -> Self {
137- Self ( Arc :: new ( Mutex :: new ( self . 0 . lock ( ) . unwrap ( ) . clone ( ) ) ) )
138- }
139- }
140-
141- impl PartialEq for BrushCache {
142- fn eq ( & self , other : & Self ) -> bool {
143- if Arc :: ptr_eq ( & self . 0 , & other. 0 ) {
144- return true ;
145- }
146-
147- let s = self . 0 . lock ( ) . unwrap ( ) ;
148- let o = other. 0 . lock ( ) . unwrap ( ) ;
149-
150- * s == * o
151- }
152- }
153-
154- impl Hash for BrushCache {
155- fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
156- self . 0 . lock ( ) . unwrap ( ) . hash ( state) ;
157- }
158- }
159-
160- impl graphene_hash:: CacheHash for BrushCache {
161- fn cache_hash < H : core:: hash:: Hasher > ( & self , state : & mut H ) {
162- core:: hash:: Hash :: hash ( & self . 0 . lock ( ) . unwrap ( ) . unique_id , state) ;
163- }
164- }
165-
16697impl BrushCache {
16798 pub fn compute_brush_plan ( & self , background : TableRow < Raster < CPU > > , input : & [ BrushStroke ] ) -> BrushPlan {
16899 let mut inner = self . 0 . lock ( ) . unwrap ( ) ;
0 commit comments