-1

我正在努力解决一些 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>
4

1 回答 1

0

在进一步阅读之后,我发现了一些建议使用 VisualBrish 的消息来源。确实,我试过这个,它似乎修复了它(再次,根据 WpfPerf.exe)。

<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>
            <VisualBrush Stretch="Uniform" ViewportUnits="Absolute" TileMode="Tile">
                <VisualBrush.Transform>
                    <ScaleTransform ScaleY="{Binding WorldAndScreen.MetersPerPixel, Converter={StaticResource Multiplier}, ConverterParameter=5}" />
                </VisualBrush.Transform>
                <VisualBrush.Visual>
                    <Image Stretch="None">
                        <Image.Source>
                            <DrawingImage>
                                <DrawingImage.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>
                                </DrawingImage.Drawing>
                            </DrawingImage>
                        </Image.Source>
                    </Image>
                </VisualBrush.Visual>
            </VisualBrush>
        </Path.Fill>
        <Path.Data>
            <PathGeometry FillRule="Nonzero" Figures="{Binding Figures, FallbackValue={StaticResource DefaultFigures}}" />
        </Path.Data>
    </Path>
</DataTemplate>
于 2014-09-29T16:50:49.210 回答