[gdk-pixbuf] build: Support Windows components-based loader



commit 7386e44bbf42359a71027d108d98afc7e454282d
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Sep 7 18:06:50 2017 +0800

    build: Support Windows components-based loader
    
    There is currently a GDI+ image loader that is within the GDK-Pixbuf
    codebase, which can serve as a basis for improvements to it or for
    moving on to more modern Windows APIs/Frameworks such as Windows
    Imaging Component (WIC).
    
    Provide a Windows-only option to build it with Meson, which will mean
    that when it is used the TIFF and JPEG loaders will not require libtiff
    and libjpeg-turbo/IJG JPEG,  but will use the GDI+ component of Windows
    to deal with these images, along with BMP, GIF, ICO and images.  This
    will also enable the support of EMF and WMF images.  For building this
    set of loaders into the GDK-Pixbuf DLL, pass in 'windows' as a part of
    the loaders passed into builtin_loaders, or pass in 'all' to
    builtin_loaders in conjunction with this option.
    
    This also means that by using this set of GDI+ loaders, we cannot use
    any of the loaders (either in-house or those using the various
    opensource libraries) for these formats, so these loaders will be
    disabled as a result, since the MIME types, extensions and signature
    of these formats are the same in the GDI+ loaders with their respective
    counterparts that are otherwise built.
    
    Note that PNG support still requires libpng, and JPEG2000 support still
    requires libjasper, and in its current state, the TIFF and JPEG and ICO
    (and hence ANI) support that are done by the opensource libraries and/or
    the in-house loaders are still preferred over the GDI+-based ones since
    in the current state they tend to work better, so this is provided as an
    option.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785767

 gdk-pixbuf/meson.build |   51 +++++++++++++++++++++++++++++++++++++++++++++--
 meson.build            |   32 +++++++++++++++++++++++------
 meson_options.txt      |    8 +++++-
 3 files changed, 79 insertions(+), 12 deletions(-)
---
diff --git a/gdk-pixbuf/meson.build b/gdk-pixbuf/meson.build
index 866365c..b8889c0 100644
--- a/gdk-pixbuf/meson.build
+++ b/gdk-pixbuf/meson.build
@@ -4,11 +4,14 @@ subdir('pixops')
 #  - name
 #  - sources
 #  - conditional, otherwise always built
