mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
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.
This commit is contained in:
parent
4842043c6a
commit
da078c4b75
@ -1465,16 +1465,10 @@ if(WITH_GTK OR HAVE_GTK)
|
|||||||
status(" GTK+:" "YES (ver ${GTK3_VERSION})")
|
status(" GTK+:" "YES (ver ${GTK3_VERSION})")
|
||||||
elseif(HAVE_GTK)
|
elseif(HAVE_GTK)
|
||||||
status(" GTK+:" "YES (ver ${GTK2_VERSION})")
|
status(" GTK+:" "YES (ver ${GTK2_VERSION})")
|
||||||
|
status(" GtkGlExt:" HAVE_GTKGLEXT THEN "YES (ver ${GTKGLEXT_VERSION})" ELSE NO)
|
||||||
else()
|
else()
|
||||||
status(" GTK+:" "NO")
|
status(" GTK+:" "NO")
|
||||||
endif()
|
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()
|
endif()
|
||||||
|
|
||||||
if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER)
|
if(WITH_FRAMEBUFFER OR HAVE_FRAMEBUFFER)
|
||||||
|
@ -228,9 +228,6 @@ if(TARGET ocv.3rdparty.gtk3 OR TARGET ocv.3rdparty.gtk2)
|
|||||||
endif()
|
endif()
|
||||||
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_gtk.cpp)
|
list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_gtk.cpp)
|
||||||
list(APPEND tgts ${__gtk_dependency})
|
list(APPEND tgts ${__gtk_dependency})
|
||||||
if(TARGET ocv.3rdparty.gthread)
|
|
||||||
list(APPEND tgts ocv.3rdparty.gthread)
|
|
||||||
endif()
|
|
||||||
if(TARGET ocv.3rdparty.gtkglext
|
if(TARGET ocv.3rdparty.gtkglext
|
||||||
AND __gtk_dependency STREQUAL "ocv.3rdparty.gtk2"
|
AND __gtk_dependency STREQUAL "ocv.3rdparty.gtk2"
|
||||||
AND NOT OPENCV_GTK_DISABLE_GTKGLEXT
|
AND NOT OPENCV_GTK_DISABLE_GTKGLEXT
|
||||||
@ -245,27 +242,18 @@ if(TARGET ocv.3rdparty.gtk3 OR TARGET ocv.3rdparty.gtk2)
|
|||||||
endif()
|
endif()
|
||||||
elseif("gtk" IN_LIST HIGHGUI_PLUGIN_LIST)
|
elseif("gtk" IN_LIST HIGHGUI_PLUGIN_LIST)
|
||||||
ocv_create_builtin_highgui_plugin(opencv_highgui_gtk ${__gtk_dependency} "window_gtk.cpp")
|
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)
|
if(TARGET ocv.3rdparty.gtkglext)
|
||||||
ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gtkglext)
|
ocv_target_link_libraries(opencv_highgui_gtk ocv.3rdparty.gtkglext)
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
if(TARGET ocv.3rdparty.gtk3 AND ("gtk3" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
|
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")
|
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)
|
if(TARGET ocv.3rdparty.gtkglext)
|
||||||
ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gtkglext)
|
ocv_target_link_libraries(opencv_highgui_gtk3 ocv.3rdparty.gtkglext)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if(TARGET ocv.3rdparty.gtk2 AND ("gtk2" IN_LIST HIGHGUI_PLUGIN_LIST OR HIGHGUI_PLUGIN_LIST STREQUAL "all"))
|
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")
|
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)
|
if(TARGET ocv.3rdparty.gtkglext)
|
||||||
ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gtkglext)
|
ocv_target_link_libraries(opencv_highgui_gtk2 ocv.3rdparty.gtkglext)
|
||||||
endif()
|
endif()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# --- GTK ---
|
# --- 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(WITH_GTK)
|
||||||
if(NOT WITH_GTK_2_X)
|
if(NOT WITH_GTK_2_X)
|
||||||
ocv_check_modules(GTK3 gtk+-3.0)
|
ocv_check_modules(GTK3 gtk+-3.0)
|
||||||
@ -20,12 +20,6 @@ if(WITH_GTK)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
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((WITH_OPENGL OR HAVE_OPENGL) AND (HAVE_GTK2 OR HAVE_GTK3))
|
||||||
if(HAVE_GTK2)
|
if(HAVE_GTK2)
|
||||||
ocv_check_modules(GTKGLEXT gtkglext-1.0)
|
ocv_check_modules(GTKGLEXT gtkglext-1.0)
|
||||||
|
@ -50,9 +50,3 @@ elseif(DEFINED GTK_VERSION)
|
|||||||
else()
|
else()
|
||||||
message(STATUS "GTK+: YES")
|
message(STATUS "GTK+: YES")
|
||||||
endif()
|
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 void icvOnTrackbar( GtkWidget* widget, gpointer user_data );
|
||||||
static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_data );
|
static gboolean icvOnMouse( GtkWidget *widget, GdkEvent *event, gpointer user_data );
|
||||||
|
|
||||||
#ifdef HAVE_GTHREAD
|
|
||||||
int thread_started=0;
|
int thread_started=0;
|
||||||
static gpointer icvWindowThreadLoop(gpointer data);
|
static gpointer icvWindowThreadLoop(gpointer data);
|
||||||
GMutex* last_key_mutex = NULL;
|
GMutex* last_key_mutex = NULL;
|
||||||
GCond* cond_have_key = NULL;
|
GCond* cond_have_key = NULL;
|
||||||
GThread* window_thread = NULL;
|
GThread* window_thread = NULL;
|
||||||
#endif
|
|
||||||
|
|
||||||
static int last_key = -1;
|
static int last_key = -1;
|
||||||
|
|
||||||
@ -660,7 +658,6 @@ CV_IMPL int cvInitSystem( int argc, char** argv )
|
|||||||
}
|
}
|
||||||
|
|
||||||
CV_IMPL int cvStartWindowThread(){
|
CV_IMPL int cvStartWindowThread(){
|
||||||
#ifdef HAVE_GTHREAD
|
|
||||||
cvInitSystem(0,NULL);
|
cvInitSystem(0,NULL);
|
||||||
if (!thread_started)
|
if (!thread_started)
|
||||||
{
|
{
|
||||||
@ -676,12 +673,8 @@ CV_IMPL int cvStartWindowThread(){
|
|||||||
}
|
}
|
||||||
thread_started = window_thread!=NULL;
|
thread_started = window_thread!=NULL;
|
||||||
return thread_started;
|
return thread_started;
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_GTHREAD
|
|
||||||
gpointer icvWindowThreadLoop(gpointer /*data*/)
|
gpointer icvWindowThreadLoop(gpointer /*data*/)
|
||||||
{
|
{
|
||||||
while(1){
|
while(1){
|
||||||
@ -698,8 +691,6 @@ gpointer icvWindowThreadLoop(gpointer /*data*/)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CV_LOCK_MUTEX() cv::AutoLock lock(getWindowMutex())
|
#define CV_LOCK_MUTEX() cv::AutoLock lock(getWindowMutex())
|
||||||
|
|
||||||
static
|
static
|
||||||
@ -1282,7 +1273,6 @@ static void checkLastWindow()
|
|||||||
// if last window...
|
// if last window...
|
||||||
if (getGTKWindows().empty())
|
if (getGTKWindows().empty())
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GTHREAD
|
|
||||||
if( thread_started )
|
if( thread_started )
|
||||||
{
|
{
|
||||||
// send key press signal to jump out of any waiting cvWaitKey's
|
// send key press signal to jump out of any waiting cvWaitKey's
|
||||||
@ -1290,7 +1280,6 @@ static void checkLastWindow()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#endif
|
|
||||||
// Some GTK+ modules (like the Unity module) use GDBusConnection,
|
// Some GTK+ modules (like the Unity module) use GDBusConnection,
|
||||||
// which has a habit of postponing cleanup by performing it via
|
// which has a habit of postponing cleanup by performing it via
|
||||||
// idle sources added to the main loop. Since this was the last window,
|
// 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.
|
// thread will process events continuously.
|
||||||
while( gtk_events_pending() )
|
while( gtk_events_pending() )
|
||||||
gtk_main_iteration();
|
gtk_main_iteration();
|
||||||
#ifdef HAVE_GTHREAD
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1852,7 +1839,6 @@ static gboolean icvOnKeyPress(GtkWidget* widget, GdkEventKey* event, gpointer us
|
|||||||
|
|
||||||
code |= event->state << 16;
|
code |= event->state << 16;
|
||||||
|
|
||||||
#ifdef HAVE_GTHREAD
|
|
||||||
if(thread_started)
|
if(thread_started)
|
||||||
{
|
{
|
||||||
g_mutex_lock(last_key_mutex);
|
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);
|
g_mutex_unlock(last_key_mutex);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
last_key = code;
|
last_key = code;
|
||||||
}
|
}
|
||||||
@ -2053,7 +2038,6 @@ static gboolean icvAlarm( gpointer user_data )
|
|||||||
|
|
||||||
CV_IMPL int cvWaitKey( int delay )
|
CV_IMPL int cvWaitKey( int delay )
|
||||||
{
|
{
|
||||||
#ifdef HAVE_GTHREAD
|
|
||||||
if (thread_started && g_thread_self() != window_thread)
|
if (thread_started && g_thread_self() != window_thread)
|
||||||
{
|
{
|
||||||
gboolean expired = true;
|
gboolean expired = true;
|
||||||
@ -2087,7 +2071,6 @@ CV_IMPL int cvWaitKey( int delay )
|
|||||||
return my_last_key;
|
return my_last_key;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
int expired = 0;
|
int expired = 0;
|
||||||
guint timer = 0;
|
guint timer = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user