BCG SVG Image performance and default BCG GraphicsManager

77 Views Asked by At

BCGControlBar Pro for MFC actively uses SVG graphics in Ribbon UI and BCG Button classes. Mostly the library uses CBCGPSVGImage class to load and render SVG content and in most case the main job is performed by CBCGPSVGImage::ExportToBitmap method.

But when your application uses a lot of SVG graphics that are load from resource dynamically you may notice a significant performance lag. CBCGPSVGImage::ExportToBitmap method uses BCG GraphicsManager abstraction to render SVG graphics in Bitmap. By default BCG used D2D Graphics Manager that has significant delay in BeginDraw\EndDraw operations.

Situation can be improved if application uses GDI+ Graphics Manager:

CBCGPGraphicsManager::SetDefaultGraphicsManagerType(CBCGPGraphicsManager::BCGP_GRAPHICS_MANAGER_GDI_PLUS);

Does anybody knows why D2D Graphics Manager is default manager? If there is strong point to use it by default, how to improve performance of it in BeginDraw\EndDraw operations?

Small experiment:

void CMyView::OnAbout()
{
    CBCGPSVGImage image;
    image.Load(IDB_IMAGE_SVG);

    const auto begin = std::chrono::high_resolution_clock::now();

    for (int i = 0; i < 20; i++)
    {
        const auto dib = image.ExportToBitmap();
        ::DeleteObject(dib);
    }

    const auto end = std::chrono::high_resolution_clock::now();
    const auto dur_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end-begin);

    AfxMessageBox(CmjStringUtilities::Format(_T("Duration: %lld ms."), dur_ms.count()));
}

Code was compiled in Release variant and run without Debugger.
Results:

BCG Default Graphic Manager - BCGP_GRAPHICS_MANAGER_D2D
Duration: 54 - 57 ms.

BCG Default Graphic Manager - BCGP_GRAPHICS_MANAGER_GDI_PLUS
Duration: 2 - 3 ms.

As you see D2D manager works significantly slower than GDI+ manager. That's very strange. Everything should be the other way around.

If you compile the code in Debug variant with BCGP_GRAPHICS_MANAGER_D2D manager and run under Visual Studio you will see a lot of exceptions inside D2D:

Exception thrown at 0x00007FFA59304D8C in App.exe: Microsoft C++ exception: _com_error at memory location 0x000000000014D1A8.
Exception thrown at 0x00007FFA59304D8C in App.exe: Microsoft C++ exception: _com_error at memory location 0x000000000014D1A8.
Exception thrown at 0x00007FFA59304D8C in App.exe: Microsoft C++ exception: _com_error at memory location 0x000000000014D1A8.
Exception thrown at 0x00007FFA59304D8C in App.exe: Microsoft C++ exception: _com_error at memory location 0x000000000014D1A8.

P.S.: SVG

<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21.8707 21.444H10.1632L5.1499 30.201C5.75301 30.5077 6.4379 30.7043 6.88087 30.7043C11.4863 30.7043 20.8853 30.6362 25.5511 30.6362C26.0308 30.6362 26.4799 30.4726 26.8827 30.2164L21.8707 21.444Z" fill="#4185F3"/>
<path d="M5.14989 30.2014L10.1632 21.4443H0.00436107C-0.000750039 22.0529 0.21562 22.6097 0.554658 23.2448C1.49919 25.0119 3.09727 27.8366 4.03601 29.312C4.26737 29.6756 5.18601 30.2198 5.14989 30.2014Z" fill="#1767D1"/>
<path d="M21.8707 21.444L26.8844 30.215C27.5342 29.802 28.0637 29.1478 28.4075 28.5454C29.1837 27.1869 30.4962 24.9247 31.4016 23.393C31.8224 22.6809 31.986 22.0413 31.9757 21.4433L21.8707 21.444Z" fill="#E94235"/>
<path d="M10.1642 21.4447L16.012 11.2783L10.7858 2.56491C10.2205 2.93666 9.73696 3.4413 9.51752 3.82565C7.23626 7.82663 2.64069 16.0266 0.329781 20.0793C0.0929862 20.494 -0.0203875 20.9677 0.00301049 21.4447H10.1642Z" fill="#30A753"/>
<path d="M21.8704 21.4447L16.012 11.2783L21.0949 2.5748C21.6601 2.94689 22.2806 3.4413 22.5001 3.826C24.7813 7.82664 29.3769 16.0266 31.6888 20.0793C31.9274 20.4961 31.9992 20.9677 31.9761 21.4447H21.8704Z" fill="#F9BC00"/>
<path d="M10.7851 2.56627L16.0121 11.2783L21.0949 2.57479C20.5702 2.26812 19.827 2.08651 19.1074 2.06368C17.1052 1.99689 13.8593 1.96997 12.1123 2.04596C11.6816 2.0647 10.7905 2.56252 10.7851 2.56627Z" fill="#0F8038"/>
</svg>

BCG Lib version is "33.1"
C++ toolset is "Visual Studio 2022 (v143)"

0

There are 0 best solutions below