+
+# We need to disable the in-house loaders for BMP, GIF and ICO
+# when enable_native_windows_loaders is true
 loaders = [
   [ 'png', [ 'io-png.c' ], enabled_loaders.contains('png') ],
-  [ 'bmp', [ 'io-bmp.c' ] ],
-  [ 'gif', [ 'io-gif.c', 'io-gif-animation.c' ] ],
-  [ 'ico', [ 'io-ico.c' ] ],
+  [ 'bmp', [ 'io-bmp.c' ], not enable_native_windows_loaders ],
+  [ 'gif', [ 'io-gif.c', 'io-gif-animation.c' ], not enable_native_windows_loaders ],
+  [ 'ico', [ 'io-ico.c' ], not enable_native_windows_loaders ],
   [ 'ani', [ 'io-ani.c', 'io-ani-animation.c' ] ],
   [ 'jpeg', [ 'io-jpeg.c' ], enabled_loaders.contains('jpeg') ],
   [ 'pnm', [ 'io-pnm.c' ] ],
@@ -125,6 +128,30 @@ foreach l: loaders
   endif
 endforeach
 
+# List of formats supported by the native Windows components-based loader(s)
+windows_native_loader_formats = [ 'bmp', 'emf', 'gif', 'ico', 'jpeg', 'tiff', 'wmf' ]
+windows_base_loader_sources = [ 'io-gdip-utils.c', 'io-gdip-animation.c' ]
+
+# Build the loaders using native Windows components as static modules, if requested
+if enable_native_windows_loaders
+  if builtin_loaders.contains('windows') or builtin_all_loaders
+    cflag_for_included_loader = ['-DINCLUDE_gdiplus']
+    included_loaders_cflags += cflag_for_included_loader
+    win_loader_sources = windows_base_loader_sources
+    foreach loader: windows_native_loader_formats
+      win_loader_sources += 'io-gdip-@0@.c'.format(loader)
+    endforeach
+
+    mod = static_library('staticpixbufloader-gdiplus',
+                         win_loader_sources,
+                         dependencies: loaders_deps + gdk_pixbuf_deps,
+                         include_directories: [ root_inc, gdk_pixbuf_inc ],
+                         c_args: common_cflags + gdk_pixbuf_cflags + cflag_for_included_loader)
+
+    included_loaders_deps += declare_dependency(link_with: mod)
+  endif
+endif
+
 # The main gdk-pixbuf shared library
 gdkpixbuf = library('gdk_pixbuf-2.0',
                     gdkpixbuf_sources + gdkpixbuf_enums + gdkpixbuf_marshals,
@@ -165,6 +192,24 @@ foreach l: loaders
   endif
 endforeach
 
+# Build the loaders using native Windows components as dynamic modules, if requested
+if enable_native_windows_loaders
+  if not (builtin_loaders.contains('windows') or builtin_all_loaders)
+    foreach loader: windows_native_loader_formats
+      loader_sources = windows_base_loader_sources + [ 'io-gdip-@0@.c'.format(loader) ]
+
+      mod = shared_module('pixbufloader-gdip-@0@'.format(loader),
+                          loader_sources,
+                          dependencies: loaders_deps + gdk_pixbuf_deps + [ gdkpixbuf_dep ],
+                          include_directories: [ root_inc, gdk_pixbuf_inc ],
+                          c_args: common_cflags + gdk_pixbuf_cflags + cflags,
+                          install: true,
+                          install_dir: gdk_pixbuf_loaderdir)
+      dynamic_loaders += mod.full_path()
+    endforeach
+  endif
+endif
+
 gdkpixbuf_bin = [
   [ 'gdk-pixbuf-csource' ],
   [ 'gdk-pixbuf-pixdata' ],
diff --git a/meson.build b/meson.build
index c8f1638..4d5cf4a 100644
--- a/meson.build
+++ b/meson.build
@@ -227,15 +227,24 @@ if get_option('enable_png')
   endforeach
 endif
 
-if get_option('enable_tiff')
-  tiff_dep = dependency('libtiff-4', required: false)
-  if tiff_dep.found()
-    enabled_loaders += 'tiff'
-    loaders_deps += tiff_dep
-  endif
+# On Windows, check whether we are building the native Windows loaders
+# (it is an "all-or-nothing" option for BMP, EMF, GIF, ICO, JPEG, TIFF and WMF)
+# Note that we currently do not use the native Windows loaders to handle PNG and
+# JPEG2000 images
+if host_system == 'windows'
+  enable_native_windows_loaders = get_option('enable_native_windows_loaders')
+else
+  enable_native_windows_loaders = false
+endif
+
+if enable_native_windows_loaders
+  loaders_deps += cc.find_library('gdiplus')
+  loaders_deps += cc.find_library('ole32')
+  enabled_loaders += 'gdiplus'
 endif
 
-if get_option('enable_jpeg')
+# Don't check and build the jpeg loader if enable_native_windows_loaders is true
+if get_option('enable_jpeg') and not enable_native_windows_loaders
   if cc.has_header('jpeglib.h')
     jpeg_dep = cc.find_library('jpeg', required: false)
     if cc.get_id() == 'msvc' and not jpeg_dep.found()
@@ -253,6 +262,15 @@ if get_option('enable_jpeg')
   endif
 endif
 
+# Don't check and build the tiff loader if enable_native_windows_loaders is true
+if get_option('enable_tiff') and not enable_native_windows_loaders
+  tiff_dep = dependency('libtiff-4', required: false)
+  if tiff_dep.found()
+    enabled_loaders += 'tiff'
+    loaders_deps += tiff_dep
+  endif
+endif
+
 jasper_extra_cflags = []
 
 if get_option('enable_jasper')
diff --git a/meson_options.txt b/meson_options.txt
index ba65246..8faab66 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,11 +3,11 @@ option('enable_png',
        type: 'boolean',
        value: true)
 option('enable_tiff',
-       description: 'Enable TIFF loader (requires libtiff)',
+       description: 'Enable TIFF loader (requires libtiff), disabled on Windows if 
"enable_native_windows_loaders" is used',
        type: 'boolean',
        value: true)
 option('enable_jpeg',
-       description: 'Enable JPEG loader (requires libjpeg)',
+       description: 'Enable JPEG loader (requires libjpeg), disabled on Windows if 
"enable_native_windows_loaders" is used',
        type: 'boolean',
        value: true)
 option('enable_jasper',
@@ -34,3 +34,7 @@ option('enable_relocatable',
        description: 'Whether to enable application bundle relocation support',
        type: 'boolean',
        value: false)
+option('enable_native_windows_loaders',
+       description: 'Use Windows system components to handle BMP, EMF, GIF, ICO, JPEG, TIFF and WMF images, 
overriding enable_jpeg and enable_tiff.  To build this into gdk-pixbuf, pass in windows" with the other 
loaders to build in or use "all" with the builtin_loaders option',
+       type: 'boolean',
+       value: false)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]