[libshumate] vector: Hide behind a build flag
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libshumate] vector: Hide behind a build flag
- Date: Wed, 10 Nov 2021 10:46:07 +0000 (UTC)
commit ea8609d14eed7c33dc70adc8516e7ee3a1df519a
Author: James Westman <james jwestman net>
Date: Mon Nov 8 12:17:35 2021 -0600
vector: Hide behind a build flag
Added a build option, -Dvector_renderer, to enable or disable the
experimental vector tile renderer. It defaults to false.
demos/org.gnome.Shumate.Demo.json | 3 ++-
demos/shumate-demo-window.c | 33 ++++++++++++++++--------------
meson.build | 2 --
meson_options.txt | 4 ++++
shumate/meson.build | 41 +++++++++++++++++++++++--------------
shumate/shumate-vector-style.c | 43 +++++++++++++++++++++++++++++++++++++++
shumate/shumate-vector-style.h | 4 ++++
tests/meson.build | 11 +++++++---
8 files changed, 105 insertions(+), 36 deletions(-)
---
diff --git a/demos/org.gnome.Shumate.Demo.json b/demos/org.gnome.Shumate.Demo.json
index 7e013fd..4077f51 100644
--- a/demos/org.gnome.Shumate.Demo.json
+++ b/demos/org.gnome.Shumate.Demo.json
@@ -55,7 +55,8 @@
"buildsystem" : "meson",
"config-opts" : [
"-Ddemos=true",
- "-Dgtk_doc=false"
+ "-Dgtk_doc=false",
+ "-Dvector_renderer=true"
],
"builddir" : true,
"sources" : [
diff --git a/demos/shumate-demo-window.c b/demos/shumate-demo-window.c
index 794979d..5afd5d7 100644
--- a/demos/shumate-demo-window.c
+++ b/demos/shumate-demo-window.c
@@ -144,22 +144,25 @@ shumate_demo_window_init (ShumateDemoWindow *self)
bytes = g_resources_lookup_data ("/org/gnome/Shumate/Demo/styles/map-style.json",
G_RESOURCE_LOOKUP_FLAGS_NONE, NULL);
style_json = g_bytes_get_data (bytes, NULL);
- if (!(style = shumate_vector_style_create (style_json, &error)))
+ if (shumate_vector_style_is_supported ())
{
- g_warning ("Failed to create vector map style: %s", error->message);
- g_clear_error (&error);
- }
- else
- {
- ShumateMapSource *map_source = SHUMATE_MAP_SOURCE (shumate_network_tile_source_new_vector_full (
- "vector-tiles",
- "Vector Tiles",
- "© OpenStreetMap contributors", NULL, 0, 5, 512,
- SHUMATE_MAP_PROJECTION_MERCATOR,
- "https://jwestman.pages.gitlab.gnome.org/vector-tile-test-data/world_overview/#Z#/#X#/#Y#.pbf",
- style
- ));
- shumate_map_source_registry_add (self->registry, map_source);
+ if (!(style = shumate_vector_style_create (style_json, &error)))
+ {
+ g_warning ("Failed to create vector map style: %s", error->message);
+ g_clear_error (&error);
+ }
+ else
+ {
+ ShumateMapSource *map_source = SHUMATE_MAP_SOURCE (shumate_network_tile_source_new_vector_full (
+ "vector-tiles",
+ "Vector Tiles",
+ "© OpenStreetMap contributors", NULL, 0, 5, 512,
+ SHUMATE_MAP_PROJECTION_MERCATOR,
+ "https://jwestman.pages.gitlab.gnome.org/vector-tile-test-data/world_overview/#Z#/#X#/#Y#.pbf",
+ style
+ ));
+ shumate_map_source_registry_add (self->registry, map_source);
+ }
}
viewport = shumate_map_get_viewport (self->map);
diff --git a/meson.build b/meson.build
index dd421d8..8cd9a08 100644
--- a/meson.build
+++ b/meson.build
@@ -69,8 +69,6 @@ cairo_dep = dependency('cairo', version: cairo_req)
sqlite_dep = dependency('sqlite3', version: sqlite_req)
libsoup_dep = dependency('libsoup-2.4', version: libsoup_req)
gtk_dep = dependency('gtk4')
-json_glib_dep = dependency('json-glib-1.0', version: json_glib_req)
-protobuf_c_dep = dependency('libprotobuf-c')
introspection_dep = dependency('gobject-introspection-1.0', version: introspection_req, required: false)
vapigen_dep = dependency('vapigen', version: vala_req, required: false)
diff --git a/meson_options.txt b/meson_options.txt
index f7a6938..238aef7 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -12,3 +12,7 @@ option('gtk_doc',
option('demos',
type: 'boolean', value: false,
description: 'Build demonstration programs')
+
+option('vector_renderer',
+ type: 'boolean', value: false,
+ description: 'Build the experimental vector tile renderer')
diff --git a/shumate/meson.build b/shumate/meson.build
index 08acdc7..c8816a0 100644
--- a/shumate/meson.build
+++ b/shumate/meson.build
@@ -62,19 +62,6 @@ libshumate_sources = [
'shumate-tile.c',
'shumate-vector-style.c',
'shumate-viewport.c',
-
- 'vector/shumate-vector-background-layer.c',
- 'vector/shumate-vector-expression.c',
- 'vector/shumate-vector-expression-interpolate.c',
- 'vector/shumate-vector-expression-filter.c',
- 'vector/shumate-vector-expression-literal.c',
- 'vector/shumate-vector-fill-layer.c',
- 'vector/shumate-vector-layer.c',
- 'vector/shumate-vector-line-layer.c',
- 'vector/shumate-vector-render-scope.c',
- 'vector/shumate-vector-utils.c',
- 'vector/shumate-vector-value.c',
- 'vector/vector_tile.pb-c.c',
]
libshumate_deps = [
@@ -86,8 +73,6 @@ libshumate_deps = [
cairo_dep,
sqlite_dep,
libsoup_dep,
- json_glib_dep,
- protobuf_c_dep,
]
libshumate_c_args = [
@@ -156,6 +141,32 @@ install_headers(
)
)
+if get_option('vector_renderer')
+ libshumate_sources += [
+ 'vector/shumate-vector-background-layer.c',
+ 'vector/shumate-vector-expression.c',
+ 'vector/shumate-vector-expression-interpolate.c',
+ 'vector/shumate-vector-expression-filter.c',
+ 'vector/shumate-vector-expression-literal.c',
+ 'vector/shumate-vector-fill-layer.c',
+ 'vector/shumate-vector-layer.c',
+ 'vector/shumate-vector-line-layer.c',
+ 'vector/shumate-vector-render-scope.c',
+ 'vector/shumate-vector-utils.c',
+ 'vector/shumate-vector-value.c',
+ 'vector/vector_tile.pb-c.c',
+ ]
+
+ libshumate_deps += [
+ dependency('json-glib-1.0', version: json_glib_req),
+ dependency('libprotobuf-c'),
+ ]
+
+ libshumate_c_args += [
+ '-DSHUMATE_VECTOR_RENDERER',
+ ]
+endif
+
libshumate_lib = library(
package_string,
libshumate_sources,
diff --git a/shumate/shumate-vector-style.c b/shumate/shumate-vector-style.c
index 6726a5c..600f4a6 100644
--- a/shumate/shumate-vector-style.c
+++ b/shumate/shumate-vector-style.c
@@ -15,12 +15,17 @@
* License along with this library; if not, see <https://www.gnu.org/licenses/>.
*/
+
+#ifdef SHUMATE_VECTOR_RENDERER
#include <json-glib/json-glib.h>
#include <cairo/cairo.h>
#include "vector/shumate-vector-render-scope-private.h"
#include "vector/shumate-vector-utils-private.h"
#include "vector/shumate-vector-layer-private.h"
+#endif
+
+#include <glib-object.h>
#include "shumate-vector-style.h"
struct _ShumateVectorStyle
@@ -67,6 +72,26 @@ shumate_vector_style_create (const char *style_json, GError **error)
}
+/**
+ * shumate_vector_style_is_supported:
+ *
+ * Checks whether libshumate was compiled with vector tile support. If it was
+ * not, vector styles cannot be created or used.
+ *
+ * Returns: %TRUE if libshumate was compiled with `-Dvector_renderer=true` or
+ * %FALSE if it was not
+ */
+gboolean
+shumate_vector_style_is_supported ()
+{
+#ifdef SHUMATE_VECTOR_RENDERER
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
+
+
static void
shumate_vector_style_finalize (GObject *object)
{
@@ -141,6 +166,7 @@ shumate_vector_style_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
+#ifdef SHUMATE_VECTOR_RENDERER
ShumateVectorStyle *self = (ShumateVectorStyle *)initable;
g_autoptr(JsonNode) node = NULL;
JsonNode *layers_node;
@@ -183,6 +209,17 @@ shumate_vector_style_initable_init (GInitable *initable,
}
return TRUE;
+#else
+ g_set_error (error,
+ SHUMATE_STYLE_ERROR,
+ SHUMATE_STYLE_ERROR_SUPPORT_OMITTED,
+ "Libshumate was compiled without support for vector tiles, so a "
+ "ShumateVectorStyle may not be constructed. You can fix this "
+ "by compiling libshumate with `-Dvector_renderer=true` or by "
+ "checking `shumate_vector_style_is_supported ()` before trying "
+ "to construct a ShumateVectorStyle.");
+ return FALSE;
+#endif
}
@@ -216,6 +253,7 @@ shumate_vector_style_get_style_json (ShumateVectorStyle *self)
}
+#ifdef SHUMATE_VECTOR_RENDERER
static GdkTexture *
texture_new_for_surface (cairo_surface_t *surface)
{
@@ -240,6 +278,7 @@ texture_new_for_surface (cairo_surface_t *surface)
return texture;
}
+#endif
/**
@@ -253,6 +292,7 @@ texture_new_for_surface (cairo_surface_t *surface)
GdkTexture *
shumate_vector_style_render (ShumateVectorStyle *self, int texture_size, GBytes *tile_data, double
zoom_level)
{
+#ifdef SHUMATE_VECTOR_RENDERER
ShumateVectorRenderScope scope;
GdkTexture *texture;
cairo_surface_t *surface;
@@ -281,6 +321,9 @@ shumate_vector_style_render (ShumateVectorStyle *self, int texture_size, GBytes
vector_tile__tile__free_unpacked (scope.tile, NULL);
return texture;
+#else
+ g_return_val_if_reached (NULL);
+#endif
}
/**
diff --git a/shumate/shumate-vector-style.h b/shumate/shumate-vector-style.h
index 908f0ac..a2e0885 100644
--- a/shumate/shumate-vector-style.h
+++ b/shumate/shumate-vector-style.h
@@ -37,6 +37,7 @@ GQuark shumate_style_error_quark (void);
* @SHUMATE_STYLE_ERROR_MALFORMED_STYLE: A JSON node in the style has the wrong type (e.g. an object where
there should be an array).
* @SHUMATE_STYLE_ERROR_UNSUPPORTED_LAYER: An unsupported layer type was encountered.
* @SHUMATE_STYLE_ERROR_INVALID_EXPRESSION: An invalid or unrecognized expression was encountered.
+ * @SHUMATE_STYLE_ERROR_SUPPORT_OMITTED: Libshumate was compiled without vector tile support.
*
* Error codes in the [error@StyleError] domain.
*/
@@ -45,6 +46,7 @@ typedef enum {
SHUMATE_STYLE_ERROR_MALFORMED_STYLE,
SHUMATE_STYLE_ERROR_UNSUPPORTED_LAYER,
SHUMATE_STYLE_ERROR_INVALID_EXPRESSION,
+ SHUMATE_STYLE_ERROR_SUPPORT_OMITTED,
} ShumateStyleError;
@@ -52,10 +54,12 @@ typedef enum {
G_DECLARE_FINAL_TYPE (ShumateVectorStyle, shumate_vector_style, SHUMATE, VECTOR_STYLE, GObject)
+gboolean shumate_vector_style_is_supported ();
ShumateVectorStyle *shumate_vector_style_create (const char *style_json, GError **error);
const char *shumate_vector_style_get_style_json (ShumateVectorStyle *self);
GdkTexture *shumate_vector_style_render (ShumateVectorStyle *self, int texture_size, GBytes *tile_data,
double zoom_level);
+
G_END_DECLS
diff --git a/tests/meson.build b/tests/meson.build
index 9cbb99d..1ed5838 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -15,12 +15,17 @@ tests = [
'marker-layer',
'memory-cache',
'network-tile-source',
- 'vector-expression',
- 'vector-style',
- 'vector-value',
'viewport',
]
+if get_option('vector_renderer')
+ tests += [
+ 'vector-expression',
+ 'vector-style',
+ 'vector-value',
+ ]
+endif
+
subdir('data')
test_utils_sources = [
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]