#include "gdk/gdktextureprivate.h"
+/* {{{ Pixbuf helpers */
+
static GdkPixbuf *
load_from_stream (GdkPixbufLoader *loader,
GInputStream *stream,
gdk_pixbuf_loader_set_size (loader, width, height);
}
-GdkPixbuf *
+static GdkPixbuf *
_gdk_pixbuf_new_from_stream_at_scale (GInputStream *stream,
int width,
int height,
return pixbuf;
}
-GdkPixbuf *
-_gdk_pixbuf_new_from_stream (GInputStream *stream,
- GCancellable *cancellable,
- GError **error)
-{
- return _gdk_pixbuf_new_from_stream_scaled (stream, 0, cancellable, error);
-}
-
-GdkPixbuf *
+static GdkPixbuf *
_gdk_pixbuf_new_from_resource_at_scale (const char *resource_path,
int width,
int height,
g_object_unref (stream);
return pixbuf;
-
}
+/* }}} */
+/* {{{ Symbolic processing */
+
static GdkPixbuf *
load_symbolic_svg (const char *escaped_file_data,
int width,
char *escaped_file_data;
/* Fetch size from the original icon */
- {
- GInputStream *stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL);
- GdkPixbuf *reference = gdk_pixbuf_new_from_stream (stream, NULL, error);
+ GInputStream *stream = g_memory_input_stream_new_from_data (file_data, file_len, NULL);
+ GdkPixbuf *reference = gdk_pixbuf_new_from_stream (stream, NULL, error);
- g_object_unref (stream);
+ g_object_unref (stream);
- if (!reference)
- return NULL;
+ if (!reference)
+ return NULL;
- icon_width = gdk_pixbuf_get_width (reference);
- icon_height = gdk_pixbuf_get_height (reference);
- g_object_unref (reference);
- }
+ icon_width = gdk_pixbuf_get_width (reference);
+ icon_height = gdk_pixbuf_get_height (reference);
+ g_object_unref (reference);
escaped_file_data = g_base64_encode ((guchar *) file_data, file_len);
icon_width_str = g_strdup_printf ("%d", icon_width);
return pixbuf;
}
-GdkPixbuf *
-gtk_make_symbolic_pixbuf_from_resource (const char *path,
- int width,
- int height,
- double scale,
- GError **error)
+static GdkPixbuf *
+make_symbolic_pixbuf_from_resource (const char *path,
+ int width,
+ int height,
+ double scale,
+ GError **error)
{
GBytes *bytes;
const char *data;
return pixbuf;
}
-GdkPixbuf *
-gtk_make_symbolic_pixbuf_from_path (const char *path,
- int width,
- int height,
- double scale,
- GError **error)
+static GdkPixbuf *
+make_symbolic_pixbuf_from_path (const char *path,
+ int width,
+ int height,
+ double scale,
+ GError **error)
{
char *data;
gsize size;
}
static GdkPixbuf *
-gtk_make_symbolic_pixbuf_from_file (GFile *file,
- int width,
- int height,
- double scale,
- GError **error)
+make_symbolic_pixbuf_from_file (GFile *file,
+ int width,
+ int height,
+ double scale,
+ GError **error)
{
char *data;
gsize size;
return pixbuf;
}
+/* }}} */
+/* {{{ Texture API */
+
+GdkTexture *
+gdk_texture_new_from_stream_at_scale (GInputStream *stream,
+ int width,
+ int height,
+ gboolean aspect,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GdkPixbuf *pixbuf;
+ GdkTexture *texture = NULL;
+
+ pixbuf = _gdk_pixbuf_new_from_stream_at_scale (stream, width, height, aspect, cancellable, error);
+ if (pixbuf)
+ {
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+ }
+
+ return texture;
+}
+
+GdkTexture *
+gdk_texture_new_from_stream (GInputStream *stream,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GdkPixbuf *pixbuf;
+ GdkTexture *texture = NULL;
+
+ pixbuf = _gdk_pixbuf_new_from_stream_scaled (stream, 0, cancellable, error);
+ if (pixbuf)
+ {
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+ }
+
+ return texture;
+}
+
+GdkTexture *
+gdk_texture_new_from_resource_at_scale (const char *path,
+ int width,
+ int height,
+ gboolean preserve_aspect,
+ GError **error)
+{
+ GdkPixbuf *pixbuf;
+ GdkTexture *texture = NULL;
+
+ pixbuf = _gdk_pixbuf_new_from_resource_at_scale (path, width, height, preserve_aspect, error);
+ if (pixbuf)
+ {
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+ }
+
+ return texture;
+}
+
+/* }}} */
+/* {{{ Symbolic texture API */
+
+GdkTexture *
+gdk_texture_new_from_path_symbolic (const char *path,
+ int width,
+ int height,
+ double scale,
+ GError **error)
+{
+ GdkPixbuf *pixbuf;
+ GdkTexture *texture = NULL;
+
+ pixbuf = make_symbolic_pixbuf_from_path (path, width, height, scale, error);
+ if (pixbuf)
+ {
+ texture = gdk_texture_new_for_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+ }
+
+ return texture;
+}
+
GdkTexture *
gtk_load_symbolic_texture_from_resource (const char *path)
{
}
GdkTexture *
-gtk_make_symbolic_texture_from_resource (const char *path,
- int width,
- int height,
- double scale,
- GError **error)
+gdk_texture_new_from_resource_symbolic (const char *path,
+ int width,
+ int height,
+ double scale,
+ GError **error)
{
GdkPixbuf *pixbuf;
GdkTexture *texture = NULL;
- pixbuf = gtk_make_symbolic_pixbuf_from_resource (path, width, height, scale, error);
+ pixbuf = make_symbolic_pixbuf_from_resource (path, width, height, scale, error);
if (pixbuf)
{
texture = gdk_texture_new_for_pixbuf (pixbuf);
if (stream == NULL)
return NULL;
- pixbuf = _gdk_pixbuf_new_from_stream (stream, NULL, NULL);
+ pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, NULL);
g_object_unref (stream);
if (pixbuf == NULL)
return NULL;
}
GdkTexture *
-gtk_make_symbolic_texture_from_file (GFile *file,
- int width,
- int height,
- double scale,
- GError **error)
+gdk_texture_new_from_file_symbolic (GFile *file,
+ int width,
+ int height,
+ double scale,
+ GError **error)
{
GdkPixbuf *pixbuf;
GdkTexture *texture;
- pixbuf = gtk_make_symbolic_pixbuf_from_file (file, width, height, scale, error);
+ pixbuf = make_symbolic_pixbuf_from_file (file, width, height, scale, error);
texture = gdk_texture_new_for_pixbuf (pixbuf);
g_object_unref (pixbuf);
return texture;
}
+/* }}} */
+/* {{{ Scaled paintable API */
+
typedef struct {
int scale_factor;
} LoaderData;
return paintable;
}
+
+/* }}} */
+
+/* vim:set foldmethod=marker expandtab: */
G_BEGIN_DECLS
-GdkPixbuf *_gdk_pixbuf_new_from_stream (GInputStream *stream,
+GdkPixbuf *gtk_make_symbolic_pixbuf_from_data (const char *data,
+ gsize len,
+ int width,
+ int height,
+ double scale,
+ const char *debug_output_to,
+ GError **error);
+
+GdkTexture *gdk_texture_new_from_stream (GInputStream *stream,
GCancellable *cancellable,
GError **error);
-GdkPixbuf *_gdk_pixbuf_new_from_stream_at_scale (GInputStream *stream,
+GdkTexture *gdk_texture_new_from_stream_at_scale (GInputStream *stream,
int width,
int height,
gboolean aspect,
GCancellable *cancellable,
GError **error);
-GdkPixbuf *_gdk_pixbuf_new_from_resource_at_scale (const char *resource_path,
+GdkTexture *gdk_texture_new_from_resource_at_scale (const char *path,
int width,
int height,
- gboolean preserve_aspect,
+ gboolean aspect,
GError **error);
-GdkPixbuf *gtk_make_symbolic_pixbuf_from_data (const char *data,
- gsize len,
+
+GdkTexture *gdk_texture_new_from_path_symbolic (const char *path,
int width,
int height,
double scale,
- const char *debug_output_to,
GError **error);
-GdkPixbuf *gtk_make_symbolic_pixbuf_from_path (const char *path,
+GdkTexture *gdk_texture_new_from_file_symbolic (GFile *file,
int width,
int height,
double scale,
GError **error);
-GdkPixbuf *gtk_make_symbolic_pixbuf_from_resource (const char *path,
+GdkTexture *gdk_texture_new_from_resource_symbolic (const char *path,
int width,
int height,
double scale,
GError **error);
+
GdkTexture *gtk_load_symbolic_texture_from_file (GFile *file);
-GdkTexture *gtk_make_symbolic_texture_from_file (GFile *file,
- int width,
- int height,
- double scale,
- GError **error);
GdkTexture *gtk_load_symbolic_texture_from_resource (const char *data);
-GdkTexture *gtk_make_symbolic_texture_from_resource (const char *path,
- int width,
- int height,
- double scale,
- GError **error);
+
GdkPaintable *gdk_paintable_new_from_path_scaled (const char *path,
int scale_factor);
GdkPaintable *gdk_paintable_new_from_resource_scaled (const char *path,
int scale_factor);
G_END_DECLS
-
{
if (icon->is_svg)
{
- GdkPixbuf *source_pixbuf;
-
if (gtk_icon_paintable_is_symbolic (icon))
- source_pixbuf = gtk_make_symbolic_pixbuf_from_resource (icon->filename,
+ icon->texture = gdk_texture_new_from_resource_symbolic (icon->filename,
pixel_size, pixel_size,
icon->desired_scale,
&load_error);
else
- source_pixbuf = _gdk_pixbuf_new_from_resource_at_scale (icon->filename,
+ icon->texture = gdk_texture_new_from_resource_at_scale (icon->filename,
pixel_size, pixel_size,
TRUE, &load_error);
- if (source_pixbuf)
- {
- icon->texture = gdk_texture_new_for_pixbuf (source_pixbuf);
- g_object_unref (source_pixbuf);
- }
}
else
icon->texture = gdk_texture_new_from_resource (icon->filename);
{
if (icon->is_svg)
{
- GdkPixbuf *source_pixbuf;
-
if (gtk_icon_paintable_is_symbolic (icon))
- source_pixbuf = gtk_make_symbolic_pixbuf_from_path (icon->filename,
+ icon->texture = gdk_texture_new_from_path_symbolic (icon->filename,
pixel_size, pixel_size,
icon->desired_scale,
&load_error);
GFile *file = g_file_new_for_path (icon->filename);
GInputStream *stream = G_INPUT_STREAM (g_file_read (file, NULL, &load_error));
- g_object_unref (file);
if (stream)
{
- source_pixbuf = _gdk_pixbuf_new_from_stream_at_scale (stream,
+ icon->texture = gdk_texture_new_from_stream_at_scale (stream,
pixel_size, pixel_size,
TRUE, NULL,
&load_error);
g_object_unref (stream);
}
- else
- source_pixbuf = NULL;
- }
- if (source_pixbuf)
- {
- icon->texture = gdk_texture_new_for_pixbuf (source_pixbuf);
- g_object_unref (source_pixbuf);
+
+ g_object_unref (file);
}
}
else
else
{
GInputStream *stream;
- GdkPixbuf *source_pixbuf;
g_assert (icon->loadable);
- stream = g_loadable_icon_load (icon->loadable,
- pixel_size,
- NULL, NULL,
- &load_error);
+ stream = g_loadable_icon_load (icon->loadable, pixel_size, NULL, NULL, &load_error);
if (stream)
{
/* SVG icons are a special case - we just immediately scale them
* to the desired size
*/
if (icon->is_svg)
- {
- source_pixbuf = _gdk_pixbuf_new_from_stream_at_scale (stream,
- pixel_size, pixel_size,
- TRUE, NULL,
- &load_error);
- }
+ icon->texture = gdk_texture_new_from_stream_at_scale (stream,
+ pixel_size, pixel_size,
+ TRUE, NULL,
+ &load_error);
else
- source_pixbuf = _gdk_pixbuf_new_from_stream (stream,
- NULL, &load_error);
+ icon->texture = gdk_texture_new_from_stream (stream, NULL, &load_error);
+
g_object_unref (stream);
- if (source_pixbuf)
- {
- icon->texture = gdk_texture_new_for_pixbuf (source_pixbuf);
- g_object_unref (source_pixbuf);
- }
}
}