/* cached-image.c generated by valac 0.56.19, the Vala compiler
 * generated from cached-image.vala, do not modify */

/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
 *
 * Copyright (C) 2012 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Michael Terry <michael.terry@canonical.com>
 */

#include <gtk/gtk.h>
#include <glib-object.h>
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <cairo-gobject.h>
#include <gdk/gdk.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define TYPE_CACHED_IMAGE (cached_image_get_type ())
#define CACHED_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CACHED_IMAGE, CachedImage))
#define CACHED_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CACHED_IMAGE, CachedImageClass))
#define IS_CACHED_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CACHED_IMAGE))
#define IS_CACHED_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CACHED_IMAGE))
#define CACHED_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CACHED_IMAGE, CachedImageClass))

typedef struct _CachedImage CachedImage;
typedef struct _CachedImageClass CachedImageClass;
typedef struct _CachedImagePrivate CachedImagePrivate;
enum  {
	CACHED_IMAGE_0_PROPERTY,
	CACHED_IMAGE_NUM_PROPERTIES
};
static GParamSpec* cached_image_properties[CACHED_IMAGE_NUM_PROPERTIES];
#define _g_hash_table_unref0(var) ((var == NULL) ? NULL : (var = (g_hash_table_unref (var), NULL)))
#define _cairo_surface_destroy0(var) ((var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL)))

struct _CachedImage {
	GtkImage parent_instance;
	CachedImagePrivate * priv;
};

struct _CachedImageClass {
	GtkImageClass parent_class;
};

static gpointer cached_image_parent_class = NULL;
static GHashTable* cached_image_surface_table;
static GHashTable* cached_image_surface_table = NULL;
VALA_EXTERN gint _scale_factor;

VALA_EXTERN GType cached_image_get_type (void) G_GNUC_CONST ;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CachedImage, g_object_unref)
VALA_EXTERN cairo_surface_t* cached_image_get_cached_surface (GdkPixbuf* pixbuf);
static void _g_object_unref0_ (gpointer var);
static void _cairo_surface_destroy0_ (gpointer var);
static void cached_image_update_image (CachedImage* self,
                                GdkPixbuf* pixbuf);
VALA_EXTERN CachedImage* cached_image_new (GdkPixbuf* pixbuf);
VALA_EXTERN CachedImage* cached_image_construct (GType object_type,
                                     GdkPixbuf* pixbuf);
VALA_EXTERN void cached_image_set_pixbuf (CachedImage* self,
                              GdkPixbuf* pixbuf);
static void cached_image_finalize (GObject * obj);
static GType cached_image_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
_g_object_unref0_ (gpointer var)
{
#line 27 "../src/cached-image.vala"
	(var == NULL) ? NULL : (var = (g_object_unref (var), NULL));
#line 104 "cached-image.c"
}

static void
_cairo_surface_destroy0_ (gpointer var)
{
#line 27 "../src/cached-image.vala"
	(var == NULL) ? NULL : (var = (cairo_surface_destroy (var), NULL));
#line 112 "cached-image.c"
}

static gpointer
_cairo_surface_reference0 (gpointer self)
{
#line 29 "../src/cached-image.vala"
	return self ? cairo_surface_reference (self) : NULL;
#line 120 "cached-image.c"
}

static gpointer
_g_object_ref0 (gpointer self)
{
#line 33 "../src/cached-image.vala"
	return self ? g_object_ref (self) : NULL;
#line 128 "cached-image.c"
}

cairo_surface_t*
cached_image_get_cached_surface (GdkPixbuf* pixbuf)
{
	GHashTable* _tmp0_;
	cairo_surface_t* surface = NULL;
	GHashTable* _tmp4_;
	gconstpointer _tmp5_;
	cairo_surface_t* _tmp6_;
	cairo_surface_t* _tmp7_;
	cairo_surface_t* result;
#line 24 "../src/cached-image.vala"
	g_return_val_if_fail (pixbuf != NULL, NULL);
#line 26 "../src/cached-image.vala"
	_tmp0_ = cached_image_surface_table;
#line 26 "../src/cached-image.vala"
	if (_tmp0_ == NULL) {
#line 147 "cached-image.c"
		GHashFunc _tmp1_;
		GEqualFunc _tmp2_;
		GHashTable* _tmp3_;
#line 27 "../src/cached-image.vala"
		_tmp1_ = g_direct_hash;
#line 27 "../src/cached-image.vala"
		_tmp2_ = g_direct_equal;
#line 27 "../src/cached-image.vala"
		_tmp3_ = g_hash_table_new_full (_tmp1_, _tmp2_, _g_object_unref0_, _cairo_surface_destroy0_);
#line 27 "../src/cached-image.vala"
		_g_hash_table_unref0 (cached_image_surface_table);
#line 27 "../src/cached-image.vala"
		cached_image_surface_table = _tmp3_;
#line 161 "cached-image.c"
	}
#line 29 "../src/cached-image.vala"
	_tmp4_ = cached_image_surface_table;
#line 29 "../src/cached-image.vala"
	_tmp5_ = g_hash_table_lookup (_tmp4_, pixbuf);
#line 29 "../src/cached-image.vala"
	_tmp6_ = _cairo_surface_reference0 ((cairo_surface_t*) _tmp5_);
#line 29 "../src/cached-image.vala"
	surface = _tmp6_;
#line 30 "../src/cached-image.vala"
	_tmp7_ = surface;
#line 30 "../src/cached-image.vala"
	if (_tmp7_ == NULL) {
#line 175 "cached-image.c"
		cairo_surface_t* _tmp8_;
		GHashTable* _tmp9_;
		GdkPixbuf* _tmp10_;
		cairo_surface_t* _tmp11_;
		cairo_surface_t* _tmp12_;
#line 32 "../src/cached-image.vala"
		_tmp8_ = gdk_cairo_surface_create_from_pixbuf (pixbuf, _scale_factor, NULL);
#line 32 "../src/cached-image.vala"
		_cairo_surface_destroy0 (surface);
#line 32 "../src/cached-image.vala"
		surface = _tmp8_;
#line 33 "../src/cached-image.vala"
		_tmp9_ = cached_image_surface_table;
#line 33 "../src/cached-image.vala"
		_tmp10_ = _g_object_ref0 (pixbuf);
#line 33 "../src/cached-image.vala"
		_tmp11_ = surface;
#line 33 "../src/cached-image.vala"
		_tmp12_ = _cairo_surface_reference0 (_tmp11_);
#line 33 "../src/cached-image.vala"
		g_hash_table_insert (_tmp9_, _tmp10_, _tmp12_);
#line 197 "cached-image.c"
	}
#line 35 "../src/cached-image.vala"
	result = surface;
#line 35 "../src/cached-image.vala"
	return result;
#line 203 "cached-image.c"
}

