@@ -10,7 +10,7 @@ use fnv::FnvHashMap;
10
10
use fonts:: FontContext ;
11
11
use fxhash:: FxHashMap ;
12
12
use net_traits:: image_cache:: {
13
- ImageCache , ImageCacheResult , ImageOrMetadataAvailable , PendingImageId , UsePlaceholder ,
13
+ Image as CachedImage , ImageCache , ImageCacheResult , ImageOrMetadataAvailable , PendingImageId , UsePlaceholder
14
14
} ;
15
15
use parking_lot:: { Mutex , RwLock } ;
16
16
use pixels:: Image as PixelImage ;
@@ -49,20 +49,28 @@ pub struct LayoutContext<'a> {
49
49
pub iframe_sizes : Mutex < IFrameSizes > ,
50
50
51
51
pub resolved_image_cache :
52
- Arc < RwLock < FnvHashMap < ( ServoUrl , UsePlaceholder ) , Option < net_traits :: image_cache :: Image > > > > ,
52
+ Arc < RwLock < FnvHashMap < ( ServoUrl , UsePlaceholder ) , Option < CachedImage > > > > ,
53
53
54
54
pub node_image_animation_map : Arc < RwLock < FxHashMap < OpaqueNode , ImageAnimationState > > > ,
55
55
}
56
56
57
+ pub struct LayoutImage {
58
+ pub image : CachedImage ,
59
+ // image-set images can override the natural resolution
60
+ // and hence the final size for raster images
61
+ pub size : DeviceIntSize
62
+ }
63
+
57
64
pub enum ResolvedImage < ' a > {
58
65
Gradient ( & ' a Gradient ) ,
59
- Image ( net_traits :: image_cache :: Image ) ,
66
+ Image ( LayoutImage ) ,
60
67
}
61
68
62
69
impl Drop for LayoutContext < ' _ > {
63
70
fn drop ( & mut self ) {
64
71
if !std:: thread:: panicking ( ) {
65
72
assert ! ( self . pending_images. lock( ) . is_empty( ) ) ;
73
+ assert ! ( self . pending_rasterization_images. lock( ) . is_empty( ) ) ;
66
74
}
67
75
}
68
76
}
@@ -156,7 +164,7 @@ impl LayoutContext<'_> {
156
164
node : OpaqueNode ,
157
165
url : ServoUrl ,
158
166
use_placeholder : UsePlaceholder ,
159
- ) -> Result < net_traits :: image_cache :: Image , ResolveImageError > {
167
+ ) -> Result < CachedImage , ResolveImageError > {
160
168
if let Some ( cached_image) = self
161
169
. resolved_image_cache
162
170
. read ( )
@@ -229,12 +237,13 @@ impl LayoutContext<'_> {
229
237
// element and not just the node.
230
238
let image_url = image_url. url ( ) . ok_or ( ResolveImageError :: InvalidUrl ) ?;
231
239
let node = node. ok_or ( ResolveImageError :: MissingNode ) ?;
232
- let webrender_info = self . get_webrender_image_for_url (
240
+ let image = self . get_webrender_image_for_url (
233
241
node,
234
242
image_url. clone ( ) . into ( ) ,
235
243
UsePlaceholder :: No ,
236
244
) ?;
237
- Ok ( ResolvedImage :: Image ( webrender_info) )
245
+ let size = Size2D :: new ( image. metadata ( ) . width as i32 , image. metadata ( ) . height as i32 ) ;
246
+ Ok ( ResolvedImage :: Image ( LayoutImage { image, size } ) )
238
247
} ,
239
248
Image :: ImageSet ( image_set) => {
240
249
image_set
@@ -244,17 +253,24 @@ impl LayoutContext<'_> {
244
253
. and_then ( |image| {
245
254
self . resolve_image ( node, & image. image )
246
255
. map ( |info| match info {
247
- ResolvedImage :: Image ( image_info ) => {
256
+ ResolvedImage :: Image ( layout_image ) => {
248
257
// From <https://drafts.csswg.org/css-images-4/#image-set-notation>:
249
258
// > A <resolution> (optional). This is used to help the UA decide
250
259
// > which <image-set-option> to choose. If the image reference is
251
260
// > for a raster image, it also specifies the image’s natural
252
261
// > resolution, overriding any other source of data that might
253
262
// > supply a natural resolution.
254
- // TODO: what is this
255
- // image_info.size = (image_info.size.to_f32() / image.resolution.dppx())
256
- // .to_u32();
257
- ResolvedImage :: Image ( image_info)
263
+ let image_metadata = layout_image. image . metadata ( ) ;
264
+ let size = if layout_image. image . as_raster_image ( ) . is_some ( ) {
265
+ let scale_factor = image. resolution . dppx ( ) ;
266
+ Size2D :: new (
267
+ image_metadata. width as f32 / scale_factor,
268
+ image_metadata. height as f32 / scale_factor
269
+ ) . to_i32 ( )
270
+ } else {
271
+ Size2D :: new ( image_metadata. width , image_metadata. height ) . to_i32 ( )
272
+ } ;
273
+ ResolvedImage :: Image ( LayoutImage { size, .. layout_image } )
258
274
} ,
259
275
_ => info,
260
276
} )
0 commit comments