@@ -51,7 +51,7 @@ pub struct LayoutContext<'a> {
5151 // A cache that maps image resources used in CSS (e.g as the `url()` value
5252 // for `background-image` or `content` property) to the final resolved image data.
5353 pub resolved_images_cache :
54- Arc < RwLock < FnvHashMap < ( ServoUrl , UsePlaceholder ) , Option < CachedImage > > > > ,
54+ Arc < RwLock < FnvHashMap < ( ServoUrl , UsePlaceholder ) , Result < CachedImage , ResolveImageError > > > > ,
5555
5656 pub node_image_animation_map : Arc < RwLock < FxHashMap < OpaqueNode , ImageAnimationState > > > ,
5757
@@ -83,7 +83,7 @@ impl Drop for LayoutContext<'_> {
8383 }
8484}
8585
86- #[ derive( Debug ) ]
86+ #[ derive( Copy , Clone , Debug ) ]
8787pub enum ResolveImageError {
8888 LoadError ,
8989 ImagePending ,
@@ -108,7 +108,7 @@ impl LayoutContext<'_> {
108108 node : OpaqueNode ,
109109 url : ServoUrl ,
110110 use_placeholder : UsePlaceholder ,
111- ) -> Result < ImageOrMetadataAvailable , ResolveImageError > {
111+ ) -> Result < Option < ImageOrMetadataAvailable > , ( ) > {
112112 // Check for available image or start tracking.
113113 let cache_result = self . image_cache . get_cached_image_status (
114114 url. clone ( ) ,
@@ -118,7 +118,7 @@ impl LayoutContext<'_> {
118118 ) ;
119119
120120 match cache_result {
121- ImageCacheResult :: Available ( img_or_meta) => Ok ( img_or_meta) ,
121+ ImageCacheResult :: Available ( img_or_meta) => Ok ( Some ( img_or_meta) ) ,
122122 // Image has been requested, is still pending. Return no image for this paint loop.
123123 // When the image loads it will trigger a reflow and/or repaint.
124124 ImageCacheResult :: Pending ( id) => {
@@ -129,7 +129,7 @@ impl LayoutContext<'_> {
129129 origin : self . origin . clone ( ) ,
130130 } ;
131131 self . pending_images . lock ( ) . push ( image) ;
132- Result :: Err ( ResolveImageError :: ImagePending )
132+ Ok ( None )
133133 } ,
134134 // Not yet requested - request image or metadata from the cache
135135 ImageCacheResult :: ReadyForRequest ( id) => {
@@ -140,10 +140,10 @@ impl LayoutContext<'_> {
140140 origin : self . origin . clone ( ) ,
141141 } ;
142142 self . pending_images . lock ( ) . push ( image) ;
143- Result :: Err ( ResolveImageError :: ImageRequested )
143+ Ok ( None )
144144 } ,
145145 // Image failed to load, so just return nothing
146- ImageCacheResult :: LoadError => Result :: Err ( ResolveImageError :: LoadError ) ,
146+ ImageCacheResult :: LoadError => Result :: Err ( ( ) ) ,
147147 }
148148 }
149149
@@ -178,26 +178,31 @@ impl LayoutContext<'_> {
178178 . read ( )
179179 . get ( & ( url. clone ( ) , use_placeholder) )
180180 {
181- return cached_image
182- . as_ref ( )
183- . map_or ( Err ( ResolveImageError :: LoadError ) , |image| Ok ( image. clone ( ) ) ) ;
181+ return cached_image. clone ( ) ;
184182 }
185183
186- let image_or_meta =
187- self . get_or_request_image_or_meta ( node, url. clone ( ) , use_placeholder) ?;
188- match image_or_meta {
189- ImageOrMetadataAvailable :: ImageAvailable { image, .. } => {
184+ let result = self . get_or_request_image_or_meta ( node, url. clone ( ) , use_placeholder) ;
185+ match result {
186+ Ok ( Some ( ImageOrMetadataAvailable :: ImageAvailable { image, .. } ) ) => {
190187 if let Some ( image) = image. as_raster_image ( ) {
191188 self . handle_animated_image ( node, image. clone ( ) ) ;
192189 }
193190
194191 let mut resolved_images_cache = self . resolved_images_cache . write ( ) ;
195- resolved_images_cache. insert ( ( url, use_placeholder) , Some ( image. clone ( ) ) ) ;
192+ resolved_images_cache. insert ( ( url, use_placeholder) , Ok ( image. clone ( ) ) ) ;
196193 Ok ( image)
197194 } ,
198- ImageOrMetadataAvailable :: MetadataAvailable ( ..) => {
195+ Ok ( Some ( ImageOrMetadataAvailable :: MetadataAvailable ( ..) ) ) => {
199196 Result :: Err ( ResolveImageError :: OnlyMetadata )
200197 } ,
198+ Ok ( None ) => Result :: Err ( ResolveImageError :: ImagePending ) ,
199+ Err ( ( ) ) => {
200+ let error = Err ( ResolveImageError :: LoadError ) ;
201+ self . resolved_images_cache
202+ . write ( )
203+ . insert ( ( url, use_placeholder) , error. clone ( ) ) ;
204+ error
205+ } ,
201206 }
202207 }
203208
0 commit comments