From 51309ad50aab30e6a98df79d455bdf1dce7596f4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 23 Sep 2014 17:44:06 +0000 Subject: [PATCH] make x11 dc could get cairo context, so the graphic module could use in x11. This use cairo xlib backend. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77853 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/x11/dcclient.h | 2 ++ src/generic/graphicc.cpp | 6 ++++++ src/x11/dcclient.cpp | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/include/wx/x11/dcclient.h b/include/wx/x11/dcclient.h index 08f540217a..fbcdec11fa 100644 --- a/include/wx/x11/dcclient.h +++ b/include/wx/x11/dcclient.h @@ -108,6 +108,8 @@ public: virtual void ComputeScaleAndOrigin(); + virtual void* GetCairoContext() const wxOVERRIDE; + protected: // implementation // -------------- diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 7a380f23d0..ec701a7a47 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1744,6 +1744,12 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& #endif #endif +#ifdef __WXX11__ + cairo_t* cr = static_cast(dc.GetImpl()->GetCairoContext()); + if ( cr ) + Init(cairo_reference(cr)); +#endif + #ifdef __WXMAC__ CGContextRef cgcontext = (CGContextRef)dc.GetWindow()->MacGetCGContextRef(); cairo_surface_t* surface = cairo_quartz_surface_create_for_cg_context(cgcontext, width, height); diff --git a/src/x11/dcclient.cpp b/src/x11/dcclient.cpp index c3c7d9a3f8..13effdd781 100644 --- a/src/x11/dcclient.cpp +++ b/src/x11/dcclient.cpp @@ -28,6 +28,8 @@ #include "wx/x11/dcclient.h" #include "wx/x11/dcmemory.h" +#include "cairo-xlib.h" + #if wxUSE_UNICODE #include "glib.h" #include "pango/pangoxft.h" @@ -343,6 +345,17 @@ void wxWindowDCImpl::SetUpDC() } } +void* wxWindowDCImpl::GetCairoContext() const +{ + int width, height; + DoGetSize(&width, &height); + cairo_surface_t *surface; + surface = cairo_xlib_surface_create((Display*) m_display, (Drawable) m_x11window, + DefaultVisual((Display*) m_display, 0), width, height); + cairo_t *cr = cairo_create(surface); + return cr; +} + void wxWindowDCImpl::DoGetSize( int* width, int* height ) const { wxCHECK_RET( m_window, wxT("GetSize() doesn't work without window") );