From f30b9eed380fc267a812460087ae50c3bbd06452 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Fri, 13 Jul 2012 16:58:37 +0000 Subject: [PATCH] avoid creating and immediately destroying a wxGraphicsContext when creating a wxDC with wxGTK3 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72073 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dcgraph.h | 4 ++++ include/wx/gtk/dc.h | 2 ++ src/common/dcgraph.cpp | 7 +++++++ src/gtk/dc.cpp | 25 ++++++++++++++----------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index afe88c83d8..9f6c178fd3 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -201,6 +201,10 @@ public: #endif // __WXMSW__ protected: + // unused int parameter distinguishes this version, which does not create a + // wxGraphicsContext, in the expectation that the derived class will do it + wxGCDCImpl(wxDC* owner, int); + // scaling variables bool m_logicalFunctionSupported; wxGraphicsMatrix m_matrixOriginal; diff --git a/include/wx/gtk/dc.h b/include/wx/gtk/dc.h index 65944e6a70..aa97ecb326 100644 --- a/include/wx/gtk/dc.h +++ b/include/wx/gtk/dc.h @@ -19,7 +19,9 @@ class wxGTKCairoDCImpl: public wxGCDCImpl typedef wxGCDCImpl base_type; public: wxGTKCairoDCImpl(wxDC* owner); + wxGTKCairoDCImpl(wxDC* owner, int); wxGTKCairoDCImpl(wxDC* owner, wxWindow* window); + virtual void DoDrawBitmap(const wxBitmap& bitmap, int x, int y, bool useMask); virtual void DoDrawIcon(const wxIcon& icon, int x, int y); #if wxUSE_IMAGE diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 19b8124b77..3b49dce031 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -205,6 +205,13 @@ wxGCDCImpl::wxGCDCImpl(wxDC *owner, const wxEnhMetaFileDC& dc) } #endif +wxGCDCImpl::wxGCDCImpl(wxDC* owner, int) + : wxDCImpl(owner) +{ + // derived class will set a context + Init(NULL); +} + void wxGCDCImpl::Init(wxGraphicsContext* ctx) { m_ok = false; diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index de3eb8005d..791961499c 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -28,8 +28,15 @@ wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner) m_height = 0; } +wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, int) + : base_type(owner, 0) +{ + m_width = 0; + m_height = 0; +} + wxGTKCairoDCImpl::wxGTKCairoDCImpl(wxDC* owner, wxWindow* window) - : base_type(owner) + : base_type(owner, 0) { m_window = window; m_font = window->GetFont(); @@ -219,6 +226,8 @@ wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window) if (x || y) SetDeviceLocalOrigin(x, y); } + else + SetGraphicsContext(wxGraphicsContext::Create()); } //----------------------------------------------------------------------------- @@ -255,13 +264,7 @@ wxClientDCImpl::wxClientDCImpl(wxClientDC* owner, wxWindow* window) } } else - { - // create something that can be used for measuring, but not drawing - cairo_t* cr = gdk_cairo_create(gdk_get_default_root_window()); - cairo_rectangle(cr, 0, 0, 0, 0); - cairo_clip(cr); - SetGraphicsContext(wxGraphicsContext::CreateFromNative(cr)); - } + SetGraphicsContext(wxGraphicsContext::Create()); } //----------------------------------------------------------------------------- @@ -279,7 +282,7 @@ wxPaintDCImpl::wxPaintDCImpl(wxPaintDC* owner, wxWindow* window) //----------------------------------------------------------------------------- wxScreenDCImpl::wxScreenDCImpl(wxScreenDC* owner) - : base_type(owner) + : base_type(owner, 0) { GdkWindow* window = gdk_get_default_root_window(); m_width = gdk_window_get_width(window); @@ -296,7 +299,7 @@ wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC* owner) } wxMemoryDCImpl::wxMemoryDCImpl(wxMemoryDC* owner, wxBitmap& bitmap) - : base_type(owner) + : base_type(owner, 0) , m_bitmap(bitmap) { Setup(); @@ -345,7 +348,7 @@ void wxMemoryDCImpl::Setup() //----------------------------------------------------------------------------- wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr) - : base_type(new wxGTKCairoDCImpl(this)) + : base_type(new wxGTKCairoDCImpl(this, 0)) { cairo_reference(cr); SetGraphicsContext(wxGraphicsContext::CreateFromNative(cr));