diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index 195a2df8bb..c6fc7477b6 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -307,7 +307,7 @@ public: that were active before the call to this function are still in effect after it. @note Under wxMSW drawing on wxGCDC is possible only if it's associated with - GDI+ wxGraphicsContext. + GDI+ or Direct2D wxGraphicsContext. @library{wxcore} @category{gdi} diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index 14e938b25c..69eb6cf7ac 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -3994,15 +3994,8 @@ public: return GetRenderTarget(); } - WXHDC GetNativeHDC() wxOVERRIDE - { - wxFAIL_MSG("Can't get HDC from Direct2D context"); - return NULL; - }; - void ReleaseNativeHDC(WXHDC WXUNUSED(hdc)) wxOVERRIDE - { - wxFAIL_MSG("Can't release HDC for Direct2D context"); - }; + WXHDC GetNativeHDC() wxOVERRIDE; + void ReleaseNativeHDC(WXHDC hdc) wxOVERRIDE; private: void Init(); @@ -4053,6 +4046,7 @@ private: wxStack m_stateStack; wxStack m_layers; ID2D1RenderTarget* m_cachedRenderTarget; + wxCOMPtr m_gdiRenderTarget; D2D1::Matrix3x2F m_initTransform; // Clipping box bool m_isClipBoxValid; @@ -4977,6 +4971,24 @@ void wxD2DContext::GetDPI(wxDouble* dpiX, wxDouble* dpiY) const } } +WXHDC wxD2DContext::GetNativeHDC() +{ + if ( !m_gdiRenderTarget ) + GetRenderTarget()->QueryInterface(IID_ID2D1GdiInteropRenderTarget, reinterpret_cast(&m_gdiRenderTarget)); + wxASSERT(m_gdiRenderTarget); + HDC hdc; + HRESULT hr = m_gdiRenderTarget->GetDC(D2D1_DC_INITIALIZE_MODE_COPY, &hdc); + wxCHECK_MSG(SUCCEEDED(hr), NULL, wxString::Format("Can't get HDC from Direct2D context (hr=%x)", hr)); + return hdc; +}; + +void wxD2DContext::ReleaseNativeHDC(WXHDC WXUNUSED(hdc)) +{ + wxCHECK_RET(m_gdiRenderTarget, "Can't release HDC for Direct2D context"); + HRESULT hr = m_gdiRenderTarget->ReleaseDC(NULL); + wxCHECK_HRESULT_RET(hr); +}; + //----------------------------------------------------------------------------- // wxD2DRenderer declaration //-----------------------------------------------------------------------------