Skip to content

Commit 00d4cf5

Browse files
author
徐扬斌
committed
GTK: Add conditional debug logging infrastructure to src/gtk/debughlp.cpp and log all gdk_window_invalidate_rect(), gtk_widget_queue_draw() and gtk_widget_queue_draw_area(). The logging will be available when GDK_DEBUG env is defined.
1 parent 942cadd commit 00d4cf5

File tree

13 files changed

+87
-10
lines changed

13 files changed

+87
-10
lines changed

build/cmake/files.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ set(GTK_LOWLEVEL_SRC
13171317
src/gtk/utilsgtk.cpp
13181318
src/gtk/win_gtk.cpp
13191319
src/gtk/window.cpp
1320+
src/gtk/debughlp.cpp
13201321
)
13211322

13221323
set(GTK2_LOWLEVEL_SRC

include/wx/gtk/private/debughlp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#ifndef _WX_GTK_PRIVATE_DEBUGHLP_H_
2+
#define _WX_GTK_PRIVATE_DEBUGHLP_H_
3+
4+
#include "wx/defs.h"
5+
6+
bool wxGtkDebugLog(const char* format, const char* function_name, int line_num, const char* src_file ...);
7+
8+
#define DO_GTK_DEBUG_LOG(format, ...) \
9+
wxGtkDebugLog("%s:%d:%s--->" format, __func__, __LINE__, __FILE__, __VA_ARGS__)
10+
11+
#endif

src/gtk/dataview.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,6 +1920,8 @@ bool wxGtkDataViewModelNotifier::ValueChanged( const wxDataViewItem &item, unsig
19201920
gtk_widget_get_allocation(GTK_WIDGET(gtk_tree_view_column_get_button(gcolumn)), &a);
19211921
int ydiff = a.height;
19221922
// Redraw
1923+
DO_GTK_DEBUG_LOG("wxGtkDataViewModelNotifier::ValueChanged:Call gtk_widget_queue_draw_area(%p, rect(%d, %d, %d, %d)).\n",
1924+
GTK_WIDGET(widget), cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height);
19231925
gtk_widget_queue_draw_area( GTK_WIDGET(widget),
19241926
cell_area.x - xdiff, ydiff + cell_area.y, cell_area.width, cell_area.height );
19251927
}
@@ -3748,6 +3750,7 @@ void wxDataViewCtrlInternal::OnInternalIdle()
37483750
if (m_dirty)
37493751
{
37503752
GtkWidget *widget = m_owner->GtkGetTreeView();
3753+
DO_GTK_DEBUG_LOG("wxDataViewCtrlInternal::OnInternalIdle() Call gtk_widget_queue_draw(%p).\n", widget);
37513754
gtk_widget_queue_draw( widget );
37523755
m_dirty = false;
37533756
}

src/gtk/debughlp.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "wx/gtk/private/debughlp.h"
2+
3+
bool wxGtkDebugLog(const char* format, const char* function_name, int line_num, const char* src_file, ...){
4+
const static auto GDK_DEBUG_defined = wxGetEnv("GDK_DEBUG", nullptr);
5+
if (!GDK_DEBUG_defined)
6+
return false;
7+
::FILE* logfile_ = std::fopen("/tmp/cmclient_gtk.log", "a");
8+
timespec nano_now;
9+
clock_gettime(CLOCK_REALTIME, &nano_now);
10+
if (logfile_ != nullptr){
11+
va_list argptr;
12+
va_start(argptr,line_num);
13+
fprintf(logfile_, "PreciseTime:%ld,%ld. ", nano_now.tv_sec, nano_now.tv_nsec);
14+
fprintf(logfile_, format, src_file, line_num, function_name, argptr);
15+
va_end(argptr);
16+
std::fclose(logfile_);
17+
return true;
18+
}
19+
return false;
20+
}

src/gtk/mdi.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#endif
2020

2121
#include "wx/gtk/private.h"
22+
#include "wx/gtk/private/debughlp.h"
2223

2324
//-----------------------------------------------------------------------------
2425
// "switch_page"
@@ -289,8 +290,10 @@ wxMDIChildFrame::~wxMDIChildFrame()
289290
delete m_menuBar;
290291

291292
// wxMDIClientWindow does not get redrawn properly after last child is removed
292-
if (m_parent && m_parent->GetChildren().size() <= 1)
293+
if (m_parent && m_parent->GetChildren().size() <= 1){
294+
DO_GTK_DEBUG_LOG("wxMDIChildFrame::~wxMDIChildFrame() Call gtk_widget_queue_draw(%p).\n", m_parent->m_widget);
293295
gtk_widget_queue_draw(m_parent->m_widget);
296+
}
294297
}
295298

296299
void wxMDIChildFrame::GTKHandleRealized()

src/gtk/minifram.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "wx/gtk/private/wrapgtk.h"
2828
#include "wx/gtk/private/gtk3-compat.h"
2929
#include "wx/gtk/private/backend.h"
30+
#include "wx/gtk/private/debughlp.h"
3031

3132
//-----------------------------------------------------------------------------
3233
// data
@@ -456,8 +457,10 @@ void wxMiniFrame::SetTitle( const wxString &title )
456457
wxFrame::SetTitle( title );
457458

458459
GdkWindow* window = gtk_widget_get_window(gtk_bin_get_child(GTK_BIN(m_widget)));
459-
if (window)
460+
if (window){
461+
DO_GTK_DEBUG_LOG("wxMiniFrame::SetTitle() Call gdk_window_invalidate_rect(%p, NULL_RECT, false).\n", window);
460462
gdk_window_invalidate_rect(window, NULL, false);
463+
}
461464
}
462465

