@@ -16,10 +16,13 @@ use graphene_core::uuid::{NodeId, generate_uuid};
1616use graphene_core:: vector:: VectorDataTable ;
1717use graphene_core:: vector:: click_target:: { ClickTarget , FreePoint } ;
1818use graphene_core:: vector:: style:: { Fill , Stroke , StrokeAlign , ViewMode } ;
19- use graphene_core:: { AlphaBlending , Artboard , ArtboardGroupTable , GraphicElement , GraphicGroupTable } ;
19+ use graphene_core:: { Artboard , ArtboardGroupTable , GraphicElement , GraphicGroupTable } ;
2020use num_traits:: Zero ;
2121use std:: collections:: { HashMap , HashSet } ;
2222use std:: fmt:: Write ;
23+ use std:: ops:: Deref ;
24+ use std:: sync:: { Arc , LazyLock } ;
25+ use vello:: peniko:: Blob ;
2326#[ cfg( feature = "vello" ) ]
2427use vello:: * ;
2528
@@ -145,7 +148,7 @@ impl Default for SvgRender {
145148#[ derive( Clone , Debug , Default ) ]
146149pub struct RenderContext {
147150 #[ cfg( feature = "vello" ) ]
148- pub resource_overrides : HashMap < u64 , wgpu:: Texture > ,
151+ pub resource_overrides : Vec < ( peniko :: Image , wgpu:: Texture ) > ,
149152}
150153
151154/// Static state used whilst rendering
@@ -1008,6 +1011,8 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
10081011 }
10091012}
10101013
1014+ const LAZY_ARC_VEC_ZERO_U8 : LazyLock < Arc < Vec < u8 > > > = LazyLock :: new ( || Arc :: new ( Vec :: new ( ) ) ) ;
1015+
10111016impl GraphicElementRendered for RasterDataTable < GPU > {
10121017 fn render_svg ( & self , _render : & mut SvgRender , _render_params : & RenderParams ) {
10131018 log:: warn!( "tried to render texture as an svg" ) ;
@@ -1017,30 +1022,30 @@ impl GraphicElementRendered for RasterDataTable<GPU> {
10171022 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , context : & mut RenderContext , _render_params : & RenderParams ) {
10181023 use vello:: peniko;
10191024
1020- let mut render_stuff = | image : peniko :: Image , instance_transform : DAffine2 , blend_mode : AlphaBlending | {
1021- let image_transform = transform * instance_transform * DAffine2 :: from_scale ( 1. / DVec2 :: new ( image . width as f64 , image . height as f64 ) ) ;
1025+ for instance in self . instance_ref_iter ( ) {
1026+ let blend_mode = * instance . alpha_blending ;
10221027 let layer = blend_mode != Default :: default ( ) ;
1023-
1024- let Some ( bounds) = self . bounding_box ( transform, true ) else { return } ;
1025- let blending = peniko:: BlendMode :: new ( blend_mode. blend_mode . to_peniko ( ) , peniko:: Compose :: SrcOver ) ;
1026-
10271028 if layer {
1029+ let Some ( bounds) = self . bounding_box ( transform, true ) else { return } ;
1030+ let blending = peniko:: BlendMode :: new ( blend_mode. blend_mode . to_peniko ( ) , peniko:: Compose :: SrcOver ) ;
10281031 let rect = kurbo:: Rect :: new ( bounds[ 0 ] . x , bounds[ 0 ] . y , bounds[ 1 ] . x , bounds[ 1 ] . y ) ;
10291032 scene. push_layer ( blending, blend_mode. opacity , kurbo:: Affine :: IDENTITY , & rect) ;
10301033 }
1034+
1035+ let image = peniko:: Image :: new (
1036+ Blob :: new ( LAZY_ARC_VEC_ZERO_U8 . deref ( ) . clone ( ) ) ,
1037+ peniko:: ImageFormat :: Rgba8 ,
1038+ instance. instance . data ( ) . width ( ) ,
1039+ instance. instance . data ( ) . height ( ) ,
1040+ )
1041+ . with_extend ( peniko:: Extend :: Repeat ) ;
1042+ let image_transform = transform * * instance. transform * DAffine2 :: from_scale ( 1. / DVec2 :: new ( image. width as f64 , image. height as f64 ) ) ;
10311043 scene. draw_image ( & image, kurbo:: Affine :: new ( image_transform. to_cols_array ( ) ) ) ;
1044+ context. resource_overrides . push ( ( image, instance. instance . data ( ) . clone ( ) ) ) ;
1045+
10321046 if layer {
10331047 scene. pop_layer ( )
10341048 }
1035- } ;
1036-
1037- for instance in self . instance_ref_iter ( ) {
1038- let image = peniko:: Image :: new ( vec ! [ ] . into ( ) , peniko:: ImageFormat :: Rgba8 , instance. instance . data ( ) . width ( ) , instance. instance . data ( ) . height ( ) ) . with_extend ( peniko:: Extend :: Repeat ) ;
1039-
1040- let id = image. data . id ( ) ;
1041- context. resource_overrides . insert ( id, instance. instance . data ( ) . clone ( ) ) ;
1042-
1043- render_stuff ( image, * instance. transform , * instance. alpha_blending ) ;
10441049 }
10451050 }
10461051
0 commit comments