Add Direct2D support to wxSTC

This commit is contained in:
New Pagodi
2018-01-25 16:07:54 -06:00
parent f836d430e9
commit b936bfe85e
12 changed files with 1449 additions and 17 deletions

View File

@@ -72,6 +72,7 @@
#include "wx/private/graphics.h"
#include "wx/stack.h"
#include "wx/sharedptr.h"
#include "wx/msw/private/graphicsd2d.h"
// This must be the last header included to only affect the DEFINE_GUID()
// occurrences below but not any GUIDs declared in the standard files included
@@ -219,6 +220,9 @@ wxDirect2D::DWriteCreateFactory_t wxDirect2D::DWriteCreateFactory = NULL;
DEFINE_GUID(wxIID_IWICImagingFactory,
0xec5ec8a9, 0xc395, 0x4314, 0x9c, 0x77, 0x54, 0xd7, 0xa9, 0x35, 0xff, 0x70);
DEFINE_GUID(wxIID_ID2D1Factory,
0x06152247, 0x6f50, 0x465a, 0x92, 0x45, 0x11, 0x8b, 0xfd, 0x3b, 0x60, 0x07);
DEFINE_GUID(wxIID_IDWriteFactory,
0xb859ee5a, 0xd838, 0x4b5b, 0xa2, 0xe8, 0x1a, 0xdc, 0x7d, 0x93, 0xdb, 0x48);
@@ -299,6 +303,39 @@ IWICImagingFactory* wxWICImagingFactory()
return gs_WICImagingFactory;
}
static ID2D1Factory* gs_ID2D1Factory = NULL;
ID2D1Factory* wxD2D1Factory()
{
if (!wxDirect2D::Initialize())
return NULL;
if (gs_ID2D1Factory == NULL)
{
D2D1_FACTORY_OPTIONS factoryOptions = {D2D1_DEBUG_LEVEL_NONE};
// According to
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee794287(v=vs.85).aspx
// the Direct2D Debug Layer is only available starting with Windows 8
// and Visual Studio 2012.
#if defined(__WXDEBUG__) && defined(__VISUALC__) && wxCHECK_VISUALC_VERSION(11)
if ( wxGetWinVersion() >= wxWinVersion_8 )
{
factoryOptions.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
}
#endif //__WXDEBUG__
HRESULT hr = wxDirect2D::D2D1CreateFactory(
D2D1_FACTORY_TYPE_SINGLE_THREADED,
wxIID_ID2D1Factory,
&factoryOptions,
reinterpret_cast<void**>(&gs_ID2D1Factory)
);
wxCHECK_HRESULT_RET_PTR(hr);
}
return gs_ID2D1Factory;
}
static IDWriteFactory* gs_IDWriteFactory = NULL;
IDWriteFactory* wxDWriteFactory()
@@ -4457,13 +4494,9 @@ wxGraphicsRenderer* wxGraphicsRenderer::GetDirect2DRenderer()
return gs_D2DRenderer;
}
wxD2DRenderer::wxD2DRenderer()
wxD2DRenderer::wxD2DRenderer():m_direct2dFactory(wxD2D1Factory())
{
HRESULT result;
result = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_direct2dFactory);
if (FAILED(result))
if ( m_direct2dFactory.get() == NULL )
{
wxFAIL_MSG("Could not create Direct2D Factory.");
}
@@ -4770,6 +4803,12 @@ public:
gs_D2DRenderer = NULL;
}
if ( gs_ID2D1Factory )
{
gs_ID2D1Factory->Release();
gs_ID2D1Factory = NULL;
}
::CoUninitialize();
}