Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upCreateDrawingSession and multithread support #570
Comments
|
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. |
|
Hi Shawnhar! 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 : _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! |
|
Hi! Thanks. |
|
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? |
|
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! |
|
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. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

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