@@ -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
@@ -1014,6 +1017,8 @@ impl GraphicElementRendered for RasterDataTable<CPU> {
10141017 }
10151018}
10161019
1020+ const LAZY_ARC_VEC_ZERO_U8 : LazyLock < Arc < Vec < u8 > > > = LazyLock :: new ( || Arc :: new ( Vec :: new ( ) ) ) ;
1021+
10171022impl GraphicElementRendered for RasterDataTable < GPU > {
10181023 fn render_svg ( & self , _render : & mut SvgRender , _render_params : & RenderParams ) {
10191024 log:: warn!( "tried to render texture as an svg" ) ;
@@ -1023,30 +1028,30 @@ impl GraphicElementRendered for RasterDataTable<GPU> {
10231028 fn render_to_vello ( & self , scene : & mut Scene , transform : DAffine2 , context : & mut RenderContext , _render_params : & RenderParams ) {
10241029 use vello:: peniko;
10251030
1026- let mut render_stuff = | image : peniko :: Image , instance_transform : DAffine2 , blend_mode : AlphaBlending | {
1027- let image_transform = transform * instance_transform * DAffine2 :: from_scale ( 1. / DVec2 :: new ( image . width as f64 , image . height as f64 ) ) ;
1031+ for instance in self . instance_ref_iter ( ) {
1032+ let blend_mode = * instance . alpha_blending ;
10281033 let layer = blend_mode != Default :: default ( ) ;
1029-
1030- let Some ( bounds) = self . bounding_box ( transform, true ) else { return } ;
1031- let blending = peniko:: BlendMode :: new ( blend_mode. blend_mode . to_peniko ( ) , peniko:: Compose :: SrcOver ) ;
1032-
10331034 if layer {
1035+ let Some ( bounds) = self . bounding_box ( transform, true ) else { return } ;
1036+ let blending = peniko:: BlendMode :: new ( blend_mode. blend_mode . to_peniko ( ) , peniko:: Compose :: SrcOver ) ;
10341037 let rect = kurbo:: Rect :: new ( bounds[ 0 ] . x , bounds[ 0 ] . y , bounds[ 1 ] . x , bounds[ 1 ] . y ) ;
10351038 scene. push_layer ( blending, blend_mode. opacity , kurbo:: Affine :: IDENTITY , & rect) ;
10361039 }
1040+
1041+ let image = peniko:: Image :: new (
1042+ Blob :: new ( LAZY_ARC_VEC_ZERO_U8 . deref ( ) . clone ( ) ) ,
1043+ peniko:: ImageFormat :: Rgba8 ,
1044+ instance. instance . data ( ) . width ( ) ,
1045+ instance. instance . data ( ) . height ( ) ,
1046+ )
1047+ . with_extend ( peniko:: Extend :: Repeat ) ;
1048+ let image_transform = transform * * instance. transform * DAffine2 :: from_scale ( 1. / DVec2 :: new ( image. width as f64 , image. height as f64 ) ) ;
10371049 scene. draw_image ( & image, kurbo:: Affine :: new ( image_transform. to_cols_array ( ) ) ) ;
1050+ context. resource_overrides . push ( ( image, instance. instance . data ( ) . clone ( ) ) ) ;
1051+
10381052 if layer {
10391053 scene. pop_layer ( )
10401054 }
1041- } ;
1042-
1043- for instance in self . instance_ref_iter ( ) {
1044- let image = peniko:: Image :: new ( vec ! [ ] . into ( ) , peniko:: ImageFormat :: Rgba8 , instance. instance . data ( ) . width ( ) , instance. instance . data ( ) . height ( ) ) . with_extend ( peniko:: Extend :: Repeat ) ;
1045-
1046- let id = image. data . id ( ) ;
1047- context. resource_overrides . insert ( id, instance. instance . data ( ) . clone ( ) ) ;
1048-
1049- render_stuff ( image, * instance. transform , * instance. alpha_blending ) ;
10501055 }
10511056 }
10521057
0 commit comments