From a3988c8db6fde2f1b2aeb8332348a7c4e1d9a3e7 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 27 Jun 2021 23:56:24 +0200 Subject: [PATCH] Implement getting/releasing HDC in Cairo wxGraphicsContext (wxMSW) --- interface/wx/renderer.h | 3 --- src/common/cairo.cpp | 4 +++- src/generic/graphicc.cpp | 26 +++++++++++++++++--------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index c6fc7477b6..3604754630 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -306,9 +306,6 @@ public: it changes them, so it is safe to assume that the same pen, brush and colours 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+ or Direct2D wxGraphicsContext. - @library{wxcore} @category{gdi} */ diff --git a/src/common/cairo.cpp b/src/common/cairo.cpp index b8a59d54a2..8a00ebc21f 100644 --- a/src/common/cairo.cpp +++ b/src/common/cairo.cpp @@ -184,7 +184,9 @@ m( cairo_get_font_options, \ (cairo_t* cr, cairo_font_options_t* options), (cr, options) ) \ m( cairo_user_to_device_distance, \ - (cairo_t* cr, double *dx, double* dy), (cr, dx, dy) ) + (cairo_t* cr, double *dx, double* dy), (cr, dx, dy) ) \ + m( cairo_surface_mark_dirty, \ + (cairo_surface_t* surface), (surface)) #ifdef __WXMAC__ #define wxCAIRO_PLATFORM_METHODS(m) \ diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index f8f6e50c25..719fb983fe 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -513,15 +513,8 @@ public: virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const wxOVERRIDE; #ifdef __WXMSW__ - virtual WXHDC GetNativeHDC() wxOVERRIDE - { - wxFAIL_MSG("Can't get HDC from Cairo context"); - return NULL; - }; - virtual void ReleaseNativeHDC(WXHDC WXUNUSED(hdc)) wxOVERRIDE - { - wxFAIL_MSG("Can't release HDC for Cairo context"); - }; + virtual WXHDC GetNativeHDC() wxOVERRIDE; + virtual void ReleaseNativeHDC(WXHDC WXUNUSED(hdc)) wxOVERRIDE; #endif protected: @@ -3086,6 +3079,21 @@ void wxCairoContext::EndLayer() cairo_paint_with_alpha(m_context, double(opacity)); } +#ifdef __WXMSW__ +WXHDC wxCairoContext::GetNativeHDC() +{ + wxCHECK_MSG(m_mswSurface, NULL, "Can't get HDC from Cairo context"); + cairo_surface_flush(m_mswSurface); + return cairo_win32_surface_get_dc(m_mswSurface); +}; + +void wxCairoContext::ReleaseNativeHDC(WXHDC WXUNUSED(hdc)) +{ + wxCHECK_RET(m_mswSurface, "Can't release HDC for Cairo context"); + cairo_surface_mark_dirty(m_mswSurface); +}; +#endif // __WXMSW__ + //----------------------------------------------------------------------------- // wxCairoRenderer declaration //-----------------------------------------------------------------------------