Skip to content

CanvasVirtualControl doesn't invalidate regions ouside 2016x1512 area #1008

@tdn77

Description

@tdn77

Hi all,

I'm trying to use a CanvasVirtualControl (Microsoft.Graphics.Win2D 1.3.2).
I noticed that if my window size is more than 2016x1512, the regions outside of this area are not invalidated even if the virtual canvas size is set to 10000x10000. The clear color is also not applied.

xaml:

<Window
    x:Class="TestVirtualCanvasControl.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TestVirtualCanvasControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
    mc:Ignorable="d"
    Title="TestVirtualCanvasControl">
    
    <ScrollViewer x:Name="scroller" HorizontalScrollMode="Auto" HorizontalScrollBarVisibility="Auto">
        <canvas:CanvasVirtualControl x:Name="canvas" Width="10000" Height="10000"
                                     ClearColor="LightGreen"
                                     RegionsInvalidated="OnRegionsInvalidated" Tapped="OnClicked"/>
    </ScrollViewer>
    
</Window>

cpp:

    void MainWindow::OnRegionsInvalidated(winrt::Microsoft::Graphics::Canvas::UI::Xaml::CanvasVirtualControl const& sender, 
										  winrt::Microsoft::Graphics::Canvas::UI::Xaml::CanvasRegionsInvalidatedEventArgs const& args)
    {
        hstring msg;

        msg = L"CanvasVirtualControl actual size: " + to_hstring(sender.ActualWidth()) + L"x" + to_hstring(sender.ActualHeight()) + L"\n";
		OutputDebugString(msg.c_str());

		msg = L"Args visible region: " + to_hstring(args.VisibleRegion().X) + L"," + to_hstring(args.VisibleRegion().Y) + L"," + to_hstring(args.VisibleRegion().Width) + L"," + to_hstring(args.VisibleRegion().Height) + L"\n";
		OutputDebugString(msg.c_str());

		msg = L"Window bounds: " + to_hstring(Bounds().X) + L"," + to_hstring(Bounds().Y) + L"," + to_hstring(Bounds().Width) + L"," + to_hstring(Bounds().Height) + L"\n";
		OutputDebugString(msg.c_str());

		msg = L"Scroller actual size: " + to_hstring(scroller().ActualWidth()) + L"x" + to_hstring(scroller().ActualHeight()) + L"\n";
		OutputDebugString(msg.c_str());

		msg = L"Scroller extent size: " + to_hstring(scroller().ExtentWidth()) + L"x" + to_hstring(scroller().ExtentHeight()) + L"\n";
		OutputDebugString(msg.c_str());

		msg = L"Scroller viewport size: " + to_hstring(scroller().ViewportWidth()) + L"x" + to_hstring(scroller().ViewportHeight()) + L"\n";
		OutputDebugString(msg.c_str());

		msg = L"Scroller scrollable size: " + to_hstring(scroller().ScrollableWidth()) + L"x" + to_hstring(scroller().ScrollableHeight()) + L"\n";
		OutputDebugString(msg.c_str());

		msg = L"Scroller offsets: " + to_hstring(scroller().HorizontalOffset()) + L"," + to_hstring(scroller().VerticalOffset()) + L"\n";
		OutputDebugString(msg.c_str());

        auto random_byte = [&]() { return 0 + rand() % 255; };
        for (auto&& rect : args.InvalidatedRegions())
        {
			msg = L"Invalidated region: " + to_hstring(rect.X) + L"," + to_hstring(rect.Y) + L"," + to_hstring(rect.Width) + L"," + to_hstring(rect.Height) + L"\n";
			OutputDebugString(msg.c_str());
  
            Windows::UI::Color color; 
			color.A = 255; color.R = random_byte(); color.G = random_byte(); color.B = random_byte();
  
			auto session{ sender.CreateDrawingSession(rect) };
			session.FillRoundedRectangle(rect, 100.0, 100.0, color);
        }
    }

    void MainWindow::OnClicked(winrt::Windows::Foundation::IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::TappedRoutedEventArgs const& e)
    {
        canvas().Invalidate();
    }

output:

CanvasVirtualControl actual size: 10000x10000
Args visible region: 0,0,1424,714
Window bounds: 0,0,2938,714
Scroller actual size: 2938x714
Scroller extent size: 10000x10000
Scroller viewport size: 2938x714
Scroller scrollable size: 7062x9286
Scroller offsets: 0,0
Invalidated region: 0,0,2016,1512

screenshot:

Image

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions