[gtk/wip/otte/paintable: 58/62] cssimage: Add gtk_css_image_is_invalid()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/paintable: 58/62] cssimage: Add gtk_css_image_is_invalid()
- Date: Sat, 17 Feb 2018 23:38:54 +0000 (UTC)
commit 5c87c2aa5f3c94f6ae5ec571d7801965ec6f45a5
Author: Benjamin Otte <otte redhat com>
Date: Sat Feb 17 20:31:14 2018 +0100
cssimage: Add gtk_css_image_is_invalid()
Use that instead of hacks to guess when an image is considered invalid.
Also add a GtkCssImageInvalid that implements the behavior of invalid
images according to the CSS spec so thjat image implementations can
refer to that image.
gtk/gtkcssimage.c | 19 +++++++++++
gtk/gtkcssimagefallback.c | 5 +--
gtk/gtkcssimageinvalid.c | 74 +++++++++++++++++++++++++++++++++++++++++
gtk/gtkcssimageinvalidprivate.h | 57 +++++++++++++++++++++++++++++++
gtk/gtkcssimageprivate.h | 3 ++
gtk/gtkcssimageurl.c | 21 ++++++++++--
gtk/meson.build | 1 +
7 files changed, 173 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index fffa13e95b..9160333228 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -96,6 +96,12 @@ gtk_css_image_real_transition (GtkCssImage *start,
return _gtk_css_image_cross_fade_new (start, end, progress);
}
+static gboolean
+gtk_css_image_real_is_invalid (GtkCssImage *image)
+{
+ return FALSE;
+}
+
static gboolean
gtk_css_image_real_is_dynamic (GtkCssImage *image)
{
@@ -118,6 +124,7 @@ _gtk_css_image_class_init (GtkCssImageClass *klass)
klass->compute = gtk_css_image_real_compute;
klass->equal = gtk_css_image_real_equal;
klass->transition = gtk_css_image_real_transition;
+ klass->is_invalid = gtk_css_image_real_is_invalid;
klass->is_dynamic = gtk_css_image_real_is_dynamic;
klass->get_dynamic_image = gtk_css_image_real_get_dynamic_image;
}
@@ -279,6 +286,18 @@ gtk_css_image_snapshot (GtkCssImage *image,
klass->snapshot (image, snapshot, width, height);
}
+gboolean
+gtk_css_image_is_invalid (GtkCssImage *image)
+{
+ GtkCssImageClass *klass;
+
+ g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), FALSE);
+
+ klass = GTK_CSS_IMAGE_GET_CLASS (image);
+
+ return klass->is_invalid (image);
+}
+
gboolean
gtk_css_image_is_dynamic (GtkCssImage *image)
{
diff --git a/gtk/gtkcssimagefallback.c b/gtk/gtkcssimagefallback.c
index 7bd310c855..75b3d4dd9a 100644
--- a/gtk/gtkcssimagefallback.c
+++ b/gtk/gtkcssimagefallback.c
@@ -154,10 +154,7 @@ gtk_css_image_fallback_compute (GtkCssImage *image,
style,
parent_style);
- /* Assume that failing to load an image leaves a 0x0 surface image */
- if (GTK_IS_CSS_IMAGE_SURFACE (copy->images[i]) &&
- _gtk_css_image_get_width (copy->images[i]) == 0 &&
- _gtk_css_image_get_height (copy->images[i]) == 0)
+ if (gtk_css_image_is_invalid (copy->images[i]))
continue;
if (copy->used < 0)
diff --git a/gtk/gtkcssimageinvalid.c b/gtk/gtkcssimageinvalid.c
new file mode 100644
index 0000000000..4a9dcbd551
--- /dev/null
+++ b/gtk/gtkcssimageinvalid.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2011 Red Hat Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include "config.h"
+
+#include "gtkcssimageinvalidprivate.h"
+
+G_DEFINE_TYPE (GtkCssImageInvalid, gtk_css_image_invalid, GTK_TYPE_CSS_IMAGE)
+
+static void
+gtk_css_image_invalid_snapshot (GtkCssImage *image,
+ GtkSnapshot *snapshot,
+ double width,
+ double height)
+{
+}
+
+static gboolean
+gtk_css_image_invalid_equal (GtkCssImage *image1,
+ GtkCssImage *image2)
+{
+ return TRUE;
+}
+
+static void
+gtk_css_image_invalid_print (GtkCssImage *image,
+ GString *string)
+{
+ g_string_append (string, "none /* invalid image */");
+}
+
+static gboolean
+gtk_css_image_invalid_is_invalid (GtkCssImage *image)
+{
+ return TRUE;
+}
+
+static void
+gtk_css_image_invalid_class_init (GtkCssImageInvalidClass *klass)
+{
+ GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
+
+ image_class->snapshot = gtk_css_image_invalid_snapshot;
+ image_class->print = gtk_css_image_invalid_print;
+ image_class->equal = gtk_css_image_invalid_equal;
+ image_class->is_invalid = gtk_css_image_invalid_is_invalid;
+}
+
+static void
+gtk_css_image_invalid_init (GtkCssImageInvalid *image_invalid)
+{
+}
+
+GtkCssImage *
+gtk_css_image_invalid_new (void)
+{
+ return g_object_new (GTK_TYPE_CSS_IMAGE_INVALID, NULL);
+}
diff --git a/gtk/gtkcssimageinvalidprivate.h b/gtk/gtkcssimageinvalidprivate.h
new file mode 100644
index 0000000000..0e7fb93036
--- /dev/null
+++ b/gtk/gtkcssimageinvalidprivate.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2011 Red Hat Inc.
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_CSS_IMAGE_INVALID_PRIVATE_H__
+#define __GTK_CSS_IMAGE_INVALID_PRIVATE_H__
+
+#include "gtk/gtkcssimageprivate.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_CSS_IMAGE_INVALID (gtk_css_image_invalid_get_type ())
+#define GTK_CSS_IMAGE_INVALID(obj) (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_CSS_IMAGE_INVALID,
GtkCssImageInvalid))
+#define GTK_CSS_IMAGE_INVALID_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_CSS_IMAGE_INVALID,
GtkCssImageInvalidClass))
+#define GTK_IS_CSS_IMAGE_INVALID(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_CSS_IMAGE_INVALID))
+#define GTK_IS_CSS_IMAGE_INVALID_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_CSS_IMAGE_INVALID))
+#define GTK_CSS_IMAGE_INVALID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_CSS_IMAGE_INVALID,
GtkCssImageInvalidClass))
+
+typedef struct _GtkCssImageInvalid GtkCssImageInvalid;
+typedef struct _GtkCssImageInvalidClass GtkCssImageInvalidClass;
+
+struct _GtkCssImageInvalid
+{
+ GtkCssImage parent;
+
+ GFile *file; /* the file we're loading from */
+ GtkCssImage *loaded_image; /* the actual image we render */
+};
+
+struct _GtkCssImageInvalidClass
+{
+ GtkCssImageClass parent_class;
+};
+
+GType gtk_css_image_invalid_get_type (void) G_GNUC_CONST;
+
+GtkCssImage * gtk_css_image_invalid_new (void);
+
+
+G_END_DECLS
+
+#endif /* __GTK_CSS_IMAGE_INVALID_PRIVATE_H__ */
diff --git a/gtk/gtkcssimageprivate.h b/gtk/gtkcssimageprivate.h
index 53f92e7b2c..ca2dafa56a 100644
--- a/gtk/gtkcssimageprivate.h
+++ b/gtk/gtkcssimageprivate.h
@@ -75,6 +75,8 @@ struct _GtkCssImageClass
GtkSnapshot *snapshot,
double width,
double height);
+ /* is this image to be considered invalid (see https://drafts.csswg.org/css-images-4/#invalid-image for
details) */
+ gboolean (* is_invalid) (GtkCssImage *image);
/* does this image change based on timestamp? (optional) */
gboolean (* is_dynamic) (GtkCssImage *image);
/* get image for given timestamp or @image when not dynamic (optional) */
@@ -117,6 +119,7 @@ void gtk_css_image_snapshot (GtkCssImage *
GtkSnapshot *snapshot,
double width,
double height);
+gboolean gtk_css_image_is_invalid (GtkCssImage *image);
gboolean gtk_css_image_is_dynamic (GtkCssImage *image);
GtkCssImage * gtk_css_image_get_dynamic_image (GtkCssImage *image,
gint64 monotonic_time);
diff --git a/gtk/gtkcssimageurl.c b/gtk/gtkcssimageurl.c
index ee6323f1d4..690afc473d 100644
--- a/gtk/gtkcssimageurl.c
+++ b/gtk/gtkcssimageurl.c
@@ -22,6 +22,8 @@
#include <string.h>
#include "gtkcssimageurlprivate.h"
+
+#include "gtkcssimageinvalidprivate.h"
#include "gtkcssimagesurfaceprivate.h"
#include "gtkstyleproviderprivate.h"
@@ -68,11 +70,15 @@ gtk_css_image_url_load_image (GtkCssImageUrl *url,
"Error loading image '%s': %s", uri, local_error->message);
g_free (uri);
}
+
+ url->loaded_image = gtk_css_image_invalid_new ();
+ }
+ else
+ {
+ url->loaded_image = gtk_css_image_surface_new (texture);
+ g_object_unref (texture);
}
- url->loaded_image = gtk_css_image_surface_new (texture);
-
- g_clear_object (&texture);
g_clear_error (&local_error);
return url->loaded_image;
@@ -145,6 +151,14 @@ gtk_css_image_url_equal (GtkCssImage *image1,
return g_file_equal (url1->file, url2->file);
}
+static gboolean
+gtk_css_image_url_is_invalid (GtkCssImage *image)
+{
+ GtkCssImageUrl *url = GTK_CSS_IMAGE_URL (image);
+
+ return gtk_css_image_is_invalid (gtk_css_image_url_load_image (url, NULL));
+}
+
static gboolean
gtk_css_image_url_parse (GtkCssImage *image,
GtkCssParser *parser)
@@ -192,6 +206,7 @@ _gtk_css_image_url_class_init (GtkCssImageUrlClass *klass)
image_class->parse = gtk_css_image_url_parse;
image_class->print = gtk_css_image_url_print;
image_class->equal = gtk_css_image_url_equal;
+ image_class->is_invalid = gtk_css_image_url_is_invalid;
object_class->dispose = gtk_css_image_url_dispose;
}
diff --git a/gtk/meson.build b/gtk/meson.build
index 9559906dc0..fe068efa09 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -46,6 +46,7 @@ gtk_private_sources = files([
'gtkcssimagecrossfade.c',
'gtkcssimagefallback.c',
'gtkcssimageicontheme.c',
+ 'gtkcssimageinvalid.c',
'gtkcssimagelinear.c',
'gtkcssimageradial.c',
'gtkcssimagerecolor.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]