@@ -344,6 +344,10 @@ pub(crate) struct PaintColorTextureMetadata {
344
344
pub ( crate ) filter : PaintFilter ,
345
345
/// How the color texture is to be composited over the base color.
346
346
pub ( crate ) composite_op : PaintCompositeOp ,
347
+ /// How much of a border there needs to be around the image.
348
+ ///
349
+ /// The border ensures clamp-to-edge yields the right result.
350
+ pub ( crate ) border : Vector2I ,
347
351
}
348
352
349
353
#[ derive( Clone , Copy , Debug ) ]
@@ -488,9 +492,13 @@ impl Palette {
488
492
} ,
489
493
transform : Transform2F :: default ( ) ,
490
494
composite_op : overlay. composite_op ( ) ,
495
+ border : Vector2I :: zero ( ) ,
491
496
} )
492
497
}
493
498
PaintContents :: Pattern ( ref pattern) => {
499
+ let border = vec2i ( if pattern. repeat_x ( ) { 0 } else { 1 } ,
500
+ if pattern. repeat_y ( ) { 0 } else { 1 } ) ;
501
+
494
502
let location;
495
503
match * pattern. source ( ) {
496
504
PatternSource :: RenderTarget { id : render_target_id, .. } => {
@@ -501,24 +509,26 @@ impl Palette {
501
509
// TODO(pcwalton): We should be able to use tile cleverness to
502
510
// repeat inside the atlas in some cases.
503
511
let image_hash = image. get_hash ( ) ;
504
- //println!("image hash: {:?}", image_hash);
505
512
match texture_manager. cached_images . get ( & image_hash) {
506
513
Some ( cached_location) => {
507
- //println!("... cache hit: {:?}", cached_location);
508
514
location = * cached_location;
509
515
used_image_hashes. insert ( image_hash) ;
510
516
}
511
517
None => {
512
- //println!("... cache MISS");
518
+ // Leave a pixel of border on the side.
513
519
let allocation_mode = AllocationMode :: OwnPage ;
514
- location = allocator. allocate ( image. size ( ) ,
515
- allocation_mode) ;
520
+ location = allocator. allocate (
521
+ image. size ( ) + border * 2 ,
522
+ allocation_mode) ;
516
523
texture_manager. cached_images . insert ( image_hash,
517
524
location) ;
518
525
}
519
526
}
520
527
image_texel_info. push ( ImageTexelInfo {
521
- location,
528
+ location : TextureLocation {
529
+ page : location. page ,
530
+ rect : location. rect . contract ( border) ,
531
+ } ,
522
532
texels : ( * image. pixels ( ) ) . clone ( ) ,
523
533
} ) ;
524
534
}
@@ -546,8 +556,9 @@ impl Palette {
546
556
page_scale : allocator. page_scale ( location. page ) ,
547
557
sampling_flags,
548
558
filter,
549
- transform : Transform2F :: default ( ) ,
559
+ transform : Transform2F :: from_translation ( border . to_f32 ( ) ) ,
550
560
composite_op : overlay. composite_op ( ) ,
561
+ border,
551
562
} )
552
563
}
553
564
}
0 commit comments