highgui: Make GThread mandatory with GTK

The GThread API is available since more than 11 years with GLib, it is now safe
to assume that it is always available.
pull/25905/head
Corentin Noël 4 months ago
parent 4842043c6a
commit da078c4b75
  1. 8
      CMakeLists.txt
  2. 12
      modules/highgui/CMakeLists.txt
  3. 8
      modules/highgui/cmake/detect_gtk.cmake
  4. 6
      modules/highgui/misc/plugins/plugin_gtk/CMakeLists.txt
  5. 17
      modules/highgui/src/window_gtk.cpp

@ -1465,16 +1465,10 @@ if(WITH_GTK OR HAVE_GTK)
status(" GTK+:" "YES (ver ${GTK3_VERSION})")
elseif(HAVE_GTK)
status(" GTK+:" "YES (ver ${GTK2_VERSION})")
status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${GTKGLEXT_VERSION})" ELSE NO)
else()
status(" GTK+:" "NO")
endif()
if(HAVE_GTK)
status( " GThread :" HAVE_GTHREAD THEN "YES (ver ${GTHREAD_VERSION})" ELSE NO)
if(NOT HAVE_GTK3)
status( " GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${GTKGLEXT_VERSION})" ELSE NO)
endif()
endif()
endif()
if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER)

@ -228,9 +228,6 @@ if(TARGET ocv.3rdparty.gtk3 OR TARGET ocv.3rdparty.gtk2)
endif()
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_gtk.cpp)
list(APPEND tgts ${__gtk_dependency})
if(TARGET ocv.3rdparty.gthread)
list(APPEND tgts ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext
AND __gtk_dependency STREQUAL "ocv.3rdparty.gtk2"
AND NOT OPENCV_GTK_DISABLE_GTKGLEXT
@ -245,27 +242,18 @@ if(TARGET ocv.3rdparty.gtk3 OR TARGET ocv.3rdparty.gtk2)
endif()
elseif("gtk" IN_LIST HIGHGUI_PLUGIN_LIST)
ocv_create_builtin_highgui_plugin(opencv_highgui_gtk ${__gtk_dependency} "window_gtk.cpp")
if(TARGET ocv.3rdparty.gthread)
ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext)
ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gtkglext)
endif()
else()
if(TARGET ocv.3rdparty.gtk3 AND ("gtk3" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
ocv_create_builtin_highgui_plugin(opencv_highgui_gtk3 ocv.3rdparty.gtk3 "window_gtk.cpp")
if(TARGET ocv.3rdparty.gthread)
ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext)
ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gtkglext)
endif()
endif()
if(TARGET ocv.3rdparty.gtk2 AND ("gtk2" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
ocv_create_builtin_highgui_plugin(opencv_highgui_gtk2 ocv.3rdparty.gtk2 "window_gtk.cpp")
if(TARGET ocv.3rdparty.gthread)
ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gthread)
endif()
if(TARGET ocv.3rdparty.gtkglext)
ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gtkglext)
endif()

@ -1,5 +1,5 @@
# --- GTK ---
ocv_clear_vars(HAVE_GTK HAVE_GTK2 HAVE_GTK3 HAVE_GTHREAD HAVE_GTKGLEXT)
ocv_clear_vars(HAVE_GTK HAVE_GTK2 HAVE_GTK3 HAVE_GTKGLEXT)
if(WITH_GTK)
if(NOT WITH_GTK_2_X)
ocv_check_modules(GTK3 gtk+-3.0)
@ -20,12 +20,6 @@ if(WITH_GTK)
endif()
endif()
endif()
ocv_check_modules(GTHREAD gthread-2.0>=2.32)
if(HAVE_GTK AND NOT HAVE_GTHREAD)
message(FATAL_ERROR "gthread not found. This library is required when building with GTK support")
else()
ocv_add_external_target(gthread "${GTHREAD_INCLUDE_DIRS}" "${GTHREAD_LIBRARIES}" "HAVE_GTHREAD")
endif()
if((WITH_OPENGL OR HAVE_OPENGL) AND (HAVE_GTK2 OR HAVE_GTK3))
if(HAVE_GTK2)
ocv_check_modules(GTKGLEXT gtkglext-1.0)

@ -50,9 +50,3 @@ elseif(DEFINED GTK_VERSION)
else()
message(STATUS "GTK+: YES")
endif()
if(HAVE_GTHREAD)
message(STATUS "GThread : YES (ver ${GTHREAD_VERSION})")
else()
message(STATUS "GThread : NO")
endif()

@ -608,13 +608,11 @@ static gboolean icvOnKeyPress( GtkWidget* widget, GdkEventKey* event, gpointer u
static void icvOnTrackbar( GtkWidget* widget, gpointer user_data );
static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_data );
#ifdef HAVE_GTHREAD
int thread_started=0;
static gpointer icvWindowThreadLoop(gpointer data);
GMutex* last_key_mutex = NULL;
GCond* cond_have_key = NULL;
GThread* window_thread = NULL;
#endif
static int last_key = -1;
@ -660,7 +658,6 @@ CV_IMPL int cvInitSystem( int argc, char** argv )
}
CV_IMPL int cvStartWindowThread(){
#ifdef HAVE_GTHREAD
cvInitSystem(0,NULL);
if (!thread_started)
{
@ -676,12 +673,8 @@ CV_IMPL int cvStartWindowThread(){
}
thread_started = window_thread!=NULL;
return thread_started;
#else
return 0;
#endif
}
#ifdef HAVE_GTHREAD
gpointer icvWindowThreadLoop(gpointer /*data*/)
{
while(1){
@ -698,8 +691,6 @@ gpointer icvWindowThreadLoop(gpointer /*data*/)
return NULL;
}
#endif
#define CV_LOCK_MUTEX() cv::AutoLock lock(getWindowMutex())
static
@ -1282,7 +1273,6 @@ static void checkLastWindow()
// if last window...
if (getGTKWindows().empty())
{
#ifdef HAVE_GTHREAD
if( thread_started )
{
// send key press signal to jump out of any waiting cvWaitKey's
@ -1290,7 +1280,6 @@ static void checkLastWindow()
}
else
{
#endif
// Some GTK+ modules (like the Unity module) use GDBusConnection,
// which has a habit of postponing cleanup by performing it via
// idle sources added to the main loop. Since this was the last window,
@ -1301,9 +1290,7 @@ static void checkLastWindow()
// thread will process events continuously.
while( gtk_events_pending() )
gtk_main_iteration();
#ifdef HAVE_GTHREAD
}
#endif
}
}
@ -1852,7 +1839,6 @@ static gboolean icvOnKeyPress(GtkWidget* widget, GdkEventKey* event, gpointer us
code |= event->state << 16;
#ifdef HAVE_GTHREAD
if(thread_started)
{
g_mutex_lock(last_key_mutex);
@ -1862,7 +1848,6 @@ static gboolean icvOnKeyPress(GtkWidget* widget, GdkEventKey* event, gpointer us
g_mutex_unlock(last_key_mutex);
}
else
#endif
{
last_key = code;
}
@ -2053,7 +2038,6 @@ static gboolean icvAlarm( gpointer user_data )
CV_IMPL int cvWaitKey( int delay )
{
#ifdef HAVE_GTHREAD
if (thread_started && g_thread_self() != window_thread)
{
gboolean expired = true;
@ -2087,7 +2071,6 @@ CV_IMPL int cvWaitKey( int delay )
return my_last_key;
}
else
#endif
{
int expired = 0;
guint timer = 0;

Loading…
Cancel
Save