The Wayback Machine - https://web.archive.org/web/20200914065516/http://github.com/microsoft/Win2D/issues/570
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreateDrawingSession and multithread support #570

Open
Petititi opened this issue Oct 16, 2017 · 6 comments
Open

CreateDrawingSession and multithread support #570

Petititi opened this issue Oct 16, 2017 · 6 comments
Labels

Comments

@Petititi
Copy link

@Petititi Petititi commented Oct 16, 2017

Hello,
would it be possible to create a DrawingSession with flag D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS enabled? This would solve a lot of performances issues I'm facing?

Thanks!

@shawnhar
Copy link
Member

@shawnhar shawnhar commented Oct 16, 2017

Thanks for the suggestion!

There is no direct way to do this in Win2D today. Indirectly this is possible by creating your own ID2D1DeviceContext1 using native D2D calls, then using interop to wrap that with a CanvasDrawingSession.

If you are able to try that (or just locally modify Win2D to always pass that flag) we would love to hear how it affects your performance situation. Any real world data about this would be a big help in deciding how to prioritize adding a flag for this to Win2D.

@Petititi
Copy link
Author

@Petititi Petititi commented Oct 16, 2017

Hi Shawnhar!
Thanks for the suggestion, but this is not possible in my case : I'm using a CanvasVirtualControl, so I can't get the bitmap to render on.

To explain my use case, I'm working on Nebo's rendering (https://www.myscript.com/nebo/) were we have a lot of filled paths (handwriting strokes). I already did some benchmarking using a little trick :
On RegionsInvalidated callback, I create a DrawingSession from CanvasVirtualControl, then I get the native ID2D1DeviceContext (thanks to interop) and finally get the Target, transform and DPI to reconstruct my renderContext with good options:

    _stolenDeviceContext = ATL::CComPtr<ID2D1DeviceContext3>(GetWrappedResource<ID2D1DeviceContext3>(device).Detach());
    _stolenDeviceContext->GetTarget(&targetBitmap);
    auto hr = _stolenDeviceContext->EndDraw();
    assert(SUCCEEDED(hr));

    //create multithreaded threaded context:
    ATL::CComPtr<ID2D1DeviceContext3> renderContext;
    _device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS, (ID2D1DeviceContext**)&renderContext);
    renderContext->SetTarget(targetBitmap);
    renderContext->SetTransform(transform);
    renderContext->SetUnitMode(D2D1_UNIT_MODE_DIPS);
    renderContext->SetDpi(_pageViewDPI, _pageViewDPI);
    renderContext->BeginDraw();

Then, once all my drawings are done, I restart the Win2D drawing:

    auto hr = renderContext->EndDraw();
    assert(SUCCEEDED(hr));
    _stolenDeviceContext->BeginDraw();
    _stolenDeviceContext = nullptr;

But as you can see, there is probably a better way to do it ;-)

For performances, we see a 20% performance increase! This is particularly noticeable when the Canvas is full of strokes, scrolling is smooth with multithreaded optimizations while white screen are visible when optims are disabled.

Tell me if you need more details on our rendering pipeline!

@Petititi
Copy link
Author

@Petititi Petititi commented Nov 10, 2017

Hi!
Do you have any idea when it will be possible to add multithreading support? This would clean the code I post below!

Thanks.

@shawnhar
Copy link
Member

@shawnhar shawnhar commented Nov 10, 2017

We'll look at this the next time we do a Win2D update, but haven't committed to the feature yet so no promises whether it will make the cut. Sorry I can't be more precise at this point.

It looks like you are unblocked for now though with a more complex workaround?

@Petititi
Copy link
Author

@Petititi Petititi commented Nov 10, 2017

Yes, we can live with this workaround, but it's not something we want to keep on a long term ;-)

Btw, thanks for this good API!

@Tom-Cuthill
Copy link

@Tom-Cuthill Tom-Cuthill commented Mar 28, 2018

We would also be interested in the ability to generate cached geometries in a multiple threads. We generate complex maps with thousands of features and every bit of performance increase would be most welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.