From 1c45ceae1d06cd3df7063e2644140b647b6d0acd Mon Sep 17 00:00:00 2001 From: martin Date: Mon, 13 Apr 2020 19:15:32 +0000 Subject: [PATCH] split out gdk code from gtk2 code, disable gtk2 by default (#544) * split gtk2 code out from gdk code * remove gtk2 module from default build --- CMakeLists.txt | 2 +- src/modules/gdk/CMakeLists.txt | 39 ++++++++ src/modules/gdk/Makefile | 74 +++++++++++++++ src/modules/gdk/configure | 82 +++++++++++++++++ src/modules/gdk/factory.c | 92 +++++++++++++++++++ src/modules/{gtk2 => gdk}/filter_rescale.c | 0 src/modules/{gtk2 => gdk}/filter_rescale.yml | 0 src/modules/{gtk2 => gdk}/have_mmx.S | 0 src/modules/{gtk2 => gdk}/pixops.c | 0 src/modules/{gtk2 => gdk}/pixops.h | 0 src/modules/{gtk2 => gdk}/producer_pango.c | 1 - src/modules/{gtk2 => gdk}/producer_pango.yml | 0 src/modules/{gtk2 => gdk}/producer_pixbuf.c | 0 src/modules/{gtk2 => gdk}/producer_pixbuf.yml | 0 .../{gtk2 => gdk}/scale_line_22_yuv_mmx.S | 0 src/modules/gtk2/deprecated | 0 20 files changed, 291 insertions(+), 151 deletions(-) create mode 100644 src/modules/gdk/CMakeLists.txt create mode 100644 src/modules/gdk/Makefile create mode 100755 src/modules/gdk/configure create mode 100644 src/modules/gdk/factory.c rename src/modules/{gtk2 => gdk}/filter_rescale.c (100%) rename src/modules/{gtk2 => gdk}/filter_rescale.yml (100%) rename src/modules/{gtk2 => gdk}/have_mmx.S (100%) rename src/modules/{gtk2 => gdk}/pixops.c (100%) rename src/modules/{gtk2 => gdk}/pixops.h (100%) rename src/modules/{gtk2 => gdk}/producer_pango.c (99%) rename src/modules/{gtk2 => gdk}/producer_pango.yml (100%) rename src/modules/{gtk2 => gdk}/producer_pixbuf.c (100%) rename src/modules/{gtk2 => gdk}/producer_pixbuf.yml (100%) rename src/modules/{gtk2 => gdk}/scale_line_22_yuv_mmx.S (100%) create mode 100644 src/modules/gtk2/deprecated diff --git a/CMakeLists.txt b/CMakeLists.txt index 54afeceda..e25ca68b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ set(modules src/modules/decklink src/modules/frei0r src/modules/feeds - src/modules/gtk2 + src/modules/gdk src/modules/kdenlive src/modules/motion_est src/modules/normalize diff --git a/src/modules/gdk/CMakeLists.txt b/src/modules/gdk/CMakeLists.txt new file mode 100644 index 000000000..b7bdb2c24 --- /dev/null +++ b/src/modules/gdk/CMakeLists.txt @@ -0,0 +1,39 @@ +set(mltgdk_src factory.c) +set(mltgdk_lib mlt m Threads::Threads) +set(mltgdk_def "") + + +pkg_check_modules(GdkPixbuf IMPORTED_TARGET gdk-pixbuf-2.0 REQUIRED) +if(TARGET PkgConfig::GdkPixbuf) + list(APPEND mltgdk_src producer_pixbuf.c pixops.c filter_rescale.c) + list(APPEND mltgdk_lib PkgConfig::GdkPixbuf) + list(APPEND mltgdk_def USE_PIXBUF) + message(STATUS "${mltgdk_lib}") +else() + message(FATAL_ERROR "Failed to find gdk pixbuf") +endif() + +pkg_check_modules(pango IMPORTED_TARGET pango) +if(TARGET PkgConfig::pango) + pkg_check_modules(fontconfig IMPORTED_TARGET fontconfig) + if(TARGET PkgConfig::fontconfig) + list(APPEND mltgdk_src producer_pango.c) + list(APPEND mltgdk_lib PkgConfig::pango PkgConfig::fontconfig) + list(APPEND mltgdk_def USE_PANGO) + endif() +endif() + +pkg_check_modules(libexif IMPORTED_TARGET libexif) +if(TARGET PkgConfig::libexif) + list(APPEND mltgdk_lib PkgConfig::libexif) + list(APPEND mltgdk_def USE_EXIF) +endif() +# Only for MMX but not x86_64: deprecated +# list(APPEND mltgdk_src have_mmx.S scale_line_22_yuv_mmx.S) +add_library(mltgdk MODULE ${mltgdk_src}) +target_link_libraries(mltgdk ${mltgdk_lib}) +target_compile_definitions(mltgdk PRIVATE ${mltgdk_def}) +install(TARGETS mltgdk LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/mlt) +file(GLOB yml *.yml) +install(FILES ${yml} + DESTINATION ${CMAKE_INSTALL_DATADIR}/mlt/gdk) diff --git a/src/modules/gdk/Makefile b/src/modules/gdk/Makefile new file mode 100644 index 000000000..2e3018976 --- /dev/null +++ b/src/modules/gdk/Makefile @@ -0,0 +1,74 @@ +include ../../../config.mak +include config.mak + +CFLAGS := -I../.. $(CFLAGS) + +LDFLAGS := -L../../framework -lmlt -lpthread -lm $(LDFLAGS) + +TARGET = ../libmltgdk$(LIBSUF) + +OBJS = factory.o + +ifdef USE_PIXBUF +OBJS += producer_pixbuf.o pixops.o filter_rescale.o +CFLAGS += $(shell pkg-config $(PKGCONFIG_PREFIX) --cflags gdk-pixbuf-2.0) +LDFLAGS += $(shell pkg-config $(PKGCONFIG_PREFIX) --libs gdk-pixbuf-2.0) +endif + +ifdef USE_EXIF +CFLAGS += $(EXIFCXXFLAGS) +LDFLAGS += $(EXIFLIBS) +endif + +ifdef MMX_FLAGS +ifndef ARCH_X86_64 +ASM_OBJS = have_mmx.o scale_line_22_yuv_mmx.o +endif +endif + +ifdef USE_PANGO +OBJS += producer_pango.o +CFLAGS += $(shell pkg-config $(PKGCONFIG_PREFIX) --cflags pangoft2) +CFLAGS += $(shell pkg-config $(PKGCONFIG_PREFIX) --cflags-only-I freetype2 | awk '{for (i=1; i<=NF; i++) $$i=sprintf("%s/freetype", $$i); print}') +LDFLAGS += $(shell pkg-config $(PKGCONFIG_PREFIX) --libs pangoft2) +ifeq ($(targetos),Darwin) +LDFLAGS += -liconv +endif +ifeq ($(targetos),FreeBSD) +LDFLAGS += -liconv +endif +ifeq ($(targetos), MinGW) +LDFLAGS += -liconv +endif +endif + +SRCS := $(OBJS:.o=.c) + +all: $(TARGET) + +$(TARGET): $(OBJS) $(ASM_OBJS) + $(CC) $(SHFLAGS) -o $@ $(OBJS) $(ASM_OBJS) $(LDFLAGS) + +have_mmx.o: + $(CC) -o $@ -c have_mmx.S + +scale_line_22_yuv_mmx.o: scale_line_22_yuv_mmx.S + $(CC) -o $@ -c scale_line_22_yuv_mmx.S + +depend: $(SRCS) + $(CC) -MM $(CFLAGS) $^ 1>.depend + +distclean: clean + rm -f .depend + +clean: + rm -f $(OBJS) $(ASM_OBJS) $(TARGET) + +install: all + install -m 755 $(TARGET) "$(DESTDIR)$(moduledir)" + install -d "$(DESTDIR)$(mltdatadir)/gdk" + install -m 644 *.yml "$(DESTDIR)$(mltdatadir)/gdk" + +ifneq ($(wildcard .depend),) +include .depend +endif diff --git a/src/modules/gdk/configure b/src/modules/gdk/configure new file mode 100755 index 000000000..07003b049 --- /dev/null +++ b/src/modules/gdk/configure @@ -0,0 +1,82 @@ +#!/bin/sh + +if [ "$help" = "1" ] +then + cat << EOF +GDK options: + + --gdk-prefix=path - Override the gdk prefix for pkg-config + +EOF + +else + pkgconfig_prefix= + for i in "$@" + do + case $i in + --gdk-prefix=* ) pkgconfig_prefix="${i#--gdk-prefix=}" ;; + esac + done + [ "$pkgconfig_prefix" != "" ] && pkgconfig_prefix="--define-variable=prefix=\"$pkgconfig_prefix\"" + + pkg-config $pkgconfig_prefix gdk-pixbuf-2.0 2> /dev/null + disable_pixbuf=$? + + pkg-config $pkgconfig_prefix gdk-pixbuf-2.0 pangoft2 2> /dev/null + disable_pango=$? + + if [ "$disable_pixbuf" != 0 -a "$disable_pango" != "0" ] + then + echo "- GDK components not found: disabling" + touch ../disable-gdk + exit 0 + fi + + echo > config.mak + + if [ "$disable_pixbuf" = "0" ] + then + echo "CFLAGS += -DUSE_PIXBUF" >> config.mak + echo "USE_PIXBUF=1" >> config.mak + else + echo "- pixbuf not found: pixbuf loader and rescaler disabled" + fi + + if [ "$disable_pango" = "0" ] + then + echo "CFLAGS += -DUSE_PANGO" >> config.mak + echo "USE_PANGO=1" >> config.mak + else + echo "- pango not found: pango titler disabled" + fi + + [ "$pkgconfig_prefix" != "" ] && echo "PKGCONFIG_PREFIX=$pkgconfig_prefix" >> config.mak + + pkg-config --exists 'libexif' + if [ $? -eq 0 ] + then + echo "- Libexif found, enabling auto rotate" + echo "USE_EXIF=1" >> config.mak + echo EXIFCXXFLAGS=$(pkg-config --cflags libexif ) >> config.mak + echo EXIFCXXFLAGS += -DUSE_EXIF >> config.mak + echo EXIFLIBS=$(pkg-config --libs libexif) >> config.mak + elif [ -d "$exif_libdir" -a -d "$exif_includedir" ] + then + # test if we have a libexif + if [ -f "$exif_libdir/exif-data.h" ] + then + echo "- Libexif found, enabling auto rotate" + echo "USE_EXIF=1" >> config.mak + echo EXIFCXXFLAGS=-I$exif_includedir >> config.mak + echo EXIFCXXFLAGS += -DUSE_EXIF >> config.mak + echo EXIFLIBS=-L$exif_libdir lexif >> config.mak + else + echo "- Libexif not found, disabling exif features (auto rotate)" + fi + else + echo "- Libexif not found, disabling exif features (auto rotate)" + fi + + exit 0 +fi + diff --git a/src/modules/gdk/factory.c b/src/modules/gdk/factory.c new file mode 100644 index 000000000..94b89466e --- /dev/null +++ b/src/modules/gdk/factory.c @@ -0,0 +1,92 @@ +/* + * factory.c -- the factory method interfaces + * Copyright (C) 2003-2014 Meltytech, LLC + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#ifdef USE_PIXBUF +extern mlt_producer producer_pixbuf_init( char *filename ); +extern mlt_filter filter_rescale_init( mlt_profile profile, char *arg ); +#endif + +#ifdef USE_PANGO +extern mlt_producer producer_pango_init( const char *filename ); +#endif + +static void initialise( ) +{ + static int init = 0; + if ( init == 0 ) + { + init = 1; + if ( getenv("MLT_PIXBUF_PRODUCER_CACHE") ) + { + int n = atoi( getenv("MLT_PIXBUF_PRODUCER_CACHE" ) ); + mlt_service_cache_set_size( NULL, "pixbuf.image", n ); + mlt_service_cache_set_size( NULL, "pixbuf.alpha", n ); + mlt_service_cache_set_size( NULL, "pixbuf.pixbuf", n ); + } + if ( getenv("MLT_PANGO_PRODUCER_CACHE") ) + { + int n = atoi( getenv("MLT_PANGO_PRODUCER_CACHE" ) ); + mlt_service_cache_set_size( NULL, "pango.image", n ); + } + } +} + +void *create_service( mlt_profile profile, mlt_service_type type, const char *id, char *arg ) +{ + initialise( ); + +#ifdef USE_PIXBUF + if ( !strcmp( id, "pixbuf" ) ) + return producer_pixbuf_init( arg ); +#endif + +#ifdef USE_PANGO + if ( !strcmp( id, "pango" ) ) + return producer_pango_init( arg ); +#endif + +#ifdef USE_PIXBUF + if ( !strcmp( id, "gtkrescale" ) ) + return filter_rescale_init( profile, arg ); +#endif + + return NULL; +} + +static mlt_properties metadata( mlt_service_type type, const char *id, void *data ) +{ + char file[ PATH_MAX ]; + snprintf( file, PATH_MAX, "%s/gtk2/%s", mlt_environment( "MLT_DATA" ), (char*) data ); + return mlt_properties_parse_yaml( file ); +} + +MLT_REPOSITORY +{ + MLT_REGISTER( filter_type, "gtkrescale", create_service ); + MLT_REGISTER( producer_type, "pango", create_service ); + MLT_REGISTER( producer_type, "pixbuf", create_service ); + + MLT_REGISTER_METADATA( filter_type, "gtkrescale", metadata, "filter_rescale.yml" ); + MLT_REGISTER_METADATA( producer_type, "pango", metadata, "producer_pango.yml" ); + MLT_REGISTER_METADATA( producer_type, "pixbuf", metadata, "producer_pixbuf.yml" ); +} diff --git a/src/modules/gtk2/filter_rescale.c b/src/modules/gdk/filter_rescale.c similarity index 100% rename from src/modules/gtk2/filter_rescale.c rename to src/modules/gdk/filter_rescale.c diff --git a/src/modules/gtk2/filter_rescale.yml b/src/modules/gdk/filter_rescale.yml similarity index 100% rename from src/modules/gtk2/filter_rescale.yml rename to src/modules/gdk/filter_rescale.yml diff --git a/src/modules/gtk2/have_mmx.S b/src/modules/gdk/have_mmx.S similarity index 100% rename from src/modules/gtk2/have_mmx.S rename to src/modules/gdk/have_mmx.S diff --git a/src/modules/gtk2/pixops.c b/src/modules/gdk/pixops.c similarity index 100% rename from src/modules/gtk2/pixops.c rename to src/modules/gdk/pixops.c diff --git a/src/modules/gtk2/pixops.h b/src/modules/gdk/pixops.h similarity index 100% rename from src/modules/gtk2/pixops.h rename to src/modules/gdk/pixops.h diff --git a/src/modules/gtk2/producer_pango.c b/src/modules/gdk/producer_pango.c similarity index 99% rename from src/modules/gtk2/producer_pango.c rename to src/modules/gdk/producer_pango.c index b3e11b942..ead6e9123 100644 --- a/src/modules/gtk2/producer_pango.c +++ b/src/modules/gdk/producer_pango.c @@ -172,7 +172,6 @@ mlt_producer producer_pango_init( const char *filename ) pthread_mutex_lock( &pango_mutex ); if ( fontmap == NULL ) fontmap = (PangoFT2FontMap*) pango_ft2_font_map_new(); - g_type_init(); pthread_mutex_unlock( &pango_mutex ); producer->get_frame = producer_get_frame; diff --git a/src/modules/gtk2/producer_pango.yml b/src/modules/gdk/producer_pango.yml similarity index 100% rename from src/modules/gtk2/producer_pango.yml rename to src/modules/gdk/producer_pango.yml diff --git a/src/modules/gtk2/producer_pixbuf.c b/src/modules/gdk/producer_pixbuf.c similarity index 100% rename from src/modules/gtk2/producer_pixbuf.c rename to src/modules/gdk/producer_pixbuf.c diff --git a/src/modules/gtk2/producer_pixbuf.yml b/src/modules/gdk/producer_pixbuf.yml similarity index 100% rename from src/modules/gtk2/producer_pixbuf.yml rename to src/modules/gdk/producer_pixbuf.yml diff --git a/src/modules/gtk2/scale_line_22_yuv_mmx.S b/src/modules/gdk/scale_line_22_yuv_mmx.S similarity index 100% rename from src/modules/gtk2/scale_line_22_yuv_mmx.S rename to src/modules/gdk/scale_line_22_yuv_mmx.S diff --git a/src/modules/gtk2/deprecated b/src/modules/gtk2/deprecated new file mode 100644 index 000000000..e69de29bb