我正在努力解决一些 WPF 性能问题。Ants 分析器和 dotTrace 都表明,WPF 内部一直很深入。我目前使用了许多 DrawingBrush 对象。旧的 WpfPerf.exe 显示我的 DrawingBrush 对象正在 CPU 而不是 GPU 上呈现。我能做些什么来改变它吗?下面是一个例子。为什么它渲染 CPU 端?
<DataTemplate DataType="mapViewModel:ObstacleVM" x:Key="ObstacleShapeTemplate">
<Path Stroke="{DynamicResource Mobius.UI.Resources.Colors.ObstacleShapeOutlineBrush}" StrokeThickness="{Binding WorldAndScreen.MetersPerPixel, Converter={StaticResource Multiplier}, ConverterParameter=1}" StrokeLineJoin="Bevel" StrokeEndLineCap="Square" StrokeStartLineCap="Flat">
<Path.Fill>
<DrawingBrush Stretch="Uniform" ViewportUnits="Absolute" TileMode="Tile">
<DrawingBrush.Transform>
<ScaleTransform ScaleY="{Binding WorldAndScreen.MetersPerPixel, Converter={StaticResource Multiplier}, ConverterParameter=5}" />
</DrawingBrush.Transform>
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="{DynamicResource Mobius.UI.Resources.Colors.ObstacleShapeFillBrush}">
<GeometryDrawing.Geometry>
<GeometryGroup FillRule="Nonzero">
<PathGeometry>
<PathFigure StartPoint="0,0">
<LineSegment Point="1,0" />
<LineSegment Point="1,1" />
<LineSegment Point="0,1" />
</PathFigure>
</PathGeometry>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="{DynamicResource Mobius.UI.Resources.Colors.ObstacleShapeOutlineBrush}">
<GeometryDrawing.Geometry>
<GeometryGroup FillRule="Nonzero">
<PathGeometry>
<PathFigure StartPoint="0,0">
<LineSegment Point="0,.33" />
<LineSegment Point="1,.33" />
<LineSegment Point="1,0" />
</PathFigure>
</PathGeometry>
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Path.Fill>
<Path.Data>
<PathGeometry FillRule="Nonzero" Figures="{Binding Figures, FallbackValue={StaticResource DefaultFigures}}" />
</Path.Data>
</Path>
</DataTemplate>