463466
#endif // wxUSE_MINIFRAME

src/gtk/overlay.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "wx/window.h"
1616
#include "wx/gtk/private/wrapgtk.h"
1717
#include "wx/gtk/private/backend.h"
18+
#include "wx/gtk/private/debughlp.h"
1819

1920
class wxOverlayImpl: public wxOverlay::Impl
2021
{
@@ -185,6 +186,7 @@ void wxOverlayImpl::EndDrawing(wxDC* dc)
185186
cairo_surface_destroy(m_surface);
186187
m_surface = surface;
187188
}
189+
DO_GTK_DEBUG_LOG("wxOverlayImpl::EndDrawing() Call gtk_widget_queue_draw(%p).\n", m_overlay);
188190
gtk_widget_queue_draw(m_overlay);
189191
}
190192

src/gtk/slider.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "wx/gtk/private/wrapgtk.h"
2222
#include "wx/gtk/private/eventsdisabler.h"
23+
#include "wx/gtk/private/debughlp.h"
2324

2425
//-----------------------------------------------------------------------------
2526
// data
@@ -432,6 +433,7 @@ void wxSlider::GTKSetValue(int value)
432433

433434
gtk_range_set_value(GTK_RANGE (m_scale), value);
434435
// GTK only updates value label if handle moves at least 1 pixel
436+
DO_GTK_DEBUG_LOG("wxSlider::GTKSetValue() Call gtk_widget_queue_draw(%p).\n", m_scale);
435437
gtk_widget_queue_draw(m_scale);
436438
}
437439

src/gtk/toplevel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "wx/gtk/private/stylecontext.h"
4040
#include "wx/gtk/private/win_gtk.h"
4141
#include "wx/gtk/private/backend.h"
42+
#include "wx/gtk/private/debughlp.h"
4243

4344
#ifdef GDK_WINDOWING_X11
4445
#include <gdk/gdkx.h>
@@ -1040,14 +1041,17 @@ bool wxTopLevelWindowGTK::ShowFullScreen(bool show, long)
10401041
void wxTopLevelWindowGTK::Refresh( bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect) )
10411042
{
10421043
wxCHECK_RET( m_widget, wxT("invalid frame") );
1043-
1044+
1045+
DO_GTK_DEBUG_LOG("wxTopLevelWindowGTK::Refresh() Call gtk_widget_queue_draw(%p).\n", m_widget);
10441046
gtk_widget_queue_draw( m_widget );
10451047

10461048
GdkWindow* window = NULL;
10471049
if (m_wxwindow)
10481050
window = gtk_widget_get_window(m_wxwindow);
1049-
if (window)
1051+
if (window){
1052+
DO_GTK_DEBUG_LOG("wxTopLevelWindowGTK::Refresh() Call gdk_window_invalidate_rect(%p, NULL_RECT, true).\n", window);
10501053
gdk_window_invalidate_rect(window, NULL, true);
1054+
}
10511055
}
10521056

10531057
#if defined(__WXGTK3__) && defined(GDK_WINDOWING_X11)

src/gtk/win_gtk.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "wx/gtk/private.h"
1212
#include "wx/gtk/private/win_gtk.h"
13+
#include "wx/gtk/private/debughlp.h"
1314

1415
/*
1516
wxPizza is a custom GTK+ widget derived from GtkFixed. A custom widget
@@ -86,6 +87,10 @@ static void pizza_size_allocate(GtkWidget* widget, GtkAllocation* alloc)
8687
GtkAllocation old_alloc;
8788
gtk_widget_get_allocation(widget, &old_alloc);
8889
GdkWindow* parent = gtk_widget_get_parent_window(widget);
90+
DO_GTK_DEBUG_LOG("pizza_size_allocate() Call gdk_window_invalidate_rect(%p, rect(%d, %d, %d, %d), false)(old_alloc).\n",
91+
parent, old_alloc.x, old_alloc.y, old_alloc.width, old_alloc.height);
92+
DO_GTK_DEBUG_LOG("pizza_size_allocate() Call gdk_window_invalidate_rect(%p, rect(%d, %d, %d, %d), false)(alloc).\n",
93+
parent, alloc->x, alloc->y, alloc->width, alloc->height);
8994
gdk_window_invalidate_rect(parent, &old_alloc, false);
9095
gdk_window_invalidate_rect(parent, alloc, false);
9196
}
@@ -135,6 +140,7 @@ static void pizza_show(GtkWidget* widget)
135140
// invalidate whole allocation so borders will be drawn properly
136141
GtkAllocation a;
137142
gtk_widget_get_allocation(widget, &a);
143+
DO_GTK_DEBUG_LOG("pizza_show() Call gtk_widget_queue_draw_area(%p, rect(%d, %d, %d, %d)).\n", parent, a.x, a.y, a.width, a.height);
138144
gtk_widget_queue_draw_area(parent, a.x, a.y, a.width, a.height);
139145
}
140146

@@ -149,6 +155,7 @@ static void pizza_hide(GtkWidget* widget)
149155
// invalidate whole allocation so borders will be erased properly
150156
GtkAllocation a;
151157
gtk_widget_get_allocation(widget, &a);
158+
DO_GTK_DEBUG_LOG("pizza_hide() Call gtk_widget_queue_draw_area(%p, rect(%d, %d, %d, %d)).\n", parent, a.x, a.y, a.width, a.height);
152159
gtk_widget_queue_draw_area(parent, a.x, a.y, a.width, a.height);
153160
}
154161

0 commit comments

Comments
 (0)