Implement SVG rasterization using Direct2D (PR #22028)

11 views
Skip to first unread message

PB

unread,
Jan 19, 2022, 1:26:52 PM1/19/22
to wx-...@googlegroups.com, Subscribed

Vadim recently mentioned that it could be good to use Direct2D to rasterize SVGs in wxBitmapBundle.

This is an attempt to implement this in a class wxBitmapBundleImplSVGD2D. Disclaimer: I have no experience with Direct2D or any other high-performance graphic API.

I was surprised how limited SVG support in Direct2D is. For example, even the latest version does not support text element, for more information about SVG support in Direct2D see here.

This makes me wonder if using Direct2D renderer is really any better than existing NanoSVG one. I will benchmark the two and see if Direct2D is at least (much) faster but considering its purpose here, the speed may not matter much. I will also finish the program displaying SVGs with both renderers to help check how they cope with different SVGs.

My implementation limitations:

  1. I chose the approach to render SVGs to IWICBitmap, the device context and bitmap are shared among all instances of wxBitmapBundle, created upon first use of any wxBitmapBundleImplSVGD2D method and kept alive during the program lifetime. This may be an utterly wrong approach, please feel free to point it out.
  2. The maximum bitmap size to be render is limited, currently to 512x512, see the code comments.
  3. Direct2D SVG support needs quite recent Windows headers. AFAIK, this rules out any current mingw distribution and leaves only MSVC with recent enough Platform SDK.

Known issues
I call Direct2D APIs like this

hr = wxD2D1Factory()->CreateWicBitmapRenderTarget(ms_bitmap, props, &target);
if ( FAILED(hr) ) ...

However, anytime a call fails, a D2D DEBUG ERROR exception is thrown before the if ( FAILED(...) is executed. I find this very surprising, similar code I saw actually had to ask for an exception with DX::ThrowIfFailed(). Yet, I do not want exceptions but I get them. I could wrap the code with try catch, but I think this should be handled differently. Any ideas?


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/22028

Commit Summary

  • 3fb9e1a Implement SVG rasterization using Direct2D

File Changes

(1 file)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22028@github.com>

PB

unread,
Jan 19, 2022, 1:44:05 PM1/19/22
to wx-...@googlegroups.com, Push

@PBfordev pushed 1 commit.

  • 798617b Wrap wxBitmapBundleImplSVGD2D code in #ifdef wxHAS_BMPBUNDLE_IMPL_SVG_D2D guard


View it on GitHub or unsubscribe.


Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22028/push/8880482689@github.com>

PB

unread,
Jan 19, 2022, 2:09:22 PM1/19/22
to wx-...@googlegroups.com, Subscribed

Closed #22028.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22028/issue_event/5919940975@github.com>

PB

unread,
Jan 19, 2022, 2:09:23 PM1/19/22
to wx-...@googlegroups.com, Subscribed

I have messed-up the commit history, closing and will create a new PR. Sorry.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22028/c1016781225@github.com>

Lauri Nurmi

unread,
Jan 19, 2022, 4:01:33 PM1/19/22
to wx-...@googlegroups.com, Subscribed

I have messed-up the commit history, closing and will create a new PR. Sorry.

You don't need to create a new PR to fix the commit history, just do a force push to your branch.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22028/c1016864615@github.com>

Reply all
Reply to author
Forward
0 new messages