static void
cached_image_update_image (CachedImage* self,
                           GdkPixbuf* pixbuf)
{
#line 38 "../src/cached-image.vala"
	g_return_if_fail (self != NULL);
#line 40 "../src/cached-image.vala"
	if (pixbuf != NULL) {
#line 214 "cached-image.c"
		cairo_surface_t* _tmp0_;
		cairo_surface_t* _tmp1_;
#line 42 "../src/cached-image.vala"
		_tmp0_ = cached_image_get_cached_surface (pixbuf);
#line 42 "../src/cached-image.vala"
		_tmp1_ = _tmp0_;
#line 42 "../src/cached-image.vala"
		g_object_set ((GtkImage*) self, "surface", _tmp1_, NULL);
#line 42 "../src/cached-image.vala"
		_cairo_surface_destroy0 (_tmp1_);
#line 225 "cached-image.c"
	} else {
#line 46 "../src/cached-image.vala"
		g_object_set ((GtkImage*) self, "surface", NULL, NULL);
#line 47 "../src/cached-image.vala"
		pixbuf = NULL;
#line 231 "cached-image.c"
	}
}

CachedImage*
cached_image_construct (GType object_type,
                        GdkPixbuf* pixbuf)
{
	CachedImage * self = NULL;
#line 51 "../src/cached-image.vala"
	self = (CachedImage*) g_object_new (object_type, NULL);
#line 53 "../src/cached-image.vala"
	cached_image_update_image (self, pixbuf);
#line 51 "../src/cached-image.vala"
	return self;
#line 246 "cached-image.c"
}

CachedImage*
cached_image_new (GdkPixbuf* pixbuf)
{
#line 51 "../src/cached-image.vala"
	return cached_image_construct (TYPE_CACHED_IMAGE, pixbuf);
#line 254 "cached-image.c"
}

void
cached_image_set_pixbuf (CachedImage* self,
                         GdkPixbuf* pixbuf)
{
#line 56 "../src/cached-image.vala"
	g_return_if_fail (self != NULL);
#line 58 "../src/cached-image.vala"
	cached_image_update_image (self, pixbuf);
#line 265 "cached-image.c"
}

static void
cached_image_class_init (CachedImageClass * klass,
                         gpointer klass_data)
{
#line 20 "../src/cached-image.vala"
	cached_image_parent_class = g_type_class_peek_parent (klass);
#line 20 "../src/cached-image.vala"
	G_OBJECT_CLASS (klass)->finalize = cached_image_finalize;
#line 276 "cached-image.c"
}

static void
cached_image_instance_init (CachedImage * self,
                            gpointer klass)
{
}

static void
cached_image_finalize (GObject * obj)
{
	CachedImage * self;
#line 20 "../src/cached-image.vala"
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_CACHED_IMAGE, CachedImage);
#line 20 "../src/cached-image.vala"
	G_OBJECT_CLASS (cached_image_parent_class)->finalize (obj);
#line 293 "cached-image.c"
}

static GType
cached_image_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (CachedImageClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) cached_image_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (CachedImage), 0, (GInstanceInitFunc) cached_image_instance_init, NULL };
	GType cached_image_type_id;
	cached_image_type_id = g_type_register_static (gtk_image_get_type (), "CachedImage", &g_define_type_info, 0);
	return cached_image_type_id;
}

GType
cached_image_get_type (void)
{
	static volatile gsize cached_image_type_id__once = 0;
	if (g_once_init_enter (&cached_image_type_id__once)) {
		GType cached_image_type_id;
		cached_image_type_id = cached_image_get_type_once ();
		g_once_init_leave (&cached_image_type_id__once, cached_image_type_id);
	}
	return cached_image_type_id__once;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

