@@ -45,7 +45,7 @@ impl From<u32> for Px {
45
45
}
46
46
}
47
47
48
- #[ derive( Debug , Clone , Copy ) ]
48
+ #[ derive( Debug , Clone , Copy , PartialEq ) ]
49
49
pub enum ImageSize {
50
50
PxWidth ( Px ) ,
51
51
PxHeight ( Px ) ,
@@ -61,7 +61,7 @@ impl ImageSize {
61
61
}
62
62
}
63
63
64
- #[ derive( SmartDebug , Default , Clone ) ]
64
+ #[ derive( SmartDebug , Default , Clone , PartialEq ) ]
65
65
pub struct ImageData {
66
66
#[ debug( wrapper = DebugBytesPrefix ) ]
67
67
lz4_blob : Vec < u8 > ,
@@ -113,6 +113,8 @@ impl ImageData {
113
113
114
114
#[ derive( SmartDebug , Default ) ]
115
115
pub struct Image {
116
+ // TODO: Instead of sharing a mutex with the image loading thread change this to hold a oneshot
117
+ // channel that stores the image?
116
118
#[ debug( skip_fn = debug_ignore_image_data) ]
117
119
pub image_data : Arc < Mutex < Option < ImageData > > > ,
118
120
#[ debug( skip_fn = Option :: is_none, wrapper = DebugInline ) ]
@@ -127,6 +129,49 @@ pub struct Image {
127
129
pub hidpi_scale : f32 ,
128
130
}
129
131
132
+ // NOTE: Internally performs some expensive operations. Avoid calling often
133
+ // TODO: can we deprecate this and then `allow` specific usages of it due to ^^?
134
+ impl PartialEq for Image {
135
+ fn eq ( & self , other : & Self ) -> bool {
136
+ let Self {
137
+ image_data,
138
+ is_aligned,
139
+ size,
140
+ bind_group,
141
+ is_link,
142
+ hidpi_scale,
143
+ } = self ;
144
+ let Self {
145
+ image_data : other_image_data,
146
+ is_aligned : other_is_aligned,
147
+ size : other_size,
148
+ bind_group : other_bind_group,
149
+ is_link : other_is_link,
150
+ hidpi_scale : other_hidpi_scale,
151
+ } = other;
152
+
153
+ let clone_image_data = |shared_image : & Mutex < Option < _ > > | {
154
+ shared_image
155
+ . lock ( )
156
+ . unwrap_or_else ( |err| err. into_inner ( ) )
157
+ . to_owned ( )
158
+ } ;
159
+ let image_data = clone_image_data ( image_data) ;
160
+ let other_image_data = clone_image_data ( other_image_data) ;
161
+
162
+ let some_bind_group = bind_group. is_some ( ) ;
163
+ let some_other_bind_group = other_bind_group. is_some ( ) ;
164
+ let bind_group_variant_matches = some_bind_group ^ !some_other_bind_group;
165
+
166
+ image_data == other_image_data
167
+ && is_aligned == other_is_aligned
168
+ && size == other_size
169
+ && is_link == other_is_link
170
+ && hidpi_scale == other_hidpi_scale
171
+ && bind_group_variant_matches
172
+ }
173
+ }
174
+
130
175
fn debug_ignore_image_data ( mutex : & Mutex < Option < ImageData > > ) -> bool {
131
176
match mutex. lock ( ) {
132
177
Ok ( data) => data. is_none ( ) ,
0 commit comments