Fix memory leaks of cairo_t caused by ca7670d2fc, see #17697

This commit is contained in:
Paul Cornett
2016-10-24 14:20:13 -07:00
parent fa4b077421
commit 3b27f7cebc
2 changed files with 4 additions and 5 deletions

View File

@@ -1586,10 +1586,7 @@ gtk_wx_cell_renderer_render (GtkCellRenderer *renderer,
if (context) if (context)
nativeContext = context->GetNativeContext(); nativeContext = context->GetNativeContext();
if (cr != nativeContext) if (cr != nativeContext)
{
cairo_reference(cr);
dc->SetGraphicsContext(wxGraphicsContext::CreateFromNative(cr)); dc->SetGraphicsContext(wxGraphicsContext::CreateFromNative(cr));
}
#else #else
wxWindowDCImpl *impl = (wxWindowDCImpl *) dc->GetImpl(); wxWindowDCImpl *impl = (wxWindowDCImpl *) dc->GetImpl();

View File

@@ -210,6 +210,7 @@ wxWindowDCImpl::wxWindowDCImpl(wxWindowDC* owner, wxWindow* window)
{ {
cairo_t* cr = gdk_cairo_create(gdkWindow); cairo_t* cr = gdk_cairo_create(gdkWindow);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
cairo_destroy(cr);
gc->EnableOffset(m_contentScaleFactor <= 1); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
GtkAllocation a; GtkAllocation a;
@@ -255,6 +256,7 @@ wxClientDCImpl::wxClientDCImpl(wxClientDC* owner, wxWindow* window)
{ {
cairo_t* cr = gdk_cairo_create(gdkWindow); cairo_t* cr = gdk_cairo_create(gdkWindow);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
cairo_destroy(cr);
gc->EnableOffset(m_contentScaleFactor <= 1); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
if (gtk_widget_get_has_window(widget)) if (gtk_widget_get_has_window(widget))
@@ -286,7 +288,6 @@ wxPaintDCImpl::wxPaintDCImpl(wxPaintDC* owner, wxWindow* window)
GdkWindow* gdkWindow = gtk_widget_get_window(window->m_wxwindow); GdkWindow* gdkWindow = gtk_widget_get_window(window->m_wxwindow);
m_width = gdk_window_get_width(gdkWindow); m_width = gdk_window_get_width(gdkWindow);
m_height = gdk_window_get_height(gdkWindow); m_height = gdk_window_get_height(gdkWindow);
cairo_reference(cr);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(m_contentScaleFactor <= 1); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
@@ -301,6 +302,7 @@ wxScreenDCImpl::wxScreenDCImpl(wxScreenDC* owner)
m_height = gdk_window_get_height(window); m_height = gdk_window_get_height(window);
cairo_t* cr = gdk_cairo_create(window); cairo_t* cr = gdk_cairo_create(window);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
cairo_destroy(cr);
gc->EnableOffset(m_contentScaleFactor <= 1); gc->EnableOffset(m_contentScaleFactor <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);
} }
@@ -357,6 +359,7 @@ void wxMemoryDCImpl::Setup()
m_contentScaleFactor = m_bitmap.GetScaleFactor(); m_contentScaleFactor = m_bitmap.GetScaleFactor();
cairo_t* cr = m_bitmap.CairoCreate(); cairo_t* cr = m_bitmap.CairoCreate();
gc = wxGraphicsContext::CreateFromNative(cr); gc = wxGraphicsContext::CreateFromNative(cr);
cairo_destroy(cr);
gc->EnableOffset(m_contentScaleFactor <= 1); gc->EnableOffset(m_contentScaleFactor <= 1);
} }
SetGraphicsContext(gc); SetGraphicsContext(gc);
@@ -366,7 +369,6 @@ void wxMemoryDCImpl::Setup()
wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr, wxWindow* window) wxGTKCairoDC::wxGTKCairoDC(cairo_t* cr, wxWindow* window)
: base_type(new wxGTKCairoDCImpl(this, window->GetContentScaleFactor())) : base_type(new wxGTKCairoDCImpl(this, window->GetContentScaleFactor()))
{ {
cairo_reference(cr);
wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr); wxGraphicsContext* gc = wxGraphicsContext::CreateFromNative(cr);
gc->EnableOffset(window->GetContentScaleFactor() <= 1); gc->EnableOffset(window->GetContentScaleFactor() <= 1);
SetGraphicsContext(gc); SetGraphicsContext(gc);