[cogl/wip/cogl-1.14: 23/50] Adds CoglError api



commit 134c1977a06723d4dee69d65d6b58f5e3f747f06
Author: Robert Bragg <robert linux intel com>
Date:   Fri Aug 31 19:28:27 2012 +0100

    Adds CoglError api
    
    Although we use GLib internally in Cogl we would rather not leak GLib
    api through Cogl's own api, except through explicitly namespaced
    cogl_glib_ / cogl_gtype_ feature apis.
    
    One of the benefits we see to not leaking GLib through Cogl's public API
    is that documentation for Cogl won't need to first introduce the Glib
    API to newcomers, thus hopefully lowering the barrier to learning Cogl.
    
    This patch provides a Cogl specific typedef for reporting runtime errors
    which by no coincidence matches the typedef for GError exactly.  If Cogl
    is built with --enable-glib (default) then developers can even safely
    assume that a CoglError is a GError under the hood.
    
    This patch also enforces a consistent policy for when NULL is passed as
    an error argument and an error is thrown. In this case we log the error
    and abort the application, instead of silently ignoring it. In common
    cases where nothing has been implemented to handle a particular error
    and/or where applications are just printing the error and aborting
    themselves then this saves some typing. This also seems more consistent
    with language based exceptions which usually cause a program to abort if
    they are not explicitly caught (which passing a non-NULL error signifies
    in this case)
    
    Since this policy for NULL error pointers is stricter than the standard
    GError convention, there is a clear note in the documentation to warn
    developers that are used to using the GError api.
    
    Reviewed-by: Neil Roberts <neil linux intel com>
    
    (cherry picked from commit b068d5ea09ab32c37e8c965fc8582c85d1b2db46)
    
    Note: Since we can't change the Cogl 1.x api the patch was changed to
    not rename _error_quark() functions to be _error_domain() functions and
    although it's a bit ugly, instead of providing our own CoglError type
    that's compatible with GError we simply #define CoglError to GError
    unless Cogl is built with glib disabled.
    
    FIXME: This patch currently causes the cogl_error_get_type() api to be
    dropped since the CoglError enum has been replaced with a
    CoglSystemError enum. We should decided whether we consider this
    a minor enough api change to allow.

 cogl/Makefile.am                                   |    3 +
 cogl/cogl-bitmap-pixbuf.c                          |   97 ++++++-----
 cogl/cogl-bitmap-private.h                         |    4 +-
 cogl/cogl-bitmap.c                                 |    6 +-
 cogl/cogl-bitmap.h                                 |   12 +-
 cogl/cogl-blend-string.c                           |   77 +++++-----
 cogl/cogl-blend-string.h                           |    2 +-
 cogl/cogl-context-private.h                        |    2 +-
 cogl/cogl-context.c                                |   26 ++-
 cogl/cogl-context.h                                |    4 +-
 cogl/cogl-display.c                                |    4 +-
 cogl/cogl-display.h                                |    4 +-
 cogl/cogl-driver.h                                 |    4 +-
 cogl/cogl-error-private.h                          |   48 ++++++
 cogl/cogl-error.c                                  |  109 ++++++++++++
 cogl/cogl-error.h                                  |  175 ++++++++++++++++++++
 cogl/cogl-framebuffer.c                            |   13 +-
 cogl/cogl-framebuffer.h                            |    6 +-
 cogl/cogl-gles2-context.c                          |   27 ++--
 cogl/cogl-gles2.h                                  |   12 +-
 cogl/cogl-internal.h                               |    2 +-
 cogl/cogl-material-compat.c                        |    8 +-
 cogl/cogl-material-compat.h                        |   17 +-
 cogl/cogl-pipeline-layer-state.c                   |   28 +--
 cogl/cogl-pipeline-layer-state.h                   |    8 +-
 cogl/cogl-pipeline-state.c                         |   28 +--
 cogl/cogl-pipeline-state.h                         |    8 +-
 cogl/cogl-renderer.c                               |   23 ++--
 cogl/cogl-renderer.h                               |   11 +-
 cogl/cogl-sdl.c                                    |    2 +-
 cogl/cogl-sdl.h                                    |    6 +-
 cogl/cogl-texture-2d-private.h                     |    2 +-
 cogl/cogl-texture-2d-sliced.c                      |   15 +-
 cogl/cogl-texture-2d-sliced.h                      |    4 +-
 cogl/cogl-texture-2d.c                             |   74 +++++----
 cogl/cogl-texture-2d.h                             |   16 +-
 cogl/cogl-texture-3d.c                             |   41 +++---
 cogl/cogl-texture-3d.h                             |   16 +-
 cogl/cogl-texture-rectangle.c                      |   59 ++++----
 cogl/cogl-texture-rectangle.h                      |   12 +-
 cogl/cogl-texture.c                                |    4 +-
 cogl/cogl-texture.h                                |    8 +-
 cogl/cogl-types.h                                  |   30 ++--
 cogl/cogl-wayland-server.h                         |    4 +-
 cogl/cogl-xlib-renderer-private.h                  |    2 +-
 cogl/cogl-xlib-renderer.c                          |    7 +-
 cogl/cogl.c                                        |    8 +-
 cogl/cogl.h                                        |    1 +
 cogl/cogl.symbols                                  |   14 +-
 cogl/cogl2-compatibility.c                         |    4 +-
 cogl/driver/gl/cogl-framebuffer-gl-private.h       |    2 +-
 cogl/driver/gl/cogl-framebuffer-gl.c               |   15 +-
 cogl/driver/gl/gl/cogl-driver-gl.c                 |   11 +-
 cogl/driver/gl/gles/cogl-driver-gles.c             |    2 +-
 cogl/winsys/cogl-texture-pixmap-x11.c              |    9 +-
 cogl/winsys/cogl-texture-pixmap-x11.h              |    8 +-
 cogl/winsys/cogl-winsys-egl-android.c              |   12 +-
 cogl/winsys/cogl-winsys-egl-gdl.c                  |   26 ++--
 cogl/winsys/cogl-winsys-egl-kms.c                  |   37 ++--
 cogl/winsys/cogl-winsys-egl-null.c                 |   12 +-
 cogl/winsys/cogl-winsys-egl-private.h              |   10 +-
 cogl/winsys/cogl-winsys-egl-wayland.c              |   19 +-
 cogl/winsys/cogl-winsys-egl-x11.c                  |   19 +-
 cogl/winsys/cogl-winsys-egl.c                      |   31 ++--
 cogl/winsys/cogl-winsys-glx.c                      |   61 ++++----
 cogl/winsys/cogl-winsys-private.h                  |   14 +-
 cogl/winsys/cogl-winsys-sdl.c                      |   19 +-
 cogl/winsys/cogl-winsys-sdl2.c                     |   22 ++--
 cogl/winsys/cogl-winsys-stub.c                     |    8 +-
 cogl/winsys/cogl-winsys-wgl.c                      |   26 ++--
 cogl/winsys/cogl-winsys.c                          |    2 +-
 .../cogl-2.0-experimental-docs.xml.in              |    1 +
 .../cogl-2.0-experimental-sections.txt             |   12 ++-
 examples/android/hello/jni/main.c                  |    2 +-
 examples/cogl-crate.c                              |    2 +-
 examples/cogl-gles2-context.c                      |    4 +-
 examples/cogl-gles2-gears.c                        |    4 +-
 examples/cogl-hello.c                              |    2 +-
 examples/cogl-info.c                               |    2 +-
 examples/cogl-msaa.c                               |    6 +-
 examples/cogl-sdl-hello.c                          |    2 +-
 examples/cogl-sdl2-hello.c                         |    2 +-
 examples/cogl-x11-foreign.c                        |    2 +-
 examples/cogl-x11-tfp.c                            |    2 +-
 examples/cogland.c                                 |    6 +-
 tests/conform/test-blend-strings.c                 |    4 +-
 tests/conform/test-gles2-context.c                 |   12 +-
 tests/conform/test-just-vertex-shader.c            |    4 +-
 tests/conform/test-multitexture.c                  |    2 +-
 tests/conform/test-pipeline-user-matrix.c          |    2 +-
 tests/conform/test-point-sprite.c                  |    2 +-
 tests/conform/test-sub-texture.c                   |    9 +-
 tests/conform/test-texture-3d.c                    |    2 +-
 tests/conform/test-utils.c                         |    2 +-
 94 files changed, 955 insertions(+), 595 deletions(-)
---
diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index 0a80204..571d221 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -125,6 +125,7 @@ cogl_experimental_h = \
 	$(srcdir)/cogl2-experimental.h		\
 	$(srcdir)/cogl2-compatibility.h		\
 	$(srcdir)/cogl-version.h		\
+	$(srcdir)/cogl-error.h			\
 	$(NULL)
 
 cogl_nodist_experimental_h = \
@@ -388,6 +389,8 @@ cogl_sources_c = \
 	$(srcdir)/cogl-gles2-context-private.h		\
 	$(srcdir)/cogl-gles2-context.c			\
 	$(srcdir)/cogl-framebuffer-gl-private.h		\
+	$(srcdir)/cogl-error-private.h			\
+	$(srcdir)/cogl-error.c				\
 	$(NULL)
 
 if USE_GLIB
diff --git a/cogl/cogl-bitmap-pixbuf.c b/cogl/cogl-bitmap-pixbuf.c
index ba31c56..0af32b1 100644
--- a/cogl/cogl-bitmap-pixbuf.c
+++ b/cogl/cogl-bitmap-pixbuf.c
@@ -30,6 +30,7 @@
 #include "cogl-bitmap-private.h"
 #include "cogl-context-private.h"
 #include "cogl-private.h"
+#include "cogl-error-private.h"
 
 #include <string.h>
 
@@ -59,7 +60,7 @@ _cogl_bitmap_get_size_from_file (const char *filename,
 CoglBitmap *
 _cogl_bitmap_from_file (CoglContext *ctx,
                         const char *filename,
-			GError **error)
+			CoglError **error)
 {
   CFURLRef url;
   CGImageSourceRef image_source;
@@ -83,10 +84,10 @@ _cogl_bitmap_from_file (CoglContext *ctx,
   if (image_source == NULL)
     {
       /* doesn't exist, not readable, etc. */
-      g_set_error_literal (error,
-                           COGL_BITMAP_ERROR,
-                           COGL_BITMAP_ERROR_FAILED,
-                           g_strerror (save_errno));
+      _cogl_set_error_literal (error,
+                               COGL_BITMAP_ERROR,
+                               COGL_BITMAP_ERROR_FAILED,
+                               g_strerror (save_errno));
       return NULL;
     }
 
@@ -97,10 +98,10 @@ _cogl_bitmap_from_file (CoglContext *ctx,
   if (type == NULL)
     {
       CFRelease (image_source);
-      g_set_error_literal (error,
-                           COGL_BITMAP_ERROR,
-                           COGL_BITMAP_ERROR_UNKNOWN_TYPE,
-                           "Unknown image type");
+      _cogl_set_error_literal (error,
+                               COGL_BITMAP_ERROR,
+                               COGL_BITMAP_ERROR_UNKNOWN_TYPE,
+                               "Unknown image type");
       return NULL;
     }
 
@@ -115,10 +116,10 @@ _cogl_bitmap_from_file (CoglContext *ctx,
     {
       /* incomplete or corrupt */
       CFRelease (image);
-      g_set_error_literal (error,
-                           COGL_BITMAP_ERROR,
-                           COGL_BITMAP_ERROR_CORRUPT_IMAGE,
-                           "Image has zero width or height");
+      _cogl_set_error_literal (error,
+                               COGL_BITMAP_ERROR,
+                               COGL_BITMAP_ERROR_CORRUPT_IMAGE,
+                               "Image has zero width or height");
       return NULL;
     }
 
@@ -174,24 +175,28 @@ _cogl_bitmap_get_size_from_file (const char *filename,
 CoglBitmap *
 _cogl_bitmap_from_file (CoglContext *ctx,
                         const char *filename,
-			GError **error)
+			CoglError **error)
 {
   static CoglUserDataKey pixbuf_key;
-  GdkPixbuf        *pixbuf;
-  CoglBool          has_alpha;
-  GdkColorspace     color_space;
-  CoglPixelFormat   pixel_format;
-  int               width;
-  int               height;
-  int               rowstride;
-  int               bits_per_sample;
-  int               n_channels;
-  CoglBitmap       *bmp;
+  GdkPixbuf *pixbuf;
+  CoglBool has_alpha;
+  GdkColorspace color_space;
+  CoglPixelFormat pixel_format;
+  int width;
+  int height;
+  int rowstride;
+  int bits_per_sample;
+  int n_channels;
+  CoglBitmap *bmp;
+  GError *glib_error = NULL;
 
   /* Load from file using GdkPixbuf */
-  pixbuf = gdk_pixbuf_new_from_file (filename, error);
+  pixbuf = gdk_pixbuf_new_from_file (filename, &glib_error);
   if (pixbuf == NULL)
-    return FALSE;
+    {
+      _cogl_propogate_gerror (error, glib_error);
+      return FALSE;
+    }
 
   /* Get pixbuf properties */
   has_alpha       = gdk_pixbuf_get_has_alpha (pixbuf);
@@ -308,7 +313,7 @@ _cogl_bitmap_new_from_stb_pixels (CoglContext *ctx,
                                   int stb_pixel_format,
                                   int width,
                                   int height,
-                                  GError **error)
+                                  CoglError **error)
 {
   static CoglUserDataKey bitmap_data_key;
   CoglBitmap *bmp;
@@ -317,10 +322,10 @@ _cogl_bitmap_new_from_stb_pixels (CoglContext *ctx,
 
   if (pixels == NULL)
     {
-      g_set_error_literal (error,
-                           COGL_BITMAP_ERROR,
-                           COGL_BITMAP_ERROR_FAILED,
-                           "Failed to load image with stb image library");
+      _cogl_set_error_literal (error,
+                               COGL_BITMAP_ERROR,
+                               COGL_BITMAP_ERROR_FAILED,
+                               "Failed to load image with stb image library");
       return NULL;
     }
 
@@ -338,11 +343,11 @@ _cogl_bitmap_new_from_stb_pixels (CoglContext *ctx,
 
         if (!pixels)
           {
-            g_set_error_literal (error,
-                                 COGL_BITMAP_ERROR,
-                                 COGL_BITMAP_ERROR_FAILED,
-                                 "Failed to alloc memory to convert "
-                                 "gray_alpha to rgba8888");
+            _cogl_set_error_literal (error,
+                                     COGL_BITMAP_ERROR,
+                                     COGL_BITMAP_ERROR_FAILED,
+                                     "Failed to alloc memory to convert "
+                                     "gray_alpha to rgba8888");
             return NULL;
           }
 
@@ -380,7 +385,7 @@ _cogl_bitmap_new_from_stb_pixels (CoglContext *ctx,
 CoglBitmap *
 _cogl_bitmap_from_file (CoglContext *ctx,
                         const char *filename,
-			GError **error)
+			CoglError **error)
 {
   int stb_pixel_format;
   int width;
@@ -401,7 +406,7 @@ CoglBitmap *
 _cogl_android_bitmap_new_from_asset (CoglContext *ctx,
                                      AAssetManager *manager,
                                      const char *filename,
-                                     GError **error)
+                                     CoglError **error)
 {
   AAsset *asset;
   const void *data;
@@ -415,20 +420,20 @@ _cogl_android_bitmap_new_from_asset (CoglContext *ctx,
   asset = AAssetManager_open (manager, filename, AASSET_MODE_BUFFER);
   if (!asset)
     {
-      g_set_error_literal (error,
-                           COGL_BITMAP_ERROR,
-                           COGL_BITMAP_ERROR_FAILED,
-                           "Failed to open asset");
+      _cogl_set_error_literal (error,
+                               COGL_BITMAP_ERROR,
+                               COGL_BITMAP_ERROR_FAILED,
+                               "Failed to open asset");
       return NULL;
     }
 
   data = AAsset_getBuffer (asset);
   if (!data)
     {
-      g_set_error_literal (error,
-                           COGL_BITMAP_ERROR,
-                           COGL_BITMAP_ERROR_FAILED,
-                           "Failed to ::getBuffer from asset");
+      _cogl_set_error_literal (error,
+                               COGL_BITMAP_ERROR,
+                               COGL_BITMAP_ERROR_FAILED,
+                               "Failed to ::getBuffer from asset");
       return NULL;
     }
 
diff --git a/cogl/cogl-bitmap-private.h b/cogl/cogl-bitmap-private.h
index c74c862..e0cf11d 100644
--- a/cogl/cogl-bitmap-private.h
+++ b/cogl/cogl-bitmap-private.h
@@ -109,14 +109,14 @@ _cogl_bitmap_convert_into_bitmap (CoglBitmap *src_bmp,
 CoglBitmap *
 _cogl_bitmap_from_file (CoglContext *ctx,
                         const char *filename,
-			GError **error);
+			CoglError **error);
 
 #ifdef COGL_HAS_ANDROID_SUPPORT
 CoglBitmap *
 _cogl_android_bitmap_new_from_asset (CoglContext *ctx,
                                      AAssetManager *manager,
                                      const char *filename,
-                                     GError **error);
+                                     CoglError **error);
 #endif
 
 CoglBool
diff --git a/cogl/cogl-bitmap.c b/cogl/cogl-bitmap.c
index 6223644..1be193a 100644
--- a/cogl/cogl-bitmap.c
+++ b/cogl/cogl-bitmap.c
@@ -225,7 +225,7 @@ _cogl_bitmap_new_shared (CoglBitmap              *shared_bmp,
 
 CoglBitmap *
 cogl_bitmap_new_from_file (const char *filename,
-                           GError **error)
+                           CoglError **error)
 {
   _COGL_GET_CONTEXT (ctx, NULL);
 
@@ -298,7 +298,7 @@ CoglBitmap *
 cogl_android_bitmap_new_from_asset (CoglContext *ctx,
                                     AAssetManager *manager,
                                     const char *filename,
-                                    GError **error)
+                                    CoglError **error)
 {
   _COGL_RETURN_VAL_IF_FAIL (ctx != NULL, NULL);
   _COGL_RETURN_VAL_IF_FAIL (manager != NULL, NULL);
@@ -349,7 +349,7 @@ cogl_bitmap_get_buffer (CoglBitmap *bitmap)
   return COGL_PIXEL_BUFFER (bitmap->buffer);
 }
 
-GQuark
+uint32_t
 cogl_bitmap_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-bitmap-error-quark");
diff --git a/cogl/cogl-bitmap.h b/cogl/cogl-bitmap.h
index 91714d4..d82dc15 100644
--- a/cogl/cogl-bitmap.h
+++ b/cogl/cogl-bitmap.h
@@ -55,7 +55,7 @@ typedef struct _CoglBitmap CoglBitmap;
 /**
  * cogl_bitmap_new_from_file:
  * @filename: the file to load.
- * @error: a #GError or %NULL.
+ * @error: a #CoglError or %NULL.
  *
  * Loads an image file from disk. This function can be safely called from
  * within a thread.
@@ -67,7 +67,7 @@ typedef struct _CoglBitmap CoglBitmap;
  */
 CoglBitmap *
 cogl_bitmap_new_from_file (const char *filename,
-                           GError **error);
+                           CoglError **error);
 
 #ifdef COGL_HAS_ANDROID_SUPPORT
 /**
@@ -75,7 +75,7 @@ cogl_bitmap_new_from_file (const char *filename,
  * @context: A #CoglContext
  * @manager: An Android Asset Manager.
  * @filename: The file name for the asset
- * @error: A return location for a GError exception.
+ * @error: A return location for a CoglError exception.
  *
  * Loads an Android asset into a newly allocated #CoglBitmap.
  *
@@ -88,7 +88,7 @@ CoglBitmap *
 cogl_android_bitmap_new_from_asset (CoglContext *context,
                                     AAssetManager *manager,
                                     const char *filename,
-                                    GError **error);
+                                    CoglError **error);
 #endif
 
 #if defined (COGL_ENABLE_EXPERIMENTAL_API)
@@ -280,7 +280,7 @@ cogl_is_bitmap (void *object);
 /**
  * COGL_BITMAP_ERROR:
  *
- * #GError domain for bitmap errors.
+ * #CoglError domain for bitmap errors.
  *
  * Since: 1.4
  */
@@ -307,7 +307,7 @@ typedef enum {
   COGL_BITMAP_ERROR_CORRUPT_IMAGE
 } CoglBitmapError;
 
-GQuark cogl_bitmap_error_quark (void);
+uint32_t cogl_bitmap_error_quark (void);
 
 G_END_DECLS
 
diff --git a/cogl/cogl-blend-string.c b/cogl/cogl-blend-string.c
index 5823a1d..a0f10a5 100644
--- a/cogl/cogl-blend-string.c
+++ b/cogl/cogl-blend-string.c
@@ -37,6 +37,7 @@
 #include "cogl-context-private.h"
 #include "cogl-debug.h"
 #include "cogl-blend-string.h"
+#include "cogl-error-private.h"
 
 typedef enum _ParserState
 {
@@ -118,7 +119,7 @@ static CoglBlendStringFunctionInfo blend_functions[] = {
 
 #undef DEFINE_FUNCTION
 
-GQuark
+uint32_t
 cogl_blend_string_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-blend-string-error-quark");
@@ -161,7 +162,7 @@ _cogl_blend_string_split_rgba_statement (CoglBlendStringStatement *statement,
 static CoglBool
 validate_tex_combine_statements (CoglBlendStringStatement *statements,
                                  int n_statements,
-                                 GError **error)
+                                 CoglError **error)
 {
   int i, j;
   const char *error_string;
@@ -190,11 +191,11 @@ validate_tex_combine_statements (CoglBlendStringStatement *statements,
   return TRUE;
 
 error:
-  g_set_error (error,
-               COGL_BLEND_STRING_ERROR,
-               detail,
-               "Invalid texture combine string: %s",
-               error_string);
+  _cogl_set_error (error,
+                   COGL_BLEND_STRING_ERROR,
+                   detail,
+                   "Invalid texture combine string: %s",
+                   error_string);
 
   if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
     {
@@ -207,7 +208,7 @@ error:
 static CoglBool
 validate_blend_statements (CoglBlendStringStatement *statements,
                            int n_statements,
-                           GError **error)
+                           CoglError **error)
 {
   int i, j;
   const char *error_string;
@@ -275,11 +276,11 @@ validate_blend_statements (CoglBlendStringStatement *statements,
   return TRUE;
 
 error:
-  g_set_error (error,
-               COGL_BLEND_STRING_ERROR,
-               detail,
-               "Invalid blend string: %s",
-               error_string);
+  _cogl_set_error (error,
+                   COGL_BLEND_STRING_ERROR,
+                   detail,
+                   "Invalid blend string: %s",
+                   error_string);
   return FALSE;
 }
 
@@ -287,7 +288,7 @@ static CoglBool
 validate_statements_for_context (CoglBlendStringStatement *statements,
                                  int n_statements,
                                  CoglBlendStringContext context,
-                                 GError **error)
+                                 CoglError **error)
 {
   const char *error_string;
 
@@ -313,13 +314,13 @@ validate_statements_for_context (CoglBlendStringStatement *statements,
     return validate_tex_combine_statements (statements, n_statements, error);
 
 error:
-  g_set_error (error,
-               COGL_BLEND_STRING_ERROR,
-               COGL_BLEND_STRING_ERROR_INVALID_ERROR,
-               "Invalid %s string: %s",
-               context == COGL_BLEND_STRING_CONTEXT_BLENDING ?
-               "blend" : "texture combine",
-               error_string);
+  _cogl_set_error (error,
+                   COGL_BLEND_STRING_ERROR,
+                   COGL_BLEND_STRING_ERROR_INVALID_ERROR,
+                   "Invalid %s string: %s",
+                   context == COGL_BLEND_STRING_CONTEXT_BLENDING ?
+                   "blend" : "texture combine",
+                   error_string);
 
   if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
     {
@@ -474,7 +475,7 @@ parse_argument (const char *string, /* original user string */
                 int current_arg,
                 CoglBlendStringArgument *arg, /* OUT */
                 CoglBlendStringContext context,
-                GError **error)
+                CoglError **error)
 {
   const char *p = *ret_p;
   const char *mark = NULL;
@@ -743,13 +744,13 @@ parse_argument (const char *string, /* original user string */
 error:
   {
     int offset = p - string;
-    g_set_error (error,
-                 COGL_BLEND_STRING_ERROR,
-                 COGL_BLEND_STRING_ERROR_ARGUMENT_PARSE_ERROR,
-                 "Syntax error for argument %d at offset %d: %s",
-                 current_arg,
-                 offset,
-                 error_string);
+    _cogl_set_error (error,
+                     COGL_BLEND_STRING_ERROR,
+                     COGL_BLEND_STRING_ERROR_ARGUMENT_PARSE_ERROR,
+                     "Syntax error for argument %d at offset %d: %s",
+                     current_arg,
+                     offset,
+                     error_string);
 
     if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
       {
@@ -764,7 +765,7 @@ int
 _cogl_blend_string_compile (const char *string,
                             CoglBlendStringContext context,
                             CoglBlendStringStatement *statements,
-                            GError **error)
+                            CoglError **error)
 {
   const char *p = string;
   const char *mark = NULL;
@@ -924,12 +925,12 @@ finished:
 error:
     {
       int offset = p - string;
-      g_set_error (error,
-                   COGL_BLEND_STRING_ERROR,
-                   COGL_BLEND_STRING_ERROR_PARSE_ERROR,
-                   "Syntax error at offset %d: %s",
-                   offset,
-                   error_string);
+      _cogl_set_error (error,
+                       COGL_BLEND_STRING_ERROR,
+                       COGL_BLEND_STRING_ERROR_PARSE_ERROR,
+                       "Syntax error at offset %d: %s",
+                       offset,
+                       error_string);
 
       if (COGL_DEBUG_ENABLED (COGL_DEBUG_BLEND_STRINGS))
         {
@@ -981,7 +982,7 @@ _cogl_blend_string_test (void)
   };
   int i;
 
-  GError *error = NULL;
+  CoglError *error = NULL;
   for (i = 0; strings[i].string; i++)
     {
       CoglBlendStringStatement statements[2];
@@ -994,7 +995,7 @@ _cogl_blend_string_test (void)
           g_print ("Failed to parse string:\n%s\n%s\n",
                    strings[i].string,
                    error->message);
-          g_error_free (error);
+          cogl_error_free (error);
           error = NULL;
           continue;
         }
diff --git a/cogl/cogl-blend-string.h b/cogl/cogl-blend-string.h
index 75d2f95..10e6b29 100644
--- a/cogl/cogl-blend-string.h
+++ b/cogl/cogl-blend-string.h
@@ -126,7 +126,7 @@ CoglBool
 _cogl_blend_string_compile (const char *string,
                             CoglBlendStringContext context,
                             CoglBlendStringStatement *statements,
-                            GError **error);
+                            CoglError **error);
 
 void
 _cogl_blend_string_split_rgba_statement (CoglBlendStringStatement *statement,
diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h
index 85d107c..5060abd 100644
--- a/cogl/cogl-context-private.h
+++ b/cogl/cogl-context-private.h
@@ -336,7 +336,7 @@ _cogl_context_get_winsys (CoglContext *context);
  * return FALSE and set @error */
 CoglBool
 _cogl_context_update_features (CoglContext *context,
-                               GError **error);
+                               CoglError **error);
 
 /* Obtains the context and returns retval if NULL */
 #define _COGL_GET_CONTEXT(ctxvar, retval) \
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 9a02a40..530dc2b 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -49,6 +49,7 @@
 #include "cogl1-context.h"
 #include "cogl-gpu-info-private.h"
 #include "cogl-config-private.h"
+#include "cogl-error-private.h"
 
 #include <string.h>
 
@@ -124,13 +125,14 @@ _cogl_context_get_winsys (CoglContext *context)
  */
 CoglContext *
 cogl_context_new (CoglDisplay *display,
-                  GError **error)
+                  CoglError **error)
 {
   CoglContext *context;
   GLubyte default_texture_data[] = { 0xff, 0xff, 0xff, 0x0 };
   CoglBitmap *default_texture_bitmap;
   const CoglWinsysVtable *winsys;
   int i;
+  CoglError *internal_error = NULL;
 
   _cogl_init ();
 
@@ -390,18 +392,26 @@ cogl_context_new (CoglDisplay *display,
                                      /* internal format */
                                      COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                      NULL);
-  /* If 3D or rectangle textures aren't supported then these should
-     just silently return NULL */
+
+  /* If 3D or rectangle textures aren't supported then these will
+   * return errors that we can simply ignore. */
+  internal_error = NULL;
   context->default_gl_texture_3d_tex =
     cogl_texture_3d_new_from_bitmap (default_texture_bitmap,
                                      1, /* height */
                                      1, /* depth */
                                      COGL_PIXEL_FORMAT_RGBA_8888_PRE,
-                                     NULL);
+                                     &internal_error);
+  if (internal_error)
+    cogl_error_free (internal_error);
+
+  internal_error = NULL;
   context->default_gl_texture_rect_tex =
     cogl_texture_rectangle_new_from_bitmap (default_texture_bitmap,
                                             COGL_PIXEL_FORMAT_RGBA_8888_PRE,
-                                            NULL);
+                                            &internal_error);
+  if (internal_error)
+    cogl_error_free (internal_error);
 
   cogl_object_unref (default_texture_bitmap);
 
@@ -532,7 +542,7 @@ _cogl_context_free (CoglContext *context)
 CoglContext *
 _cogl_context_get_default (void)
 {
-  GError *error = NULL;
+  CoglError *error = NULL;
   /* Create if doesn't exist yet */
   if (_cogl_context == NULL)
     {
@@ -541,7 +551,7 @@ _cogl_context_get_default (void)
         {
           g_warning ("Failed to create default context: %s",
                      error->message);
-          g_error_free (error);
+          cogl_error_free (error);
         }
     }
 
@@ -569,7 +579,7 @@ cogl_egl_context_get_egl_display (CoglContext *context)
 
 CoglBool
 _cogl_context_update_features (CoglContext *context,
-                               GError **error)
+                               CoglError **error)
 {
   return context->driver_vtable->update_features (context, error);
 }
diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h
index d09f46d..17fb7f4 100644
--- a/cogl/cogl-context.h
+++ b/cogl/cogl-context.h
@@ -94,7 +94,7 @@ G_BEGIN_DECLS
 /**
  * cogl_context_new:
  * @display: A #CoglDisplay pointer
- * @error: A GError return location.
+ * @error: A CoglError return location.
  *
  * Creates a new #CoglContext which acts as an application sandbox
  * for any state objects that are allocated.
@@ -105,7 +105,7 @@ G_BEGIN_DECLS
  */
 CoglContext *
 cogl_context_new (CoglDisplay *display,
-                  GError **error);
+                  CoglError **error);
 
 /**
  * cogl_context_get_display:
diff --git a/cogl/cogl-display.c b/cogl/cogl-display.c
index f6e01be..ec5f88a 100644
--- a/cogl/cogl-display.c
+++ b/cogl/cogl-display.c
@@ -83,7 +83,7 @@ cogl_display_new (CoglRenderer *renderer,
                   CoglOnscreenTemplate *onscreen_template)
 {
   CoglDisplay *display = g_slice_new0 (CoglDisplay);
-  GError *error = NULL;
+  CoglError *error = NULL;
 
   _cogl_init ();
 
@@ -119,7 +119,7 @@ cogl_display_get_renderer (CoglDisplay *display)
 
 CoglBool
 cogl_display_setup (CoglDisplay *display,
-                    GError **error)
+                    CoglError **error)
 {
   const CoglWinsysVtable *winsys;
 
diff --git a/cogl/cogl-display.h b/cogl/cogl-display.h
index c8cf7be..70bbf27 100644
--- a/cogl/cogl-display.h
+++ b/cogl/cogl-display.h
@@ -124,7 +124,7 @@ cogl_display_get_renderer (CoglDisplay *display);
 /**
  * cogl_display_setup:
  * @display: a #CoglDisplay
- * @error: return location for a #GError
+ * @error: return location for a #CoglError
  *
  * Explicitly sets up the given @display object. Use of this api is
  * optional since Cogl will internally setup the display if not done
@@ -154,7 +154,7 @@ cogl_display_get_renderer (CoglDisplay *display);
  */
 CoglBool
 cogl_display_setup (CoglDisplay *display,
-                    GError **error);
+                    CoglError **error);
 
 #ifdef COGL_HAS_EGL_PLATFORM_GDL_SUPPORT
 /**
diff --git a/cogl/cogl-driver.h b/cogl/cogl-driver.h
index 7b82628..63b737d 100644
--- a/cogl/cogl-driver.h
+++ b/cogl/cogl-driver.h
@@ -46,11 +46,11 @@ struct _CoglDriverVtable
 
   CoglBool
   (* update_features) (CoglContext *context,
-                       GError **error);
+                       CoglError **error);
 
   CoglBool
   (* offscreen_allocate) (CoglOffscreen *offscreen,
-                          GError **error);
+                          CoglError **error);
 
   void
   (* offscreen_free) (CoglOffscreen *offscreen);
diff --git a/cogl/cogl-error-private.h b/cogl/cogl-error-private.h
new file mode 100644
index 0000000..85b64f7
--- /dev/null
+++ b/cogl/cogl-error-private.h
@@ -0,0 +1,48 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * 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 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __COGL_ERROR_PRIVATE_H__
+#define __COGL_ERROR_PRIVATE_H__
+
+#include "cogl-error.h"
+
+void
+_cogl_set_error (CoglError **error,
+                 uint32_t domain,
+                 int code,
+                 const char *format,
+                 ...) G_GNUC_PRINTF (4, 5);
+
+void
+_cogl_set_error_literal (CoglError **error,
+                         uint32_t domain,
+                         int code,
+                         const char *message);
+
+void
+_cogl_propogate_gerror (CoglError **dest,
+                        GError *src);
+
+#define _cogl_clear_error(X) g_clear_error ((GError **)X)
+
+#endif /* __COGL_ERROR_PRIVATE_H__ */
diff --git a/cogl/cogl-error.c b/cogl/cogl-error.c
new file mode 100644
index 0000000..969c85c
--- /dev/null
+++ b/cogl/cogl-error.c
@@ -0,0 +1,109 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2011 Intel Corporation.
+ *
+ * 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 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors:
+ *   Robert Bragg <robert linux intel com>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "cogl-types.h"
+#include "cogl-util.h"
+#include "cogl-error-private.h"
+
+#include <glib.h>
+
+void
+cogl_error_free (CoglError *error)
+{
+  g_error_free ((GError *)error);
+}
+
+CoglError *
+cogl_error_copy (CoglError *error)
+{
+  return (CoglError *)g_error_copy ((GError *)error);
+}
+
+CoglBool
+cogl_error_matches (CoglError *error,
+                    uint32_t domain,
+                    int code)
+{
+  return g_error_matches ((GError *)error, domain, code);
+}
+
+#define ERROR_OVERWRITTEN_WARNING \
+  "CoglError set over the top of a previous CoglError or " \
+  "uninitialized memory.\nThis indicates a bug in someone's " \
+  "code. You must ensure an error is NULL before it's set.\n" \
+  "The overwriting error message was: %s"
+
+void
+_cogl_set_error (CoglError **error,
+                 uint32_t domain,
+                 int code,
+                 const char *format,
+                 ...)
+{
+  GError *new;
+
+  va_list args;
+
+  va_start (args, format);
+
+  if (error == NULL)
+    {
+      g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
+      va_end (args);
+      return;
+    }
+
+  new = g_error_new_valist (domain, code, format, args);
+  va_end (args);
+
+  if (*error == NULL)
+    *error = (CoglError *)new;
+  else
+    g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
+}
+
+void
+_cogl_set_error_literal (CoglError **error,
+                         uint32_t domain,
+                         int code,
+                         const char *message)
+{
+  _cogl_set_error (error, domain, code, "%s", message);
+}
+
+void
+_cogl_propogate_gerror (CoglError **dest,
+                        GError *src)
+{
+  _COGL_RETURN_IF_FAIL (src != NULL);
+
+  _cogl_set_error_literal (dest, src->domain, src->code, src->message);
+  g_error_free (src);
+}
diff --git a/cogl/cogl-error.h b/cogl/cogl-error.h
new file mode 100644
index 0000000..965c43d
--- /dev/null
+++ b/cogl/cogl-error.h
@@ -0,0 +1,175 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * 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 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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined(__COGL_H_INSIDE__) && !defined(COGL_COMPILATION)
+#error "Only <cogl/cogl.h> can be included directly."
+#endif
+
+#ifndef __COGL_ERROR_H__
+#define __COGL_ERROR_H__
+
+#include "cogl-types.h"
+
+/**
+ * SECTION:cogl-error
+ * @short_description: A way for Cogl to throw exceptions
+ *
+ * As a general rule Cogl shields non-recoverable errors from
+ * developers, such as most heap allocation failures (unless for
+ * exceptionally large resources which we might reasonably expect to
+ * fail) and this reduces the burdon on developers.
+ *
+ * There are some Cogl apis though that can fail for exceptional
+ * reasons that can also potentially be recovered from at runtime
+ * and for these apis we use a standard convention for reporting
+ * runtime recoverable errors.
+ *
+ * As an example if we look at the cogl_context_new() api which
+ * takes an error argument:
+ * |[
+ *   CoglContext *
+ *   cogl_context_new (CoglDisplay *display, CoglError **error);
+ * ]|
+ *
+ * A caller interested in catching any runtime error when creating a
+ * new #CoglContext would pass the address of a #CoglError pointer
+ * that has first been initialized to %NULL as follows:
+ *
+ * |[
+ *   CoglError *error = NULL;
+ *   CoglContext *context;
+ *
+ *   context = cogl_context_new (NULL, &error);
+ * ]|
+ *
+ * The return status should usually be enough to determine if there
+ * was an error set (in this example we can check if context == %NULL)
+ * but if it's not possible to tell from the function's return status
+ * you can instead look directly at the error pointer which you
+ * initialized to %NULL. In this example we now check the error,
+ * report any error to the user, free the error and then simply
+ * abort without attempting to recover.
+ *
+ * |[
+ *   if (context == NULL)
+ *     {
+ *       fprintf (stderr, "Failed to create a Cogl context: %s\n",
+ *                error->message);
+ *       cogl_error_free (error);
+ *       abort ();
+ *     }
+ * ]|
+ *
+ * All Cogl APIs that accept an error argument can also be passed a
+ * %NULL pointer. In this case if an exceptional error condition is hit
+ * then Cogl will simply log the error message and abort the
+ * application. This can be compared to language execeptions where the
+ * developer has not attempted to catch the exception. This means the
+ * above example is essentially redundant because it's what Cogl would
+ * have done automatically and so, similarly, if your application has
+ * no way to recover from a particular error you might just as well
+ * pass a %NULL #CoglError pointer to save a bit of typing.
+ *
+ * <note>If you are used to using the GLib API you will probably
+ * recognize that #CoglError is just like a #GError. In fact if Cogl
+ * has been built with --enable-glib then it is safe to cast a
+ * #CoglError to a #GError.</note>
+ *
+ * <note>An important detail to be aware of if you are used to using
+ * GLib's GError API is that Cogl deviates from the GLib GError
+ * conventions in one noteable way which is that a %NULL error pointer
+ * does not mean you want to ignore the details of an error, it means
+ * you are not trying to catch any exceptional errors the function might
+ * throw which will result in the program aborting with a log message
+ * if an error is thrown.</note>
+ */
+
+#ifdef COGL_HAS_GLIB_SUPPORT
+#define CoglError GError
+#else
+/**
+ * CoglError:
+ * @domain: A high-level domain identifier for the error
+ * @code: A specific error code within a specified domain
+ * @message: A human readable error message
+ */
+typedef struct _CoglError
+{
+  uint32_t domain;
+  int code;
+  char *message;
+} CoglError;
+#endif /* COGL_HAS_GLIB_SUPPORT */
+
+/**
+ * cogl_error_free:
+ * @error: A #CoglError thrown by the Cogl api
+ *
+ * Frees a #CoglError and associated resources.
+ */
+void
+cogl_error_free (CoglError *error);
+
+/**
+ * cogl_error_copy:
+ * @error: A #CoglError thrown by the Cogl api
+ *
+ * Makes a copy of @error which can later be freed using
+ * cogl_error_free().
+ *
+ * Return value: A newly allocated #CoglError initialized to match the
+ *               contents of @error.
+ */
+CoglError *
+cogl_error_copy (CoglError *error);
+
+/**
+ * cogl_error_matches:
+ * @error: A #CoglError thrown by the Cogl api or %NULL
+ *
+ * Returns %TRUE if error matches domain and code, %FALSE otherwise.
+ * In particular, when error is %NULL, FALSE will be returned.
+ *
+ * Return value: whether the @error corresponds to the given @domain
+ *               and @code.
+ */
+CoglBool
+cogl_error_matches (CoglError *error,
+                    uint32_t domain,
+                    int code);
+
+/**
+ * COGL_GLIB_ERROR:
+ * @COGL_ERROR: A #CoglError thrown by the Cogl api or %NULL
+ *
+ * Simply casts a #CoglError to a #CoglError
+ *
+ * If Cogl is built with GLib support then it can safely be assumed
+ * that a CoglError is a GError and can be used directly with the
+ * GError api.
+ */
+#ifdef COGL_HAS_GLIB_SUPPORT
+#define COGL_GLIB_ERROR(COGL_ERROR) ((CoglError *)COGL_ERROR)
+#endif
+
+#endif /* __COGL_ERROR_H__ */
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index 3b927c2..b4dfc91 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -49,6 +49,7 @@
 #include "cogl-private.h"
 #include "cogl-primitives-private.h"
 #include "cogl-path-private.h"
+#include "cogl-error-private.h"
 
 typedef struct _CoglFramebufferStackEntry
 {
@@ -75,7 +76,7 @@ COGL_OBJECT_DEFINE_DEPRECATED_REF_COUNTING (offscreen);
  * abstract class manually.
  */
 
-GQuark
+uint32_t
 cogl_framebuffer_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-framebuffer-error-quark");
@@ -652,7 +653,7 @@ _cogl_offscreen_free (CoglOffscreen *offscreen)
 
 CoglBool
 cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
-                           GError **error)
+                           CoglError **error)
 {
   CoglOnscreen *onscreen = COGL_ONSCREEN (framebuffer);
   const CoglWinsysVtable *winsys = _cogl_framebuffer_get_winsys (framebuffer);
@@ -664,10 +665,10 @@ cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
     {
       if (framebuffer->config.depth_texture_enabled)
         {
-          g_set_error (error, COGL_FRAMEBUFFER_ERROR,
-                       COGL_FRAMEBUFFER_ERROR_ALLOCATE,
-                       "Can't allocate onscreen framebuffer with a "
-                       "texture based depth buffer");
+          _cogl_set_error (error, COGL_FRAMEBUFFER_ERROR,
+                           COGL_FRAMEBUFFER_ERROR_ALLOCATE,
+                           "Can't allocate onscreen framebuffer with a "
+                           "texture based depth buffer");
           return FALSE;
         }
 
diff --git a/cogl/cogl-framebuffer.h b/cogl/cogl-framebuffer.h
index b7563b6..2358304 100644
--- a/cogl/cogl-framebuffer.h
+++ b/cogl/cogl-framebuffer.h
@@ -98,7 +98,7 @@ typedef struct _CoglFramebuffer CoglFramebuffer;
 /**
  * cogl_framebuffer_allocate:
  * @framebuffer: A #CoglFramebuffer
- * @error: A pointer to a #GError for returning exceptions.
+ * @error: A pointer to a #CoglError for returning exceptions.
  *
  * Explicitly allocates a configured #CoglFramebuffer allowing developers to
  * check and handle any errors that might arise from an unsupported
@@ -117,7 +117,7 @@ typedef struct _CoglFramebuffer CoglFramebuffer;
  */
 CoglBool
 cogl_framebuffer_allocate (CoglFramebuffer *framebuffer,
-                           GError **error);
+                           CoglError **error);
 
 /**
  * cogl_framebuffer_get_width:
@@ -1782,7 +1782,7 @@ cogl_get_draw_framebuffer (void);
 /* XXX: Note these are defined outside the COGL_ENABLE_EXPERIMENTAL_API guard since
  * otherwise the glib-mkenums stuff will get upset. */
 
-GQuark
+uint32_t
 cogl_framebuffer_error_quark (void);
 
 /**
diff --git a/cogl/cogl-gles2-context.c b/cogl/cogl-gles2-context.c
index 14f091c..c8d0e20 100644
--- a/cogl/cogl-gles2-context.c
+++ b/cogl/cogl-gles2-context.c
@@ -45,6 +45,7 @@
 #include "cogl-swap-chain-private.h"
 #include "cogl-texture-2d-private.h"
 #include "cogl-pipeline-opengl-private.h"
+#include "cogl-error-private.h"
 
 static void _cogl_gles2_context_free (CoglGLES2Context *gles2_context);
 
@@ -88,7 +89,7 @@ enum {
   RESTORE_FB_FROM_ONSCREEN,
 };
 
-GQuark
+uint32_t
 _cogl_gles2_context_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-gles2-context-error-quark");
@@ -1556,14 +1557,14 @@ free_texture_object_data (CoglGLES2TextureObjectData *data)
 }
 
 CoglGLES2Context *
-cogl_gles2_context_new (CoglContext *ctx, GError **error)
+cogl_gles2_context_new (CoglContext *ctx, CoglError **error)
 {
   CoglGLES2Context *gles2_ctx;
   const CoglWinsysVtable *winsys;
 
   if (!cogl_has_feature (ctx, COGL_FEATURE_ID_GLES2_CONTEXT))
     {
-      g_set_error (error, COGL_GLES2_CONTEXT_ERROR,
+      _cogl_set_error (error, COGL_GLES2_CONTEXT_ERROR,
                    COGL_GLES2_CONTEXT_ERROR_UNSUPPORTED,
                    "Backend doesn't support creating GLES2 contexts");
 
@@ -1683,11 +1684,11 @@ cogl_gles2_context_get_vtable (CoglGLES2Context *gles2_ctx)
 static CoglGLES2Offscreen *
 _cogl_gles2_offscreen_allocate (CoglOffscreen *offscreen,
                                 CoglGLES2Context *gles2_context,
-                                GError **error)
+                                CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (offscreen);
   const CoglWinsysVtable *winsys;
-  GError *internal_error = NULL;
+  CoglError *internal_error = NULL;
   CoglGLES2Offscreen *gles2_offscreen;
 
   if (!framebuffer->allocated &&
@@ -1710,8 +1711,8 @@ _cogl_gles2_offscreen_allocate (CoglOffscreen *offscreen,
     {
       winsys->restore_context (framebuffer->context);
 
-      g_error_free (internal_error);
-      g_set_error (error, COGL_FRAMEBUFFER_ERROR,
+      cogl_error_free (internal_error);
+      _cogl_set_error (error, COGL_FRAMEBUFFER_ERROR,
                    COGL_FRAMEBUFFER_ERROR_ALLOCATE,
                    "Failed to bind gles2 context to create framebuffer");
       return NULL;
@@ -1732,7 +1733,7 @@ _cogl_gles2_offscreen_allocate (CoglOffscreen *offscreen,
 
       g_slice_free (CoglGLES2Offscreen, gles2_offscreen);
 
-      g_set_error (error, COGL_FRAMEBUFFER_ERROR,
+      _cogl_set_error (error, COGL_FRAMEBUFFER_ERROR,
                    COGL_FRAMEBUFFER_ERROR_ALLOCATE,
                    "Failed to create an OpenGL framebuffer object");
       return NULL;
@@ -1763,10 +1764,10 @@ cogl_push_gles2_context (CoglContext *ctx,
                          CoglGLES2Context *gles2_ctx,
                          CoglFramebuffer *read_buffer,
                          CoglFramebuffer *write_buffer,
-                         GError **error)
+                         CoglError **error)
 {
   const CoglWinsysVtable *winsys = ctx->display->renderer->winsys_vtable;
-  GError *internal_error = NULL;
+  CoglError *internal_error = NULL;
 
   _COGL_RETURN_VAL_IF_FAIL (gles2_ctx != NULL, FALSE);
 
@@ -1845,8 +1846,8 @@ cogl_push_gles2_context (CoglContext *ctx,
     {
       winsys->restore_context (ctx);
 
-      g_error_free (internal_error);
-      g_set_error (error, COGL_GLES2_CONTEXT_ERROR,
+      cogl_error_free (internal_error);
+      _cogl_set_error (error, COGL_GLES2_CONTEXT_ERROR,
                    COGL_GLES2_CONTEXT_ERROR_DRIVER,
                    "Driver failed to make GLES2 context current");
       return FALSE;
@@ -1930,7 +1931,7 @@ cogl_gles2_texture_2d_new_from_handle (CoglContext *ctx,
                                        int width,
                                        int height,
                                        CoglPixelFormat internal_format,
-                                       GError **error)
+                                       CoglError **error)
 {
   return cogl_texture_2d_new_from_foreign (ctx,
                                            handle,
diff --git a/cogl/cogl-gles2.h b/cogl/cogl-gles2.h
index 34467b2..8174e7b 100644
--- a/cogl/cogl-gles2.h
+++ b/cogl/cogl-gles2.h
@@ -124,7 +124,7 @@ struct _CoglGLES2Vtable
 #undef COGL_EXT_END
 };
 
-GQuark
+uint32_t
 _cogl_gles2_context_error_quark (void);
 
 /**
@@ -156,7 +156,7 @@ typedef enum { /*< prefix=COGL_GLES2_CONTEXT_ERROR >*/
 /**
  * cogl_gles2_context_new:
  * @ctx: A #CoglContext
- * @error: A pointer to a #GError for returning exceptions
+ * @error: A pointer to a #CoglError for returning exceptions
  *
  * Allocates a new OpenGLES 2.0 context that can be used to render to
  * #CoglOffscreen framebuffers (Rendering to #CoglOnscreen
@@ -183,7 +183,7 @@ typedef enum { /*< prefix=COGL_GLES2_CONTEXT_ERROR >*/
  * Stability: unstable
  */
 CoglGLES2Context *
-cogl_gles2_context_new (CoglContext *ctx, GError **error);
+cogl_gles2_context_new (CoglContext *ctx, CoglError **error);
 
 /**
  * cogl_gles2_context_get_vtable:
@@ -215,7 +215,7 @@ cogl_gles2_context_get_vtable (CoglGLES2Context *gles2_ctx);
  * @write_buffer: A #CoglFramebuffer to access for drawing operations
  *                such as glDrawArrays. (must be a #CoglOffscreen
  *               framebuffer currently)
- * @error: A pointer to a #GError for returning exceptions
+ * @error: A pointer to a #CoglError for returning exceptions
  *
  * Pushes the given @gles2_ctx onto a stack associated with @ctx so
  * that the OpenGLES 2.0 api can be used instead of the Cogl
@@ -239,7 +239,7 @@ cogl_push_gles2_context (CoglContext *ctx,
                          CoglGLES2Context *gles2_ctx,
                          CoglFramebuffer *read_buffer,
                          CoglFramebuffer *write_buffer,
-                         GError **error);
+                         CoglError **error);
 
 /**
  * cogl_pop_gles2_context:
@@ -306,7 +306,7 @@ cogl_gles2_texture_2d_new_from_handle (CoglContext *ctx,
                                        int width,
                                        int height,
                                        CoglPixelFormat internal_format,
-                                       GError **error);
+                                       CoglError **error);
 
 /**
  * cogl_gles2_texture_get_handle:
diff --git a/cogl/cogl-internal.h b/cogl/cogl-internal.h
index 5881315..88fd188 100644
--- a/cogl/cogl-internal.h
+++ b/cogl/cogl-internal.h
@@ -118,7 +118,7 @@ typedef enum _CoglPipelineEvalFlags
 CoglBool
 _cogl_check_extension (const char *name, const char *ext);
 
-GQuark
+uint32_t
 _cogl_driver_error_quark (void);
 
 #endif /* __COGL_INTERNAL_H */
diff --git a/cogl/cogl-material-compat.c b/cogl/cogl-material-compat.c
index c7519d9..af56223 100644
--- a/cogl/cogl-material-compat.c
+++ b/cogl/cogl-material-compat.c
@@ -192,7 +192,7 @@ cogl_material_set_alpha_test_function (CoglMaterial         *material,
 CoglBool
 cogl_material_set_blend (CoglMaterial *material,
                          const char   *blend_string,
-                         GError      **error)
+                         CoglError   **error)
 {
   return cogl_pipeline_set_blend (COGL_PIPELINE (material),
                                   blend_string,
@@ -252,7 +252,7 @@ CoglBool
 cogl_material_set_layer_combine (CoglMaterial *material,
 				 int           layer_index,
 				 const char   *blend_string,
-                                 GError      **error)
+                                 CoglError   **error)
 {
   return cogl_pipeline_set_layer_combine (COGL_PIPELINE (material),
                                           layer_index,
@@ -331,7 +331,7 @@ CoglBool
 cogl_material_set_layer_point_sprite_coords_enabled (CoglMaterial *material,
                                                      int           layer_index,
                                                      CoglBool      enable,
-                                                     GError      **error)
+                                                     CoglError   **error)
 {
   CoglPipeline *pipeline = COGL_PIPELINE (material);
   return cogl_pipeline_set_layer_point_sprite_coords_enabled (pipeline,
@@ -439,7 +439,7 @@ cogl_material_foreach_layer (CoglMaterial *material,
 CoglBool
 cogl_material_set_depth_state (CoglMaterial *material,
                                const CoglDepthState *state,
-                               GError **error)
+                               CoglError **error)
 {
   return cogl_pipeline_set_depth_state (COGL_PIPELINE (material),
                                         state, error);
diff --git a/cogl/cogl-material-compat.h b/cogl/cogl-material-compat.h
index 964fa4a..756e833 100644
--- a/cogl/cogl-material-compat.h
+++ b/cogl/cogl-material-compat.h
@@ -31,6 +31,7 @@
 #include <cogl/cogl-types.h>
 #include <cogl/cogl-matrix.h>
 #include <cogl/cogl-depth-state.h>
+#include <cogl/cogl-error.h>
 
 G_BEGIN_DECLS
 
@@ -508,7 +509,7 @@ cogl_material_set_alpha_test_function (CoglMaterial         *material,
  * @material: A #CoglMaterial object
  * @blend_string: A <link linkend="cogl-Blend-Strings">Cogl blend string</link>
  *   describing the desired blend function.
- * @error: return location for a #GError that may report lack of driver
+ * @error: return location for a #CoglError that may report lack of driver
  *   support if you give separate blend string statements for the alpha
  *   channel and RGB channels since some drivers, or backends such as
  *   GLES 1.1, don't support this feature. May be %NULL, in which case a
@@ -590,7 +591,7 @@ cogl_material_set_alpha_test_function (CoglMaterial         *material,
 CoglBool
 cogl_material_set_blend (CoglMaterial *material,
                          const char   *blend_string,
-                         GError      **error);
+                         CoglError   **error);
 
 /**
  * cogl_material_set_blend_constant:
@@ -746,7 +747,7 @@ cogl_material_remove_layer (CoglMaterial *material,
  * @layer_index: Specifies the layer you want define a combine function for
  * @blend_string: A <link linkend="cogl-Blend-Strings">Cogl blend string</link>
  *    describing the desired texture combine function.
- * @error: A #GError that may report parse errors or lack of GPU/driver
+ * @error: A #CoglError that may report parse errors or lack of GPU/driver
  *   support. May be %NULL, in which case a warning will be printed out if an
  *   error is encountered.
  *
@@ -836,7 +837,7 @@ CoglBool
 cogl_material_set_layer_combine (CoglMaterial *material,
 				 int           layer_index,
 				 const char   *blend_string,
-                                 GError      **error);
+                                 CoglError   **error);
 
 /**
  * cogl_material_set_layer_combine_constant:
@@ -997,7 +998,7 @@ cogl_material_set_layer_filters (CoglMaterial      *material,
  * @material: a #CoglHandle to a material.
  * @layer_index: the layer number to change.
  * @enable: whether to enable point sprite coord generation.
- * @error: A return location for a GError, or NULL to ignore errors.
+ * @error: A return location for a CoglError, or NULL to ignore errors.
  *
  * When rendering points, if @enable is %TRUE then the texture
  * coordinates for this layer will be replaced with coordinates that
@@ -1017,7 +1018,7 @@ CoglBool
 cogl_material_set_layer_point_sprite_coords_enabled (CoglMaterial *material,
                                                      int           layer_index,
                                                      CoglBool      enable,
-                                                     GError      **error);
+                                                     CoglError   **error);
 
 /**
  * cogl_material_get_layer_point_sprite_coords_enabled:
@@ -1199,7 +1200,7 @@ cogl_material_layer_get_wrap_mode_p (CoglMaterialLayer *layer);
  * cogl_material_set_depth_state:
  * @material: A #CoglMaterial object
  * @state: A #CoglDepthState struct
- * @error: A #GError to report failures to setup the given @state.
+ * @error: A #CoglError to report failures to setup the given @state.
  *
  * This commits all the depth state configured in @state struct to the
  * given @material. The configuration values are copied into the
@@ -1218,7 +1219,7 @@ cogl_material_layer_get_wrap_mode_p (CoglMaterialLayer *layer);
 CoglBool
 cogl_material_set_depth_state (CoglMaterial *material,
                                const CoglDepthState *state,
-                               GError **error);
+                               CoglError **error);
 
 /**
  * cogl_material_get_depth_state:
diff --git a/cogl/cogl-pipeline-layer-state.c b/cogl/cogl-pipeline-layer-state.c
index 19bece5..b69ff46 100644
--- a/cogl/cogl-pipeline-layer-state.c
+++ b/cogl/cogl-pipeline-layer-state.c
@@ -37,6 +37,7 @@
 #include "cogl-snippet-private.h"
 #include "cogl-texture-private.h"
 #include "cogl-pipeline-layer-state-private.h"
+#include "cogl-error-private.h"
 
 #include "string.h"
 #if 0
@@ -734,7 +735,7 @@ CoglBool
 cogl_pipeline_set_layer_point_sprite_coords_enabled (CoglPipeline *pipeline,
                                                      int layer_index,
                                                      CoglBool enable,
-                                                     GError **error)
+                                                     CoglError **error)
 {
   CoglPipelineLayerState       change =
     COGL_PIPELINE_LAYER_STATE_POINT_SPRITE_COORDS;
@@ -752,9 +753,11 @@ cogl_pipeline_set_layer_point_sprite_coords_enabled (CoglPipeline *pipeline,
     {
       if (error)
         {
-          g_set_error (error, COGL_ERROR, COGL_ERROR_UNSUPPORTED,
-                       "Point sprite texture coordinates are enabled "
-                       "for a layer but the GL driver does not support it.");
+          _cogl_set_error (error,
+                           COGL_SYSTEM_ERROR,
+                           COGL_SYSTEM_ERROR_UNSUPPORTED,
+                           "Point sprite texture coordinates are enabled for "
+                           "a layer but the GL driver does not support it.");
         }
       else
         {
@@ -1168,7 +1171,7 @@ CoglBool
 cogl_pipeline_set_layer_combine (CoglPipeline *pipeline,
 				 int layer_index,
 				 const char *combine_description,
-                                 GError **error)
+                                 CoglError **error)
 {
   CoglPipelineLayerState state = COGL_PIPELINE_LAYER_STATE_COMBINE;
   CoglPipelineLayer *authority;
@@ -1177,7 +1180,6 @@ cogl_pipeline_set_layer_combine (CoglPipeline *pipeline,
   CoglBlendStringStatement split[2];
   CoglBlendStringStatement *rgb;
   CoglBlendStringStatement *a;
-  GError *internal_error = NULL;
   int count;
 
   _COGL_RETURN_VAL_IF_FAIL (cogl_is_pipeline (pipeline), FALSE);
@@ -1198,19 +1200,9 @@ cogl_pipeline_set_layer_combine (CoglPipeline *pipeline,
     _cogl_blend_string_compile (combine_description,
                                 COGL_BLEND_STRING_CONTEXT_TEXTURE_COMBINE,
                                 statements,
-                                &internal_error);
+                                error);
   if (!count)
-    {
-      if (error)
-	g_propagate_error (error, internal_error);
-      else
-	{
-	  g_warning ("Cannot compile combine description: %s\n",
-		     internal_error->message);
-	  g_error_free (internal_error);
-	}
-      return FALSE;
-    }
+    return FALSE;
 
   if (statements[0].mask == COGL_BLEND_STRING_CHANNEL_MASK_RGBA)
     {
diff --git a/cogl/cogl-pipeline-layer-state.h b/cogl/cogl-pipeline-layer-state.h
index 39a4757..62f09f6 100644
--- a/cogl/cogl-pipeline-layer-state.h
+++ b/cogl/cogl-pipeline-layer-state.h
@@ -208,7 +208,7 @@ cogl_pipeline_remove_layer (CoglPipeline *pipeline,
  * @layer_index: Specifies the layer you want define a combine function for
  * @blend_string: A <link linkend="cogl-Blend-Strings">Cogl blend string</link>
  *    describing the desired texture combine function.
- * @error: A #GError that may report parse errors or lack of GPU/driver
+ * @error: A #CoglError that may report parse errors or lack of GPU/driver
  *   support. May be %NULL, in which case a warning will be printed out if an
  *   error is encountered.
  *
@@ -299,7 +299,7 @@ CoglBool
 cogl_pipeline_set_layer_combine (CoglPipeline *pipeline,
 				 int           layer_index,
 				 const char   *blend_string,
-                                 GError      **error);
+                                 CoglError      **error);
 
 /**
  * cogl_pipeline_set_layer_combine_constant:
@@ -416,7 +416,7 @@ cogl_pipeline_get_layer_mag_filter (CoglPipeline *pipeline,
  * @pipeline: A #CoglPipeline object
  * @layer_index: the layer number to change.
  * @enable: whether to enable point sprite coord generation.
- * @error: A return location for a GError, or NULL to ignore errors.
+ * @error: A return location for a CoglError, or NULL to ignore errors.
  *
  * When rendering points, if @enable is %TRUE then the texture
  * coordinates for this layer will be replaced with coordinates that
@@ -437,7 +437,7 @@ CoglBool
 cogl_pipeline_set_layer_point_sprite_coords_enabled (CoglPipeline *pipeline,
                                                      int           layer_index,
                                                      CoglBool      enable,
-                                                     GError      **error);
+                                                     CoglError      **error);
 
 /**
  * cogl_pipeline_get_layer_point_sprite_coords_enabled:
diff --git a/cogl/cogl-pipeline-state.c b/cogl/cogl-pipeline-state.c
index 6b14f37..96a72e2 100644
--- a/cogl/cogl-pipeline-state.c
+++ b/cogl/cogl-pipeline-state.c
@@ -36,6 +36,7 @@
 #include "cogl-depth-state-private.h"
 #include "cogl-pipeline-state-private.h"
 #include "cogl-snippet-private.h"
+#include "cogl-error-private.h"
 
 #include "string.h"
 
@@ -938,14 +939,13 @@ setup_blend_state (CoglBlendStringStatement *statement,
 CoglBool
 cogl_pipeline_set_blend (CoglPipeline *pipeline,
                          const char *blend_description,
-                         GError **error)
+                         CoglError **error)
 {
   CoglPipelineState state = COGL_PIPELINE_STATE_BLEND;
   CoglPipeline *authority;
   CoglBlendStringStatement statements[2];
   CoglBlendStringStatement *rgb;
   CoglBlendStringStatement *a;
-  GError *internal_error = NULL;
   int count;
   CoglPipelineBlendState *blend_state;
 
@@ -957,19 +957,9 @@ cogl_pipeline_set_blend (CoglPipeline *pipeline,
     _cogl_blend_string_compile (blend_description,
                                 COGL_BLEND_STRING_CONTEXT_BLENDING,
                                 statements,
-                                &internal_error);
+                                error);
   if (!count)
-    {
-      if (error)
-	g_propagate_error (error, internal_error);
-      else
-	{
-	  g_warning ("Cannot compile blend description: %s\n",
-		     internal_error->message);
-	  g_error_free (internal_error);
-	}
-      return FALSE;
-    }
+    return FALSE;
 
   if (count == 1)
     rgb = a = statements;
@@ -1161,7 +1151,7 @@ cogl_pipeline_set_user_program (CoglPipeline *pipeline,
 CoglBool
 cogl_pipeline_set_depth_state (CoglPipeline *pipeline,
                                const CoglDepthState *depth_state,
-                               GError **error)
+                               CoglError **error)
 {
   CoglPipelineState state = COGL_PIPELINE_STATE_DEPTH;
   CoglPipeline *authority;
@@ -1186,10 +1176,10 @@ cogl_pipeline_set_depth_state (CoglPipeline *pipeline,
       (depth_state->range_near != 0 ||
        depth_state->range_far != 1))
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "glDepthRange not available on GLES 1");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "glDepthRange not available on GLES 1");
       return FALSE;
     }
 
diff --git a/cogl/cogl-pipeline-state.h b/cogl/cogl-pipeline-state.h
index 0172046..9915e62 100644
--- a/cogl/cogl-pipeline-state.h
+++ b/cogl/cogl-pipeline-state.h
@@ -385,7 +385,7 @@ cogl_pipeline_get_alpha_test_reference (CoglPipeline *pipeline);
  * @pipeline: A #CoglPipeline object
  * @blend_string: A <link linkend="cogl-Blend-Strings">Cogl blend string</link>
  *   describing the desired blend function.
- * @error: return location for a #GError that may report lack of driver
+ * @error: return location for a #CoglError that may report lack of driver
  *   support if you give separate blend string statements for the alpha
  *   channel and RGB channels since some drivers, or backends such as
  *   GLES 1.1, don't support this feature. May be %NULL, in which case a
@@ -465,7 +465,7 @@ cogl_pipeline_get_alpha_test_reference (CoglPipeline *pipeline);
 CoglBool
 cogl_pipeline_set_blend (CoglPipeline *pipeline,
                          const char   *blend_string,
-                         GError      **error);
+                         CoglError      **error);
 
 /**
  * cogl_pipeline_set_blend_constant:
@@ -619,7 +619,7 @@ cogl_pipeline_set_user_program (CoglPipeline *pipeline,
  * cogl_pipeline_set_depth_state:
  * @pipeline: A #CoglPipeline object
  * @state: A #CoglDepthState struct
- * @error: A #GError to report failures to setup the given @state.
+ * @error: A #CoglError to report failures to setup the given @state.
  *
  * This commits all the depth state configured in @state struct to the
  * given @pipeline. The configuration values are copied into the
@@ -638,7 +638,7 @@ cogl_pipeline_set_user_program (CoglPipeline *pipeline,
 CoglBool
 cogl_pipeline_set_depth_state (CoglPipeline *pipeline,
                                const CoglDepthState *state,
-                               GError **error);
+                               CoglError **error);
 
 /**
  * cogl_pipeline_get_depth_state
diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c
index bf971a1..55e520f 100644
--- a/cogl/cogl-renderer.c
+++ b/cogl/cogl-renderer.c
@@ -43,6 +43,7 @@
 #include "cogl-winsys-private.h"
 #include "cogl-winsys-stub-private.h"
 #include "cogl-config-private.h"
+#include "cogl-error-private.h"
 
 #ifdef COGL_HAS_EGL_PLATFORM_XLIB_SUPPORT
 #include "cogl-winsys-egl-x11-private.h"
@@ -129,7 +130,7 @@ typedef struct _CoglNativeFilterClosure
   void *data;
 } CoglNativeFilterClosure;
 
-GQuark
+uint32_t
 cogl_renderer_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-renderer-error-quark");
@@ -225,7 +226,7 @@ cogl_xlib_renderer_set_event_retrieval_enabled (CoglRenderer *renderer,
 CoglBool
 cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
                                        CoglOnscreenTemplate *onscreen_template,
-                                       GError **error)
+                                       CoglError **error)
 {
   CoglDisplay *display;
 
@@ -246,7 +247,7 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
 
 static CoglBool
 _cogl_renderer_choose_driver (CoglRenderer *renderer,
-                              GError **error)
+                              CoglError **error)
 {
   const char *driver_name = g_getenv ("COGL_DRIVER");
   const char *libgl_name;
@@ -307,7 +308,7 @@ _cogl_renderer_choose_driver (CoglRenderer *renderer,
     }
 #endif
 
-  g_set_error (error,
+  _cogl_set_error (error,
                COGL_DRIVER_ERROR,
                COGL_DRIVER_ERROR_NO_SUITABLE_DRIVER_FOUND,
                "No suitable driver found");
@@ -318,7 +319,7 @@ found:
   if (support_gles2_constraint &&
       renderer->driver != COGL_DRIVER_GLES2)
     {
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_RENDERER_ERROR,
                    COGL_RENDERER_ERROR_BAD_CONSTRAINT,
                    "No suitable driver found");
@@ -332,7 +333,7 @@ found:
 
   if (renderer->libgl_module == NULL)
     {
-      g_set_error (error, COGL_DRIVER_ERROR,
+      _cogl_set_error (error, COGL_DRIVER_ERROR,
                    COGL_DRIVER_ERROR_FAILED_TO_LOAD_LIBRARY,
                    "Failed to dynamically open the GL library \"%s\"",
                    libgl_name);
@@ -368,7 +369,7 @@ found:
 /* Final connection API */
 
 CoglBool
-cogl_renderer_connect (CoglRenderer *renderer, GError **error)
+cogl_renderer_connect (CoglRenderer *renderer, CoglError **error)
 {
   int i;
   GString *error_message;
@@ -387,7 +388,7 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
   for (i = 0; i < G_N_ELEMENTS (_cogl_winsys_vtable_getters); i++)
     {
       const CoglWinsysVtable *winsys = _cogl_winsys_vtable_getters[i]();
-      GError *tmp_error = NULL;
+      CoglError *tmp_error = NULL;
       GList *l;
       CoglBool skip_due_to_constraints = FALSE;
 
@@ -430,7 +431,7 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
         {
           g_string_append_c (error_message, '\n');
           g_string_append (error_message, tmp_error->message);
-          g_error_free (tmp_error);
+          cogl_error_free (tmp_error);
         }
       else
         {
@@ -444,14 +445,14 @@ cogl_renderer_connect (CoglRenderer *renderer, GError **error)
     {
       if (constraints_failed)
         {
-          g_set_error (error, COGL_RENDERER_ERROR,
+          _cogl_set_error (error, COGL_RENDERER_ERROR,
                        COGL_RENDERER_ERROR_BAD_CONSTRAINT,
                        "Failed to connected to any renderer due to constraints");
           return FALSE;
         }
 
       renderer->winsys_vtable = NULL;
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "Failed to connected to any renderer: %s",
                    error_message->str);
diff --git a/cogl/cogl-renderer.h b/cogl/cogl-renderer.h
index c8bac6e..9766e77 100644
--- a/cogl/cogl-renderer.h
+++ b/cogl/cogl-renderer.h
@@ -32,6 +32,7 @@
 
 #include <cogl/cogl-types.h>
 #include <cogl/cogl-onscreen-template.h>
+#include <cogl/cogl-error.h>
 
 G_BEGIN_DECLS
 
@@ -75,7 +76,7 @@ G_BEGIN_DECLS
  */
 #define COGL_RENDERER_ERROR cogl_renderer_error_quark ()
 
-GQuark
+uint32_t
 cogl_renderer_error_quark (void);
 
 typedef struct _CoglRenderer CoglRenderer;
@@ -220,7 +221,7 @@ cogl_renderer_get_n_fragment_texture_units (CoglRenderer *renderer);
  * cogl_renderer_check_onscreen_template:
  * @renderer: A #CoglRenderer
  * @onscreen_template: A #CoglOnscreenTemplate
- * @error: A pointer to a #GError for reporting exceptions
+ * @error: A pointer to a #CoglError for reporting exceptions
  *
  * Tests if a given @onscreen_template can be supported with the given
  * @renderer.
@@ -233,14 +234,14 @@ cogl_renderer_get_n_fragment_texture_units (CoglRenderer *renderer);
 CoglBool
 cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
                                        CoglOnscreenTemplate *onscreen_template,
-                                       GError **error);
+                                       CoglError **error);
 
 /* Final connection API */
 
 /**
  * cogl_renderer_connect:
  * @renderer: An unconnected #CoglRenderer
- * @error a pointer to a #GError for reporting exceptions
+ * @error a pointer to a #CoglError for reporting exceptions
  *
  * Connects the configured @renderer. Renderer connection isn't a
  * very active process, it basically just means validating that
@@ -253,7 +254,7 @@ cogl_renderer_check_onscreen_template (CoglRenderer *renderer,
  * Stability: unstable
  */
 CoglBool
-cogl_renderer_connect (CoglRenderer *renderer, GError **error);
+cogl_renderer_connect (CoglRenderer *renderer, CoglError **error);
 
 /**
  * CoglRendererConstraint:
diff --git a/cogl/cogl-sdl.c b/cogl/cogl-sdl.c
index c4adbf8..03afeb7 100644
--- a/cogl/cogl-sdl.c
+++ b/cogl/cogl-sdl.c
@@ -46,7 +46,7 @@ cogl_sdl_renderer_get_event_type (CoglRenderer *renderer)
 }
 
 CoglContext *
-cogl_sdl_context_new (int type, GError **error)
+cogl_sdl_context_new (int type, CoglError **error)
 {
   CoglRenderer *renderer = cogl_renderer_new ();
   CoglDisplay *display;
diff --git a/cogl/cogl-sdl.h b/cogl/cogl-sdl.h
index 6e9c079..05da036 100644
--- a/cogl/cogl-sdl.h
+++ b/cogl/cogl-sdl.h
@@ -56,7 +56,7 @@ G_BEGIN_DECLS
  * this:
  * |[
  * MyAppData data;
- * GError *error = NULL;
+ * CoglError *error = NULL;
  *
  * data.ctx = cogl_sdl_context_new (SDL_USEREVENT, &error);
  * if (!data.ctx)
@@ -99,7 +99,7 @@ G_BEGIN_DECLS
  * cogl_sdl_context_new:
  * @type: An SDL user event type between %SDL_USEREVENT and
  *        %SDL_NUMEVENTS - %1
- * @error: A GError return location.
+ * @error: A CoglError return location.
  *
  * This is a convenience function for creating a new #CoglContext for
  * use with SDL and specifying what SDL user event type Cogl can use
@@ -132,7 +132,7 @@ G_BEGIN_DECLS
  * Stability: unstable
  */
 CoglContext *
-cogl_sdl_context_new (int type, GError **error);
+cogl_sdl_context_new (int type, CoglError **error);
 
 /**
  * cogl_sdl_renderer_set_event_type:
diff --git a/cogl/cogl-texture-2d-private.h b/cogl/cogl-texture-2d-private.h
index 823303c..a7f41b6 100644
--- a/cogl/cogl-texture-2d-private.h
+++ b/cogl/cogl-texture-2d-private.h
@@ -67,7 +67,7 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
                                      int height,
                                      CoglPixelFormat format,
                                      EGLImageKHR image,
-                                     GError **error);
+                                     CoglError **error);
 #endif
 
 /*
diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c
index d8b229e..a87cc39 100644
--- a/cogl/cogl-texture-2d-sliced.c
+++ b/cogl/cogl-texture-2d-sliced.c
@@ -45,6 +45,7 @@
 #include "cogl-journal-private.h"
 #include "cogl-pipeline-opengl-private.h"
 #include "cogl-primitive-texture.h"
+#include "cogl-error-private.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -752,7 +753,7 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
 
       for (x = 0; x < n_x_slices; ++x)
         {
-          GError *error = NULL;
+          CoglError *error = NULL;
           x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, x);
 
           COGL_NOTE (SLICING, "CREATE SLICE (%d,%d)\tsize (%d,%d)",
@@ -766,7 +767,7 @@ _cogl_texture_2d_sliced_slices_create (CoglContext *ctx,
           if (!slice_textures[y * n_x_slices + x])
             {
               g_array_set_size (tex_2ds->slice_textures, y * n_x_slices + x);
-              g_error_free (error);
+              cogl_error_free (error);
               return FALSE;
             }
         }
@@ -843,7 +844,7 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
                                       unsigned int height,
                                       int max_waste,
                                       CoglPixelFormat internal_format,
-                                      GError **error)
+                                      CoglError **error)
 {
   CoglTexture2DSliced   *tex_2ds;
 
@@ -862,10 +863,10 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
                                           internal_format))
     {
       _cogl_texture_2d_sliced_free (tex_2ds);
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_NO_MEMORY,
-                   "Not enough memory to allocate texture slices");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_NO_MEMORY,
+                       "Not enough memory to allocate texture slices");
       return NULL;
     }
 
diff --git a/cogl/cogl-texture-2d-sliced.h b/cogl/cogl-texture-2d-sliced.h
index 7ec2fed..3173d14 100644
--- a/cogl/cogl-texture-2d-sliced.h
+++ b/cogl/cogl-texture-2d-sliced.h
@@ -75,7 +75,7 @@ typedef struct _CoglTexture2DSliced CoglTexture2DSliced;
  *             are allowed in the non-power-of-two textures before
  *             they must be sliced to reduce the amount of waste.
  * @internal_format: The format of the texture
- * @error: A #GError for exceptions.
+ * @error: A #CoglError for exceptions.
  *
  * Creates a #CoglTexture2DSliced that may internally be comprised of
  * 1 or more #CoglTexture2D textures with power-of-two sizes.
@@ -97,7 +97,7 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
                                       unsigned int height,
                                       int max_waste,
                                       CoglPixelFormat internal_format,
-                                      GError **error);
+                                      CoglError **error);
 
 /**
  * cogl_is_texture_2d_sliced:
diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c
index f3f6b5f..52ce9ca 100644
--- a/cogl/cogl-texture-2d.c
+++ b/cogl/cogl-texture-2d.c
@@ -38,6 +38,7 @@
 #include "cogl-journal-private.h"
 #include "cogl-pipeline-opengl-private.h"
 #include "cogl-framebuffer-private.h"
+#include "cogl-error-private.h"
 #ifdef COGL_HAS_EGL_SUPPORT
 #include "cogl-winsys-egl-private.h"
 #endif
@@ -183,7 +184,7 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
                                int width,
                                int height,
                                CoglPixelFormat internal_format,
-                               GError **error)
+                               CoglError **error)
 {
   CoglTexture2D         *tex_2d;
   GLenum                 gl_intformat;
@@ -196,10 +197,10 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
 
   if (!_cogl_texture_2d_can_create (ctx, width, height, internal_format))
     {
-      g_set_error (error, COGL_TEXTURE_ERROR,
-                   COGL_TEXTURE_ERROR_SIZE,
-                   "Failed to create texture 2d due to size/format"
-                   " constraints");
+      _cogl_set_error (error, COGL_TEXTURE_ERROR,
+                       COGL_TEXTURE_ERROR_SIZE,
+                       "Failed to create texture 2d due to size/format"
+                       " constraints");
       return NULL;
     }
 
@@ -226,7 +227,7 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
 CoglTexture2D *
 cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
                                  CoglPixelFormat internal_format,
-                                 GError **error)
+                                 CoglError **error)
 {
   CoglTexture2D *tex_2d;
   CoglBitmap *dst_bmp;
@@ -249,10 +250,10 @@ cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
                                     cogl_bitmap_get_height (bmp),
                                     internal_format))
     {
-      g_set_error (error, COGL_TEXTURE_ERROR,
-                   COGL_TEXTURE_ERROR_SIZE,
-                   "Failed to create texture 2d due to size/format"
-                   " constraints");
+      _cogl_set_error (error, COGL_TEXTURE_ERROR,
+                       COGL_TEXTURE_ERROR_SIZE,
+                       "Failed to create texture 2d due to size/format"
+                       " constraints");
       return NULL;
 
     }
@@ -264,9 +265,9 @@ cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp,
                                                    &gl_format,
                                                    &gl_type)) == NULL)
     {
-      g_set_error (error, COGL_TEXTURE_ERROR,
-                   COGL_TEXTURE_ERROR_FORMAT,
-                   "Failed to prepare texture upload due to format");
+      _cogl_set_error (error, COGL_TEXTURE_ERROR,
+                       COGL_TEXTURE_ERROR_FORMAT,
+                       "Failed to prepare texture upload due to format");
       return NULL;
     }
 
@@ -315,7 +316,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
                                CoglPixelFormat internal_format,
                                int rowstride,
                                const uint8_t *data,
-                               GError **error)
+                               CoglError **error)
 {
   CoglBitmap *bmp;
   CoglTexture2D *tex_2d;
@@ -349,7 +350,7 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
                                   int width,
                                   int height,
                                   CoglPixelFormat format,
-                                  GError **error)
+                                  CoglError **error)
 {
   /* NOTE: width, height and internal format are not queriable
    * in GLES, hence such a function prototype.
@@ -365,9 +366,9 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
 
   if (!ctx->texture_driver->allows_foreign_gl_target (ctx, GL_TEXTURE_2D))
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
+      _cogl_set_error (error,
+                   COGL_SYSTEM_ERROR,
+                   COGL_SYSTEM_ERROR_UNSUPPORTED,
                    "Foreign GL_TEXTURE_2D textures are not "
                    "supported by your system");
       return NULL;
@@ -381,10 +382,10 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
   _cogl_bind_gl_texture_transient (GL_TEXTURE_2D, gl_handle, TRUE);
   if (ctx->glGetError () != GL_NO_ERROR)
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "Failed to bind foreign GL_TEXTURE_2D texture");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "Failed to bind foreign GL_TEXTURE_2D texture");
       return NULL;
     }
 
@@ -414,10 +415,10 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
                                                               gl_int_format,
                                                               &format))
         {
-          g_set_error (error,
-                       COGL_ERROR,
-                       COGL_ERROR_UNSUPPORTED,
-                       "Unsupported internal format for foreign texture");
+          _cogl_set_error (error,
+                           COGL_SYSTEM_ERROR,
+                           COGL_SYSTEM_ERROR_UNSUPPORTED,
+                           "Unsupported internal format for foreign texture");
           return NULL;
         }
     }
@@ -446,10 +447,10 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
   /* Compressed texture images not supported */
   if (gl_compressed == GL_TRUE)
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "Compressed foreign textures aren't currently supported");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "Compressed foreign textures aren't currently supported");
       return NULL;
     }
 
@@ -496,7 +497,7 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
                                      int height,
                                      CoglPixelFormat format,
                                      EGLImageKHR image,
-                                     GError **error)
+                                     CoglError **error)
 {
   CoglTexture2D *tex_2d;
   GLenum gl_error;
@@ -523,10 +524,11 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
   ctx->glEGLImageTargetTexture2D (GL_TEXTURE_2D, image);
   if (ctx->glGetError () != GL_NO_ERROR)
     {
-      g_set_error (error,
-                   COGL_TEXTURE_ERROR,
-                   COGL_TEXTURE_ERROR_BAD_PARAMETER,
-                   "Could not create a CoglTexture2D from a given EGLImage");
+      _cogl_set_error (error,
+                       COGL_TEXTURE_ERROR,
+                       COGL_TEXTURE_ERROR_BAD_PARAMETER,
+                       "Could not create a CoglTexture2D from a given "
+                       "EGLImage");
       return NULL;
     }
 
@@ -538,7 +540,7 @@ _cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
 CoglTexture2D *
 cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
                                          struct wl_buffer *buffer,
-                                         GError **error)
+                                         CoglError **error)
 {
   if (wl_buffer_is_shm (buffer))
     {
diff --git a/cogl/cogl-texture-2d.h b/cogl/cogl-texture-2d.h
index 7316738..1fc3d12 100644
--- a/cogl/cogl-texture-2d.h
+++ b/cogl/cogl-texture-2d.h
@@ -75,7 +75,7 @@ cogl_is_texture_2d (void *object);
  * @width: Width of the texture to allocate
  * @height: Height of the texture to allocate
  * @internal_format: The format of the texture
- * @error: A #GError for exceptions
+ * @error: A #CoglError for exceptions
  *
  * Allocates a low-level #CoglTexture2D texture that your GPU can
  * texture from directly. This is unlike sliced textures for example
@@ -100,7 +100,7 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
                                int width,
                                int height,
                                CoglPixelFormat internal_format,
-                               GError **error);
+                               CoglError **error);
 
 /**
  * cogl_texture_2d_new_from_data:
@@ -120,7 +120,7 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
  *    scanlines in @data. A value of 0 will make Cogl automatically
  *    calculate @rowstride from @width and @format.
  * @data: pointer the memory region where the source buffer resides
- * @error: A #GError for exceptions
+ * @error: A #CoglError for exceptions
  *
  * Creates a new #CoglTexture2D texture based on data residing in memory.
  * These are unlike sliced textures for example which may be comprised
@@ -147,7 +147,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
                                CoglPixelFormat internal_format,
                                int rowstride,
                                const uint8_t *data,
-                               GError **error);
+                               CoglError **error);
 
 /**
  * cogl_texture_2d_new_from_bitmap:
@@ -160,7 +160,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
  *    is if you have non-premultiplied source data and are going to adjust
  *    the blend mode (see cogl_pipeline_set_blend()) or use the data for
  *    something other than straight blending.
- * @error: A #GError for exceptions
+ * @error: A #CoglError for exceptions
  *
  * Creates a new #CoglTexture2D texture based on data residing in a
  * bitmap. These are unlike sliced textures for example which may be
@@ -184,7 +184,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
 CoglTexture2D *
 cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap,
                                  CoglPixelFormat internal_format,
-                                 GError **error);
+                                 CoglError **error);
 
 
 /**
@@ -194,7 +194,7 @@ cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap,
  * @width: Width of the foreign GL texture
  * @height: Height of the foreign GL texture
  * @internal_format: The format of the texture
- * @error: A #GError for exceptions
+ * @error: A #CoglError for exceptions
  *
  * Wraps an existing GL_TEXTURE_2D texture object as a #CoglTexture2D.
  * This can be used for integrating Cogl with software using OpenGL
@@ -217,7 +217,7 @@ cogl_texture_2d_new_from_foreign (CoglContext *ctx,
                                   int width,
                                   int height,
                                   CoglPixelFormat format,
-                                  GError **error);
+                                  CoglError **error);
 
 G_END_DECLS
 
diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c
index 1a2b84d..7b781cb 100644
--- a/cogl/cogl-texture-3d.c
+++ b/cogl/cogl-texture-3d.c
@@ -37,6 +37,7 @@
 #include "cogl-journal-private.h"
 #include "cogl-pipeline-private.h"
 #include "cogl-pipeline-opengl-private.h"
+#include "cogl-error-private.h"
 
 #include <string.h>
 #include <math.h>
@@ -145,7 +146,7 @@ _cogl_texture_3d_can_create (CoglContext *ctx,
                              int height,
                              int depth,
                              CoglPixelFormat internal_format,
-                             GError **error)
+                             CoglError **error)
 {
   GLenum gl_intformat;
   GLenum gl_type;
@@ -153,10 +154,10 @@ _cogl_texture_3d_can_create (CoglContext *ctx,
   /* This should only happen on GLES */
   if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_3D))
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "3D textures are not supported by the GPU");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "3D textures are not supported by the GPU");
       return FALSE;
     }
 
@@ -167,11 +168,11 @@ _cogl_texture_3d_can_create (CoglContext *ctx,
        !_cogl_util_is_pot (height) ||
        !_cogl_util_is_pot (depth)))
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "A non-power-of-two size was requested but this is not "
-                   "supported by the GPU");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "A non-power-of-two size was requested but this is not "
+                       "supported by the GPU");
       return FALSE;
     }
 
@@ -190,10 +191,10 @@ _cogl_texture_3d_can_create (CoglContext *ctx,
                                                height,
                                                depth))
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "The requested dimensions are not supported by the GPU");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "The requested dimensions are not supported by the GPU");
       return FALSE;
     }
 
@@ -206,7 +207,7 @@ cogl_texture_3d_new_with_size (CoglContext *ctx,
                                int height,
                                int depth,
                                CoglPixelFormat internal_format,
-                               GError **error)
+                               CoglError **error)
 {
   CoglTexture3D         *tex_3d;
   GLenum                 gl_intformat;
@@ -248,7 +249,7 @@ cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
                                  unsigned int height,
                                  unsigned int depth,
                                  CoglPixelFormat internal_format,
-                                 GError **error)
+                                 CoglError **error)
 {
   CoglTexture3D *tex_3d;
   CoglBitmap *dst_bmp;
@@ -283,8 +284,8 @@ cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp,
 
   if (dst_bmp == NULL)
     {
-      g_set_error (error, COGL_BITMAP_ERROR, COGL_BITMAP_ERROR_FAILED,
-                   "Bitmap conversion failed");
+      _cogl_set_error (error, COGL_BITMAP_ERROR, COGL_BITMAP_ERROR_FAILED,
+                       "Bitmap conversion failed");
       return NULL;
     }
 
@@ -337,13 +338,13 @@ cogl_texture_3d_new_from_data (CoglContext *context,
                                int rowstride,
                                int image_stride,
                                const uint8_t *data,
-                               GError **error)
+                               CoglError **error)
 {
   CoglBitmap *bitmap;
   CoglTexture3D *ret;
 
   /* These are considered a programmer errors so we won't set a
-     GError. It would be nice if this was a _COGL_RETURN_IF_FAIL but the
+     CoglError. It would be nice if this was a _COGL_RETURN_IF_FAIL but the
      rest of Cogl isn't using that */
   if (format == COGL_PIXEL_FORMAT_ANY)
     return NULL;
diff --git a/cogl/cogl-texture-3d.h b/cogl/cogl-texture-3d.h
index 019be51..1956b4d 100644
--- a/cogl/cogl-texture-3d.h
+++ b/cogl/cogl-texture-3d.h
@@ -57,12 +57,12 @@ typedef struct _CoglTexture3D CoglTexture3D;
  * @depth: depth of the texture in pixels.
  * @internal_format: the #CoglPixelFormat to use for the GPU
  *    storage of the texture.
- * @error: A GError return location.
+ * @error: A CoglError return location.
  *
  * Creates a new Cogl 3D texture with the specified dimensions and
  * pixel format.
  *
- * Note that this function will throw a #GError if
+ * Note that this function will throw a #CoglError if
  * %COGL_FEATURE_TEXTURE_3D is not advertised. It can also fail if the
  * requested dimensions are not supported by the GPU.
  *
@@ -78,7 +78,7 @@ cogl_texture_3d_new_with_size (CoglContext *context,
                                int height,
                                int depth,
                                CoglPixelFormat  internal_format,
-                               GError **error);
+                               CoglError **error);
 
 /**
  * cogl_texture_3d_new_from_data:
@@ -103,13 +103,13 @@ cogl_texture_3d_new_with_size (CoglContext *context,
  *    rows. Alternatively 0 can be passed to infer the @image_stride
  *    from the @height.
  * @data: pointer the memory region where the source buffer resides
- * @error: A GError return location.
+ * @error: A CoglError return location.
  *
  * Creates a new 3D texture and initializes it with @data. The data is
  * assumed to be packed array of @depth images. There can be padding
  * between the images using @image_stride.
  *
- * Note that this function will throw a #GError if
+ * Note that this function will throw a #CoglError if
  * %COGL_FEATURE_TEXTURE_3D is not advertised. It can also fail if the
  * requested dimensions are not supported by the GPU.
  *
@@ -129,7 +129,7 @@ cogl_texture_3d_new_from_data (CoglContext *context,
                                int rowstride,
                                int image_stride,
                                const uint8_t *data,
-                               GError **error);
+                               CoglError **error);
 
 /**
  * cogl_texture_3d_new_from_bitmap:
@@ -144,7 +144,7 @@ cogl_texture_3d_new_from_data (CoglContext *context,
  *    is if you have non-premultiplied source data and are going to adjust
  *    the blend mode (see cogl_pipeline_set_blend()) or use the data for
  *    something other than straight blending.
- * @error: A GError return location.
+ * @error: A CoglError return location.
  *
  * Creates a new 3D texture and initializes it with the images in
  * @bitmap. The images are assumed to be packed together after one
@@ -163,7 +163,7 @@ cogl_texture_3d_new_from_bitmap (CoglBitmap *bitmap,
                                  unsigned int height,
                                  unsigned int depth,
                                  CoglPixelFormat internal_format,
-                                 GError **error);
+                                 CoglError **error);
 
 /**
  * cogl_is_texture_3d:
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
index e87c707..2b55564 100644
--- a/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl-texture-rectangle.c
@@ -37,6 +37,7 @@
 #include "cogl-object-private.h"
 #include "cogl-journal-private.h"
 #include "cogl-pipeline-opengl-private.h"
+#include "cogl-error-private.h"
 
 #include <string.h>
 #include <math.h>
@@ -112,7 +113,7 @@ _cogl_texture_rectangle_can_create (CoglContext *ctx,
                                     unsigned int width,
                                     unsigned int height,
                                     CoglPixelFormat internal_format,
-                                    GError **error)
+                                    CoglError **error)
 {
   GLenum gl_intformat;
   GLenum gl_format;
@@ -120,10 +121,10 @@ _cogl_texture_rectangle_can_create (CoglContext *ctx,
 
   if (!cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_RECTANGLE))
     {
-      g_set_error (error,
-                   COGL_TEXTURE_ERROR,
-                   COGL_TEXTURE_ERROR_TYPE,
-                   "The CoglTextureRectangle feature isn't available");
+      _cogl_set_error (error,
+                       COGL_TEXTURE_ERROR,
+                       COGL_TEXTURE_ERROR_TYPE,
+                       "The CoglTextureRectangle feature isn't available");
       return FALSE;
     }
 
@@ -142,10 +143,10 @@ _cogl_texture_rectangle_can_create (CoglContext *ctx,
                                             width,
                                             height))
     {
-      g_set_error (error,
-                   COGL_TEXTURE_ERROR,
-                   COGL_TEXTURE_ERROR_SIZE,
-                   "The requested texture size + format is unsupported");
+      _cogl_set_error (error,
+                       COGL_TEXTURE_ERROR,
+                       COGL_TEXTURE_ERROR_SIZE,
+                       "The requested texture size + format is unsupported");
       return FALSE;
     }
 
@@ -192,7 +193,7 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
                                       int width,
                                       int height,
                                       CoglPixelFormat internal_format,
-                                      GError **error)
+                                      CoglError **error)
 {
   CoglTextureRectangle *tex_rect;
   GLenum                gl_intformat;
@@ -234,7 +235,7 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
 CoglTextureRectangle *
 cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp,
                                         CoglPixelFormat internal_format,
-                                        GError **error)
+                                        CoglError **error)
 {
   CoglTextureRectangle *tex_rect;
   CoglBitmap           *dst_bmp;
@@ -299,7 +300,7 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
                                          int width,
                                          int height,
                                          CoglPixelFormat format,
-                                         GError **error)
+                                         CoglError **error)
 {
   /* NOTE: width, height and internal format are not queriable
    * in GLES, hence such a function prototype.
@@ -316,11 +317,11 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
   if (!ctx->texture_driver->allows_foreign_gl_target (ctx,
                                                       GL_TEXTURE_RECTANGLE_ARB))
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "Foreign GL_TEXTURE_RECTANGLE textures are not "
-                   "supported by your system");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "Foreign GL_TEXTURE_RECTANGLE textures are not "
+                       "supported by your system");
       return NULL;
     }
 
@@ -331,10 +332,10 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
   _cogl_bind_gl_texture_transient (GL_TEXTURE_RECTANGLE_ARB, gl_handle, TRUE);
   if (ctx->glGetError () != GL_NO_ERROR)
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "Failed to bind foreign GL_TEXTURE_RECTANGLE texture");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "Failed to bind foreign GL_TEXTURE_RECTANGLE texture");
       return NULL;
     }
 
@@ -361,10 +362,10 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
                                                               gl_int_format,
                                                               &format))
         {
-          g_set_error (error,
-                       COGL_ERROR,
-                       COGL_ERROR_UNSUPPORTED,
-                       "Unsupported internal format for foreign texture");
+          _cogl_set_error (error,
+                           COGL_SYSTEM_ERROR,
+                           COGL_SYSTEM_ERROR_UNSUPPORTED,
+                           "Unsupported internal format for foreign texture");
           return NULL;
         }
     }
@@ -393,10 +394,10 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
   /* Compressed texture images not supported */
   if (gl_compressed == GL_TRUE)
     {
-      g_set_error (error,
-                   COGL_ERROR,
-                   COGL_ERROR_UNSUPPORTED,
-                   "Compressed foreign textures aren't currently supported");
+      _cogl_set_error (error,
+                       COGL_SYSTEM_ERROR,
+                       COGL_SYSTEM_ERROR_UNSUPPORTED,
+                       "Compressed foreign textures aren't currently supported");
       return NULL;
     }
 
diff --git a/cogl/cogl-texture-rectangle.h b/cogl/cogl-texture-rectangle.h
index b97bbc2..20de97d 100644
--- a/cogl/cogl-texture-rectangle.h
+++ b/cogl/cogl-texture-rectangle.h
@@ -82,7 +82,7 @@ cogl_is_texture_rectangle (void *object);
  * @width: The texture width to allocate
  * @height: The texture height to allocate
  * @internal_format: The desired internal texture format
- * @error: An optional GError pointer for reporting exceptions
+ * @error: An optional CoglError pointer for reporting exceptions
  *
  * Allocates a new #CoglTextureRectangle texture with a given @width, @height
  * and @internal_format. This texture is a low-level texture that
@@ -114,14 +114,14 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
                                       int width,
                                       int height,
                                       CoglPixelFormat internal_format,
-                                      GError **error);
+                                      CoglError **error);
 
 /**
  * cogl_texture_rectangle_new_from_bitmap:
  * @bitmap: A #CoglBitmap
  * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
  *    texture
- * @error: A return location for a GError or %NULL
+ * @error: A return location for a CoglError or %NULL
  *
  * Allocates a new #CoglTextureRectangle texture which will be
  * initialized with the pixel data from @bitmap. Internally the data
@@ -152,7 +152,7 @@ cogl_texture_rectangle_new_with_size (CoglContext *ctx,
 CoglTextureRectangle *
 cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap,
                                         CoglPixelFormat internal_format,
-                                        GError **error);
+                                        CoglError **error);
 
 /**
  * cogl_texture_rectangle_new_from_foreign:
@@ -161,7 +161,7 @@ cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bitmap,
  * @width: Width of the foreign GL texture
  * @height: Height of the foreign GL texture
  * @internal_format: The format of the texture
- * @error: A #GError for exceptions
+ * @error: A #CoglError for exceptions
  *
  * Wraps an existing GL_TEXTURE_RECTANGLE texture object as a
  * #CoglTextureRectangle.  This can be used for integrating Cogl with
@@ -197,7 +197,7 @@ cogl_texture_rectangle_new_from_foreign (CoglContext *ctx,
                                          int width,
                                          int height,
                                          CoglPixelFormat format,
-                                         GError **error);
+                                         CoglError **error);
 
 G_END_DECLS
 
diff --git a/cogl/cogl-texture.c b/cogl/cogl-texture.c
index e89c868..7155898 100644
--- a/cogl/cogl-texture.c
+++ b/cogl/cogl-texture.c
@@ -59,7 +59,7 @@
 #include <stdlib.h>
 #include <math.h>
 
-GQuark
+uint32_t
 cogl_texture_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-texture-error-quark");
@@ -446,7 +446,7 @@ CoglTexture *
 cogl_texture_new_from_file (const char        *filename,
                             CoglTextureFlags   flags,
                             CoglPixelFormat    internal_format,
-                            GError           **error)
+                            CoglError           **error)
 {
   CoglBitmap *bmp;
   CoglTexture *texture = NULL;
diff --git a/cogl/cogl-texture.h b/cogl/cogl-texture.h
index 0aa4e40..cd3f394 100644
--- a/cogl/cogl-texture.h
+++ b/cogl/cogl-texture.h
@@ -58,7 +58,7 @@ G_BEGIN_DECLS
 /**
  * COGL_TEXTURE_ERROR:
  *
- * #GError domain for texture errors.
+ * #CoglError domain for texture errors.
  *
  * Since: 2.0
  * Stability: Unstable
@@ -100,7 +100,7 @@ typedef enum {
   COGL_TEXTURE_TYPE_RECTANGLE
 } CoglTextureType;
 
-GQuark cogl_texture_error_quark (void);
+uint32_t cogl_texture_error_quark (void);
 
 /**
  * cogl_texture_new_with_size:
@@ -134,7 +134,7 @@ cogl_texture_new_with_size (unsigned int width,
  *    have non-premultiplied source data and are going to adjust the blend
  *    mode (see cogl_material_set_blend()) or use the data for something
  *    other than straight blending.
- * @error: return location for a #GError or %NULL
+ * @error: return location for a #CoglError or %NULL
  *
  * Creates a #CoglTexture from an image file.
  *
@@ -146,7 +146,7 @@ CoglTexture *
 cogl_texture_new_from_file (const char       *filename,
                             CoglTextureFlags   flags,
                             CoglPixelFormat    internal_format,
-                            GError           **error);
+                            CoglError           **error);
 
 /**
  * cogl_texture_new_from_data:
diff --git a/cogl/cogl-types.h b/cogl/cogl-types.h
index cd527e5..0a9074f 100644
--- a/cogl/cogl-types.h
+++ b/cogl/cogl-types.h
@@ -566,7 +566,7 @@ typedef enum {
 /**
  * COGL_BLEND_STRING_ERROR:
  *
- * #GError domain for blend string parser errors
+ * #CoglError domain for blend string parser errors
  *
  * Since: 1.0
  */
@@ -591,28 +591,28 @@ typedef enum { /*< prefix=COGL_BLEND_STRING_ERROR >*/
   COGL_BLEND_STRING_ERROR_GPU_UNSUPPORTED_ERROR
 } CoglBlendStringError;
 
-GQuark
+uint32_t
 cogl_blend_string_error_quark (void);
 
-#define COGL_ERROR (_cogl_error_quark ())
+#define COGL_SYSTEM_ERROR (_cogl_system_error_quark ())
 
 /**
- * CoglError:
- * @COGL_ERROR_UNSUPPORTED: You tried to use a feature or
+ * CoglSystemError:
+ * @COGL_SYSTEM_ERROR_UNSUPPORTED: You tried to use a feature or
  *    configuration not currently available.
- * @COGL_ERROR_NO_MEMORY: You tried to allocate a resource
+ * @COGL_SYSTEM_ERROR_NO_MEMORY: You tried to allocate a resource
  *    such as a texture and there wasn't enough memory.
  *
  * Error enumeration for Cogl
  *
- * The @COGL_ERROR_UNSUPPORTED error can be thrown for a variety of
- * reasons. For example:
+ * The @COGL_SYSTEM_ERROR_UNSUPPORTED error can be thrown for a
+ * variety of reasons. For example:
  *
  * <itemizedlist>
  *  <listitem><para>You've tried to use a feature that is not
- *   advertised by cogl_get_features(). This could happen if you create
+ *   advertised by cogl_has_feature(). This could happen if you create
  *   a 2d texture with a non-power-of-two size when
- *   %COGL_FEATURE_TEXTURE_NPOT is not advertised.</para></listitem>
+ *   %COGL_FEATURE_ID_TEXTURE_NPOT is not advertised.</para></listitem>
  *  <listitem><para>The GPU can not handle the configuration you have
  *   requested. An example might be if you try to use too many texture
  *   layers in a single #CoglPipeline</para></listitem>
@@ -627,12 +627,12 @@ cogl_blend_string_error_quark (void);
  * Stability: unstable
  */
 typedef enum { /*< prefix=COGL_ERROR >*/
-  COGL_ERROR_UNSUPPORTED,
-  COGL_ERROR_NO_MEMORY
-} CoglError;
+  COGL_SYSTEM_ERROR_UNSUPPORTED,
+  COGL_SYSTEM_ERROR_NO_MEMORY
+} CoglSystemError;
 
-GQuark
-_cogl_error_quark (void);
+uint32_t
+_cogl_system_error_quark (void);
 
 /**
  * CoglAttributeType:
diff --git a/cogl/cogl-wayland-server.h b/cogl/cogl-wayland-server.h
index 315af22..6e66292 100644
--- a/cogl/cogl-wayland-server.h
+++ b/cogl/cogl-wayland-server.h
@@ -54,7 +54,7 @@ cogl_wayland_display_set_compositor_display (CoglDisplay *display,
  * cogl_wayland_texture_2d_new_from_buffer:
  * @ctx: A #CoglContext
  * @buffer: A Wayland buffer
- * @error: A #GError for exceptions
+ * @error: A #CoglError for exceptions
  *
  * Uploads the given Wayland @buffer to a #CoglTexture2D.
  *
@@ -77,7 +77,7 @@ cogl_wayland_display_set_compositor_display (CoglDisplay *display,
 CoglTexture2D *
 cogl_wayland_texture_2d_new_from_buffer (CoglContext *ctx,
                                          struct wl_buffer *buffer,
-                                         GError **error);
+                                         CoglError **error);
 
 G_END_DECLS
 
diff --git a/cogl/cogl-xlib-renderer-private.h b/cogl/cogl-xlib-renderer-private.h
index 0c73b5c..4970f20 100644
--- a/cogl/cogl-xlib-renderer-private.h
+++ b/cogl/cogl-xlib-renderer-private.h
@@ -44,7 +44,7 @@ typedef struct _CoglXlibRenderer
 } CoglXlibRenderer;
 
 CoglBool
-_cogl_xlib_renderer_connect (CoglRenderer *renderer, GError **error);
+_cogl_xlib_renderer_connect (CoglRenderer *renderer, CoglError **error);
 
 void
 _cogl_xlib_renderer_disconnect (CoglRenderer *renderer);
diff --git a/cogl/cogl-xlib-renderer.c b/cogl/cogl-xlib-renderer.c
index 9ae7765..713df7f 100644
--- a/cogl/cogl-xlib-renderer.c
+++ b/cogl/cogl-xlib-renderer.c
@@ -37,6 +37,7 @@
 #include "cogl-xlib-renderer-private.h"
 #include "cogl-x11-renderer-private.h"
 #include "cogl-winsys-private.h"
+#include "cogl-error-private.h"
 
 #include <X11/Xlib.h>
 #include <X11/extensions/Xdamage.h>
@@ -164,7 +165,7 @@ _cogl_xlib_renderer_untrap_errors (CoglRenderer *renderer,
 }
 
 static Display *
-assert_xlib_display (CoglRenderer *renderer, GError **error)
+assert_xlib_display (CoglRenderer *renderer, CoglError **error)
 {
   Display *xdpy = cogl_xlib_renderer_get_foreign_display (renderer);
   CoglXlibRenderer *xlib_renderer = _cogl_xlib_renderer_get_data (renderer);
@@ -179,7 +180,7 @@ assert_xlib_display (CoglRenderer *renderer, GError **error)
   xdpy = XOpenDisplay (_cogl_x11_display_name);
   if (xdpy == NULL)
     {
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_RENDERER_ERROR,
                    COGL_RENDERER_ERROR_XLIB_DISPLAY_OPEN,
                    "Failed to open X Display %s", _cogl_x11_display_name);
@@ -191,7 +192,7 @@ assert_xlib_display (CoglRenderer *renderer, GError **error)
 }
 
 CoglBool
-_cogl_xlib_renderer_connect (CoglRenderer *renderer, GError **error)
+_cogl_xlib_renderer_connect (CoglRenderer *renderer, CoglError **error)
 {
   CoglXlibRenderer *xlib_renderer =
     _cogl_xlib_renderer_get_data (renderer);
diff --git a/cogl/cogl.c b/cogl/cogl.c
index eda6efa..5ccfcfb 100644
--- a/cogl/cogl.c
+++ b/cogl/cogl.c
@@ -559,7 +559,7 @@ cogl_set_projection_matrix (CoglMatrix *matrix)
   cogl_framebuffer_set_projection_matrix (cogl_get_draw_framebuffer (), matrix);
 }
 
-GQuark
+uint32_t
 _cogl_driver_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-driver-error-quark");
@@ -784,10 +784,10 @@ _cogl_transform_point (const CoglMatrix *matrix_mv,
 #undef VIEWPORT_TRANSFORM_X
 #undef VIEWPORT_TRANSFORM_Y
 
-GQuark
-_cogl_error_quark (void)
+uint32_t
+_cogl_system_error_quark (void)
 {
-  return g_quark_from_static_string ("cogl-error-quark");
+  return g_quark_from_static_string ("cogl-system-error-quark");
 }
 
 void
diff --git a/cogl/cogl.h b/cogl/cogl.h
index 797cdb7..5f939e6 100644
--- a/cogl/cogl.h
+++ b/cogl/cogl.h
@@ -46,6 +46,7 @@
  */
 
 #include <cogl/cogl-defines.h>
+#include <cogl/cogl-error.h>
 
 #include <cogl/cogl-object.h>
 #include <cogl/cogl1-context.h>
diff --git a/cogl/cogl.symbols b/cogl/cogl.symbols
index 58c82c5..3d38555 100644
--- a/cogl/cogl.symbols
+++ b/cogl/cogl.symbols
@@ -37,7 +37,7 @@ cogl_attribute_type_get_type
 cogl_begin_gl
 
 cogl_bitmap_error_get_type
-cogl_bitmap_error_quark
+cogl_bitmap_error_domain
 cogl_bitmap_get_buffer
 cogl_bitmap_get_format
 cogl_bitmap_get_height
@@ -49,7 +49,7 @@ cogl_bitmap_new_from_file
 cogl_bitmap_new_from_buffer
 cogl_bitmap_new_with_size
 cogl_blend_string_error_get_type
-cogl_blend_string_error_quark
+cogl_blend_string_error_domain
 
 cogl_buffer_bit_get_type
 cogl_buffer_get_size
@@ -216,7 +216,7 @@ cogl_framebuffer_draw_rectangle
 cogl_framebuffer_draw_rectangles
 cogl_framebuffer_draw_textured_rectangle
 cogl_framebuffer_draw_textured_rectangles
-cogl_framebuffer_error_quark
+cogl_framebuffer_error_domain
 cogl_framebuffer_fill_path
 cogl_framebuffer_finish
 cogl_framebuffer_frustum
@@ -695,7 +695,7 @@ cogl_renderer_connect
 cogl_renderer_get_driver
 cogl_renderer_get_n_fragment_texture_units
 cogl_renderer_error_get_type
-cogl_renderer_error_quark
+cogl_renderer_error_domain
 cogl_renderer_get_winsys_id
 cogl_renderer_new
 cogl_renderer_remove_constraint
@@ -766,7 +766,7 @@ cogl_swap_chain_new
 cogl_swap_chain_set_has_alpha
 cogl_swap_chain_set_length
 
-cogl_texture_error_quark
+cogl_texture_error_domain
 cogl_texture_flags_get_type
 cogl_texture_get_data
 cogl_texture_get_format
@@ -783,7 +783,7 @@ cogl_texture_new_from_foreign
 cogl_texture_new_from_sub_texture
 cogl_texture_new_with_size
 #ifdef COGL_HAS_X11
-cogl_texture_pixmap_x11_error_quark
+cogl_texture_pixmap_x11_error_domain
 cogl_texture_pixmap_x11_is_using_tfp_extension
 cogl_texture_pixmap_x11_new
 cogl_texture_pixmap_x11_set_damage_object
@@ -908,7 +908,7 @@ _cogl_atlas_texture_new_from_bitmap
 _cogl_atlas_texture_new_with_size
 _cogl_atlas_texture_remove_reorganize_callback
 _cogl_context_get_default
-_cogl_error_quark
+_cogl_system_error_domain
 _cogl_texture_associate_framebuffer
 _cogl_texture_can_hardware_repeat
 _cogl_texture_determine_internal_format
diff --git a/cogl/cogl2-compatibility.c b/cogl/cogl2-compatibility.c
index a474c89..fa03368 100644
--- a/cogl/cogl2-compatibility.c
+++ b/cogl/cogl2-compatibility.c
@@ -57,7 +57,7 @@ cogl_texture_3d_error_quark (void);
 
 CoglBool
 cogl_index_buffer_allocate (CoglIndexBuffer *indices,
-                            GError *error);
+                            CoglError *error);
 
 CoglBool
 cogl_is_journal (void *object);
@@ -97,7 +97,7 @@ cogl_texture_3d_error_quark (void)
 
 CoglBool
 cogl_index_buffer_allocate (CoglIndexBuffer *indices,
-                            GError *error)
+                            CoglError *error)
 {
   return TRUE;
 }
diff --git a/cogl/driver/gl/cogl-framebuffer-gl-private.h b/cogl/driver/gl/cogl-framebuffer-gl-private.h
index 4a616a1..5ab3817 100644
--- a/cogl/driver/gl/cogl-framebuffer-gl-private.h
+++ b/cogl/driver/gl/cogl-framebuffer-gl-private.h
@@ -30,7 +30,7 @@
 
 CoglBool
 _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
-                             GError **error);
+                             CoglError **error);
 
 void
 _cogl_offscreen_gl_free (CoglOffscreen *offscreen);
diff --git a/cogl/driver/gl/cogl-framebuffer-gl.c b/cogl/driver/gl/cogl-framebuffer-gl.c
index 38ef260..d1e18b6 100644
--- a/cogl/driver/gl/cogl-framebuffer-gl.c
+++ b/cogl/driver/gl/cogl-framebuffer-gl.c
@@ -29,6 +29,7 @@
 #include "cogl-context-private.h"
 #include "cogl-framebuffer-private.h"
 #include "cogl-framebuffer-gl-private.h"
+#include "cogl-error-private.h"
 
 #include <glib.h>
 
@@ -692,7 +693,7 @@ _cogl_framebuffer_try_creating_gl_fbo (CoglContext *ctx,
 
 CoglBool
 _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
-                             GError **error)
+                             CoglError **error)
 {
   CoglFramebuffer *fb = COGL_FRAMEBUFFER (offscreen);
   CoglContext *ctx = fb->context;
@@ -711,9 +712,9 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
         _cogl_texture_associate_framebuffer (offscreen->depth_texture, fb);
       else
         {
-          g_set_error (error, COGL_FRAMEBUFFER_ERROR,
-                       COGL_FRAMEBUFFER_ERROR_ALLOCATE,
-                       "Failed to allocate depth texture for framebuffer");
+          _cogl_set_error (error, COGL_FRAMEBUFFER_ERROR,
+                           COGL_FRAMEBUFFER_ERROR_ALLOCATE,
+                           "Failed to allocate depth texture for framebuffer");
         }
     }
 
@@ -824,9 +825,9 @@ _cogl_offscreen_gl_allocate (CoglOffscreen *offscreen,
     }
   else
     {
-      g_set_error (error, COGL_FRAMEBUFFER_ERROR,
-                   COGL_FRAMEBUFFER_ERROR_ALLOCATE,
-                   "Failed to create an OpenGL framebuffer object");
+      _cogl_set_error (error, COGL_FRAMEBUFFER_ERROR,
+                       COGL_FRAMEBUFFER_ERROR_ALLOCATE,
+                       "Failed to create an OpenGL framebuffer object");
       return FALSE;
     }
 }
diff --git a/cogl/driver/gl/gl/cogl-driver-gl.c b/cogl/driver/gl/gl/cogl-driver-gl.c
index 991440f..593942b 100644
--- a/cogl/driver/gl/gl/cogl-driver-gl.c
+++ b/cogl/driver/gl/gl/cogl-driver-gl.c
@@ -33,6 +33,7 @@
 #include "cogl-feature-private.h"
 #include "cogl-renderer-private.h"
 #include "cogl-framebuffer-gl-private.h"
+#include "cogl-error-private.h"
 
 static CoglBool
 _cogl_driver_pixel_format_from_gl_internal (CoglContext *context,
@@ -276,14 +277,14 @@ _cogl_get_gl_version (CoglContext *ctx,
 
 static CoglBool
 check_gl_version (CoglContext *ctx,
-                  GError **error)
+                  CoglError **error)
 {
   int major, minor;
   const char *gl_extensions;
 
   if (!_cogl_get_gl_version (ctx, &major, &minor))
     {
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_DRIVER_ERROR,
                    COGL_DRIVER_ERROR_UNKNOWN_VERSION,
                    "The OpenGL version could not be determined");
@@ -300,7 +301,7 @@ check_gl_version (CoglContext *ctx,
      extension */
   if (!_cogl_check_extension ("GL_ARB_multitexture", gl_extensions))
     {
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_DRIVER_ERROR,
                    COGL_DRIVER_ERROR_INVALID_VERSION,
                    "The OpenGL driver is missing "
@@ -311,7 +312,7 @@ check_gl_version (CoglContext *ctx,
   /* OpenGL 1.2 is required */
   if (!COGL_CHECK_GL_VERSION (major, minor, 1, 2))
     {
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_DRIVER_ERROR,
                    COGL_DRIVER_ERROR_INVALID_VERSION,
                    "The OpenGL version of your driver (%i.%i) "
@@ -325,7 +326,7 @@ check_gl_version (CoglContext *ctx,
 
 static CoglBool
 _cogl_driver_update_features (CoglContext *ctx,
-                              GError **error)
+                              CoglError **error)
 {
   CoglPrivateFeatureFlags private_flags = 0;
   CoglFeatureFlags flags = 0;
diff --git a/cogl/driver/gl/gles/cogl-driver-gles.c b/cogl/driver/gl/gles/cogl-driver-gles.c
index 85811e9..d3e557c 100644
--- a/cogl/driver/gl/gles/cogl-driver-gles.c
+++ b/cogl/driver/gl/gles/cogl-driver-gles.c
@@ -184,7 +184,7 @@ _cogl_driver_pixel_format_to_gl (CoglContext *context,
 
 static CoglBool
 _cogl_driver_update_features (CoglContext *context,
-                              GError **error)
+                              CoglError **error)
 {
   CoglPrivateFeatureFlags private_flags = 0;
   CoglFeatureFlags flags = 0;
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/winsys/cogl-texture-pixmap-x11.c
index aebf8e6..a3f99e6 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11.c
+++ b/cogl/winsys/cogl-texture-pixmap-x11.c
@@ -47,6 +47,7 @@
 #include "cogl-winsys-private.h"
 #include "cogl-pipeline-opengl-private.h"
 #include "cogl-xlib.h"
+#include "cogl-error-private.h"
 
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -64,7 +65,7 @@ COGL_TEXTURE_DEFINE (TexturePixmapX11, texture_pixmap_x11);
 
 static const CoglTextureVtable cogl_texture_pixmap_x11_vtable;
 
-GQuark
+uint32_t
 cogl_texture_pixmap_x11_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-texture-pixmap-error-quark");
@@ -273,7 +274,7 @@ CoglTexturePixmapX11 *
 cogl_texture_pixmap_x11_new (CoglContext *ctxt,
                              uint32_t pixmap,
                              CoglBool automatic_updates,
-                             GError **error)
+                             CoglError **error)
 {
   CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1);
   Display *display = cogl_xlib_get_display ();
@@ -300,7 +301,7 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
                      &pixmap_border_width, &tex_pixmap->depth))
     {
       g_free (tex_pixmap);
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_TEXTURE_PIXMAP_X11_ERROR,
                    COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
                    "Unable to query pixmap size");
@@ -312,7 +313,7 @@ cogl_texture_pixmap_x11_new (CoglContext *ctxt,
   if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
     {
       g_free (tex_pixmap);
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_TEXTURE_PIXMAP_X11_ERROR,
                    COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
                    "Unable to query root window attributes");
diff --git a/cogl/winsys/cogl-texture-pixmap-x11.h b/cogl/winsys/cogl-texture-pixmap-x11.h
index c517762..9770bfa 100644
--- a/cogl/winsys/cogl-texture-pixmap-x11.h
+++ b/cogl/winsys/cogl-texture-pixmap-x11.h
@@ -59,7 +59,7 @@ typedef enum
 /**
  * COGL_TEXTURE_PIXMAP_X11_ERROR:
  *
- * #GError domain for texture-pixmap-x11 errors.
+ * #CoglError domain for texture-pixmap-x11 errors.
  *
  * Since: 1.10
  */
@@ -78,7 +78,7 @@ typedef enum {
   COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
 } CoglTexturePixmapX11Error;
 
-GQuark cogl_texture_pixmap_x11_error_quark (void);
+uint32_t cogl_texture_pixmap_x11_error_quark (void);
 
 /**
  * cogl_texture_pixmap_x11_new:
@@ -86,7 +86,7 @@ GQuark cogl_texture_pixmap_x11_error_quark (void);
  * @pixmap: A X11 pixmap ID
  * @automatic_updates: Whether to automatically copy the contents of
  * the pixmap to the texture.
- * @error: A #GError for exceptions
+ * @error: A #CoglError for exceptions
  *
  * Creates a texture that contains the contents of @pixmap. If
  * @automatic_updates is %TRUE then Cogl will attempt to listen for
@@ -102,7 +102,7 @@ CoglTexturePixmapX11 *
 cogl_texture_pixmap_x11_new (CoglContext *context,
                              uint32_t pixmap,
                              CoglBool automatic_updates,
-                             GError **error);
+                             CoglError **error);
 
 /**
  * cogl_texture_pixmap_x11_update_area:
diff --git a/cogl/winsys/cogl-winsys-egl-android.c b/cogl/winsys/cogl-winsys-egl-android.c
index 269d65d..d014370 100644
--- a/cogl/winsys/cogl-winsys-egl-android.c
+++ b/cogl/winsys/cogl-winsys-egl-android.c
@@ -69,7 +69,7 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   CoglRendererEGL *egl_renderer;
 
@@ -92,7 +92,7 @@ error:
 
 static CoglBool
 _cogl_winsys_egl_context_created (CoglDisplay *display,
-                                  GError **error)
+                                  CoglError **error)
 {
   CoglRenderer *renderer = display->renderer;
   CoglRendererEGL *egl_renderer = renderer->winsys;
@@ -154,7 +154,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
   return TRUE;
 
  fail:
-  g_set_error (error, COGL_WINSYS_ERROR,
+  _cogl_set_error (error, COGL_WINSYS_ERROR,
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
   return FALSE;
@@ -162,7 +162,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
 
 static CoglBool
 _cogl_winsys_egl_display_setup (CoglDisplay *display,
-                                GError **error)
+                                CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
   CoglDisplayAndroid *android_display;
@@ -184,7 +184,7 @@ _cogl_winsys_egl_display_destroy (CoglDisplay *display)
 static CoglBool
 _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
                                 EGLConfig egl_config,
-                                GError **error)
+                                CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -195,7 +195,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
 
   if (android_display->have_onscreen)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "EGL platform only supports a single onscreen window");
       return FALSE;
diff --git a/cogl/winsys/cogl-winsys-egl-gdl.c b/cogl/winsys/cogl-winsys-egl-gdl.c
index 8d57904..f8b4a13 100644
--- a/cogl/winsys/cogl-winsys-egl-gdl.c
+++ b/cogl/winsys/cogl-winsys-egl-gdl.c
@@ -67,7 +67,7 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   CoglRendererEGL *egl_renderer;
   CoglRendererGDL *gdl_renderer;
@@ -91,7 +91,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   rc = gdl_init (NULL);
   if (rc != GDL_SUCCESS)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "GDL initialize failed. %s",
                    gdl_get_error_string (rc));
@@ -101,7 +101,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   rc = gdl_get_display_info (GDL_DISPLAY_ID_0, &gdl_display_info);
   if (rc != GDL_SUCCESS)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "GDL failed to get display information: %s",
                    gdl_get_error_string (rc));
@@ -120,7 +120,7 @@ error:
 
 static CoglBool
 _cogl_winsys_egl_context_created (CoglDisplay *display,
-                                  GError **error)
+                                  CoglError **error)
 {
   CoglRenderer *renderer = display->renderer;
   CoglRendererEGL *egl_renderer = renderer->winsys;
@@ -162,14 +162,14 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
   return TRUE;
 
  fail:
-  g_set_error (error, COGL_WINSYS_ERROR,
+  _cogl_set_error (error, COGL_WINSYS_ERROR,
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
   return FALSE;
 }
 
 static CoglBool
-gdl_plane_init (CoglDisplay *display, GError **error)
+gdl_plane_init (CoglDisplay *display, CoglError **error)
 {
   CoglBool ret = TRUE;
   gdl_color_space_t colorSpace = GDL_COLOR_SPACE_RGB;
@@ -180,7 +180,7 @@ gdl_plane_init (CoglDisplay *display, GError **error)
 
   if (!display->gdl_plane)
     {
-      g_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
+      _cogl_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "No GDL plane specified with "
                    "cogl_gdl_display_set_plane");
       return FALSE;
@@ -189,7 +189,7 @@ gdl_plane_init (CoglDisplay *display, GError **error)
   rc = gdl_init (NULL);
   if (rc != GDL_SUCCESS)
     {
-      g_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
+      _cogl_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "GDL initialize failed. %s", gdl_get_error_string (rc));
       return FALSE;
     }
@@ -197,7 +197,7 @@ gdl_plane_init (CoglDisplay *display, GError **error)
   rc = gdl_get_display_info (GDL_DISPLAY_ID_0, &display_info);
   if (rc != GDL_SUCCESS)
     {
-      g_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
+      _cogl_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "GDL failed to get display infomation: %s",
                    gdl_get_error_string (rc));
       gdl_close ();
@@ -243,7 +243,7 @@ gdl_plane_init (CoglDisplay *display, GError **error)
 
   if (rc != GDL_SUCCESS)
     {
-      g_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
+      _cogl_set_error (error, COGL_WINSYS_ERROR, COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "GDL configuration failed: %s.", gdl_get_error_string (rc));
       ret = FALSE;
     }
@@ -255,7 +255,7 @@ gdl_plane_init (CoglDisplay *display, GError **error)
 
 static CoglBool
 _cogl_winsys_egl_display_setup (CoglDisplay *display,
-                                GError **error)
+                                CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
   CoglDisplayGDL *gdl_display;
@@ -294,7 +294,7 @@ _cogl_winsys_egl_cleanup_context (CoglDisplay *display)
 static CoglBool
 _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
                                 EGLConfig egl_config,
-                                GError **error)
+                                CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -305,7 +305,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
 
   if (gdl_display->have_onscreen)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "EGL platform only supports a single onscreen window");
       return FALSE;
diff --git a/cogl/winsys/cogl-winsys-egl-kms.c b/cogl/winsys/cogl-winsys-egl-kms.c
index e1d098e..ff538e2 100644
--- a/cogl/winsys/cogl-winsys-egl-kms.c
+++ b/cogl/winsys/cogl-winsys-egl-kms.c
@@ -52,6 +52,7 @@
 #include "cogl-kms-renderer.h"
 #include "cogl-kms-display.h"
 #include "cogl-version.h"
+#include "cogl-error-private.h"
 
 static const CoglWinsysEGLVtable _cogl_winsys_egl_vtable;
 
@@ -115,7 +116,7 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   CoglRendererEGL *egl_renderer;
   CoglRendererKMS *kms_renderer;
@@ -131,7 +132,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   if (kms_renderer->fd < 0)
     {
       /* Probably permissions error */
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "Couldn't open %s", device_name);
       return FALSE;
@@ -140,7 +141,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   kms_renderer->gbm = gbm_create_device (kms_renderer->fd);
   if (kms_renderer->gbm == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "Couldn't create gbm device");
       goto close_fd;
@@ -149,7 +150,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
   egl_renderer->edpy = eglGetDisplay ((EGLNativeDisplayType)kms_renderer->gbm);
   if (egl_renderer->edpy == EGL_NO_DISPLAY)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "Couldn't get eglDisplay");
       goto destroy_gbm_device;
@@ -264,7 +265,7 @@ find_output (int _index,
              drmModeRes *resources,
              int *excluded_connectors,
              int n_excluded_connectors,
-             GError **error)
+             CoglError **error)
 {
   char *connector_env_name = g_strdup_printf ("COGL_KMS_CONNECTOR%d", _index);
   char *mode_env_name;
@@ -288,7 +289,7 @@ find_output (int _index,
                                 excluded_connectors, n_excluded_connectors);
   if (connector == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "No currently active connector found");
       return NULL;
@@ -340,7 +341,7 @@ find_output (int _index,
       if (!found)
         {
           g_free (mode_env_name);
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_INIT,
                        "COGL_KMS_CONNECTOR%d_MODE of %s could not be found",
                        _index, name);
@@ -384,7 +385,7 @@ setup_crtc_modes (CoglDisplay *display, int fb_id)
 
 static CoglBool
 _cogl_winsys_egl_display_setup (CoglDisplay *display,
-                                GError **error)
+                                CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
   CoglDisplayKMS *kms_display;
@@ -400,7 +401,7 @@ _cogl_winsys_egl_display_setup (CoglDisplay *display,
   resources = drmModeGetResources (kms_renderer->fd);
   if (!resources)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "drmModeGetResources failed");
       return FALSE;
@@ -440,7 +441,7 @@ _cogl_winsys_egl_display_setup (CoglDisplay *display,
                               &output0->mode,
                               &output1->mode))
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_INIT,
                        "Failed to find matching modes for mirroring");
           return FALSE;
@@ -508,7 +509,7 @@ _cogl_winsys_egl_display_destroy (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_egl_context_created (CoglDisplay *display,
-                                  GError **error)
+                                  CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
   CoglDisplayKMS *kms_display = egl_display->platform;
@@ -522,7 +523,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
                                                        GBM_BO_USE_RENDERING);
   if (!kms_display->dummy_gbm_surface)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Failed to create dummy GBM surface");
       return FALSE;
@@ -535,7 +536,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
                             NULL);
   if (egl_display->dummy_surface == EGL_NO_SURFACE)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Failed to create dummy EGL surface");
       return FALSE;
@@ -546,7 +547,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
                                       egl_display->dummy_surface,
                                       egl_display->egl_context))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Failed to make context current");
       return FALSE;
@@ -749,7 +750,7 @@ _cogl_winsys_onscreen_swap_buffers (CoglOnscreen *onscreen)
 
 static CoglBool
 _cogl_winsys_egl_context_init (CoglContext *context,
-                               GError **error)
+                               CoglError **error)
 {
   COGL_FLAGS_SET (context->features,
                   COGL_FEATURE_ID_SWAP_BUFFERS_EVENT, TRUE);
@@ -762,7 +763,7 @@ _cogl_winsys_egl_context_init (CoglContext *context,
 
 static CoglBool
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            GError **error)
+                            CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -793,7 +794,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
 
   if (!kms_onscreen->surface)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "Failed to allocate surface");
       return FALSE;
@@ -806,7 +807,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
                             NULL);
   if (egl_onscreen->egl_surface == EGL_NO_SURFACE)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "Failed to allocate surface");
       return FALSE;
diff --git a/cogl/winsys/cogl-winsys-egl-null.c b/cogl/winsys/cogl-winsys-egl-null.c
index 65da170..ee817e0 100644
--- a/cogl/winsys/cogl-winsys-egl-null.c
+++ b/cogl/winsys/cogl-winsys-egl-null.c
@@ -56,7 +56,7 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   CoglRendererEGL *egl_renderer;
 
@@ -79,7 +79,7 @@ error:
 
 static CoglBool
 _cogl_winsys_egl_context_created (CoglDisplay *display,
-                                  GError **error)
+                                  CoglError **error)
 {
   CoglRenderer *renderer = display->renderer;
   CoglRendererEGL *egl_renderer = renderer->winsys;
@@ -120,7 +120,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
   return TRUE;
 
  fail:
-  g_set_error (error, COGL_WINSYS_ERROR,
+  _cogl_set_error (error, COGL_WINSYS_ERROR,
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
   return FALSE;
@@ -128,7 +128,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
 
 static CoglBool
 _cogl_winsys_egl_display_setup (CoglDisplay *display,
-                                GError **error)
+                                CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
   CoglDisplayNull *null_display;
@@ -164,7 +164,7 @@ _cogl_winsys_egl_cleanup_context (CoglDisplay *display)
 static CoglBool
 _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
                                 EGLConfig egl_config,
-                                GError **error)
+                                CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -175,7 +175,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
 
   if (null_display->have_onscreen)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "EGL platform only supports a single onscreen window");
       return FALSE;
diff --git a/cogl/winsys/cogl-winsys-egl-private.h b/cogl/winsys/cogl-winsys-egl-private.h
index eeb7028..3f092ae 100644
--- a/cogl/winsys/cogl-winsys-egl-private.h
+++ b/cogl/winsys/cogl-winsys-egl-private.h
@@ -34,19 +34,19 @@ typedef struct _CoglWinsysEGLVtable
 {
   CoglBool
   (* display_setup) (CoglDisplay *display,
-                     GError **error);
+                     CoglError **error);
   void
   (* display_destroy) (CoglDisplay *display);
 
   CoglBool
   (* context_created) (CoglDisplay *display,
-                       GError **error);
+                       CoglError **error);
 
   void
   (* cleanup_context) (CoglDisplay *display);
 
   CoglBool
-  (* context_init) (CoglContext *context, GError **error);
+  (* context_init) (CoglContext *context, CoglError **error);
 
   void
   (* context_deinit) (CoglContext *context);
@@ -54,7 +54,7 @@ typedef struct _CoglWinsysEGLVtable
   CoglBool
   (* onscreen_init) (CoglOnscreen *onscreen,
                      EGLConfig config,
-                     GError **error);
+                     CoglError **error);
   void
   (* onscreen_deinit) (CoglOnscreen *onscreen);
 
@@ -159,6 +159,6 @@ _cogl_egl_destroy_image (CoglContext *ctx,
 
 CoglBool
 _cogl_winsys_egl_renderer_connect_common (CoglRenderer *renderer,
-                                          GError **error);
+                                          CoglError **error);
 
 #endif /* __COGL_WINSYS_EGL_PRIVATE_H */
diff --git a/cogl/winsys/cogl-winsys-egl-wayland.c b/cogl/winsys/cogl-winsys-egl-wayland.c
index 6bc85b9..feeb529 100644
--- a/cogl/winsys/cogl-winsys-egl-wayland.c
+++ b/cogl/winsys/cogl-winsys-egl-wayland.c
@@ -38,6 +38,7 @@
 #include "cogl-renderer-private.h"
 #include "cogl-onscreen-private.h"
 #include "cogl-wayland-renderer.h"
+#include "cogl-error-private.h"
 
 static const CoglWinsysEGLVtable _cogl_winsys_egl_vtable;
 
@@ -108,7 +109,7 @@ static const struct wl_registry_listener registry_listener = {
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   CoglRendererEGL *egl_renderer;
   CoglRendererWayland *wayland_renderer;
@@ -144,7 +145,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
       wayland_renderer->wayland_display = wl_display_connect (NULL);
       if (!wayland_renderer->wayland_display)
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_INIT,
                        "Failed to connect wayland display");
           goto error;
@@ -183,7 +184,7 @@ error:
 
 static CoglBool
 _cogl_winsys_egl_display_setup (CoglDisplay *display,
-                                GError **error)
+                                CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
   CoglDisplayWayland *wayland_display;
@@ -204,7 +205,7 @@ _cogl_winsys_egl_display_destroy (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_egl_context_created (CoglDisplay *display,
-                                  GError **error)
+                                  CoglError **error)
 {
   CoglRenderer *renderer = display->renderer;
   CoglRendererEGL *egl_renderer = renderer->winsys;
@@ -255,7 +256,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
   return TRUE;
 
  fail:
-  g_set_error (error, COGL_WINSYS_ERROR,
+  _cogl_set_error (error, COGL_WINSYS_ERROR,
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
   return FALSE;
@@ -290,7 +291,7 @@ _cogl_winsys_egl_cleanup_context (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_egl_context_init (CoglContext *context,
-                               GError **error)
+                               CoglError **error)
 {
   context->feature_flags |= COGL_FEATURE_ONSCREEN_MULTIPLE;
   COGL_FLAGS_SET (context->features,
@@ -305,7 +306,7 @@ _cogl_winsys_egl_context_init (CoglContext *context,
 static CoglBool
 _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
                                 EGLConfig egl_config,
-                                GError **error)
+                                CoglError **error)
 {
   CoglOnscreenEGL *egl_onscreen = onscreen->winsys;
   CoglOnscreenWayland *wayland_onscreen;
@@ -322,7 +323,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
     wl_compositor_create_surface (wayland_renderer->wayland_compositor);
   if (!wayland_onscreen->wayland_surface)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "Error while creating wayland surface for CoglOnscreen");
       return FALSE;
@@ -338,7 +339,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
                           cogl_framebuffer_get_height (framebuffer));
   if (!wayland_onscreen->wayland_egl_native_window)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "Error while creating wayland egl native window "
                    "for CoglOnscreen");
diff --git a/cogl/winsys/cogl-winsys-egl-x11.c b/cogl/winsys/cogl-winsys-egl-x11.c
index 1b02ac0..fca7609 100644
--- a/cogl/winsys/cogl-winsys-egl-x11.c
+++ b/cogl/winsys/cogl-winsys-egl-x11.c
@@ -42,6 +42,7 @@
 
 #include "cogl-texture-pixmap-x11-private.h"
 #include "cogl-texture-2d-private.h"
+#include "cogl-error-private.h"
 
 #define COGL_ONSCREEN_X11_EVENT_MASK StructureNotifyMask
 
@@ -194,7 +195,7 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   CoglRendererEGL *egl_renderer;
   CoglXlibRenderer *xlib_renderer;
@@ -223,7 +224,7 @@ error:
 
 static CoglBool
 _cogl_winsys_egl_display_setup (CoglDisplay *display,
-                                GError **error)
+                                CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
   CoglDisplayXlib *xlib_display;
@@ -244,7 +245,7 @@ _cogl_winsys_egl_display_destroy (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_egl_context_init (CoglContext *context,
-                               GError **error)
+                               CoglError **error)
 {
   cogl_xlib_renderer_add_filter (context->display->renderer,
                                  event_filter_cb,
@@ -271,7 +272,7 @@ _cogl_winsys_egl_context_deinit (CoglContext *context)
 static CoglBool
 _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
                                 EGLConfig egl_config,
-                                GError **error)
+                                CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -312,7 +313,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
           char message[1000];
           XGetErrorText (xlib_renderer->xdpy, xerror,
                          message, sizeof (message));
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "Unable to query geometry of foreign "
                        "xid 0x%08lX: %s",
@@ -347,7 +348,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
       xvisinfo = get_visual_info (display, egl_config);
       if (xvisinfo == NULL)
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "Unable to retrieve the X11 visual of context's "
                        "fbconfig");
@@ -389,7 +390,7 @@ _cogl_winsys_egl_onscreen_init (CoglOnscreen *onscreen,
           char message[1000];
           XGetErrorText (xlib_renderer->xdpy, xerror,
                          message, sizeof (message));
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "X error while creating Window for CoglOnscreen: %s",
                        message);
@@ -510,7 +511,7 @@ _cogl_winsys_onscreen_x11_get_window_xid (CoglOnscreen *onscreen)
 
 static CoglBool
 _cogl_winsys_egl_context_created (CoglDisplay *display,
-                                  GError **error)
+                                  CoglError **error)
 {
   CoglRenderer *renderer = display->renderer;
   CoglDisplayEGL *egl_display = display->winsys;
@@ -575,7 +576,7 @@ _cogl_winsys_egl_context_created (CoglDisplay *display,
   return TRUE;
 
 fail:
-  g_set_error (error, COGL_WINSYS_ERROR,
+  _cogl_set_error (error, COGL_WINSYS_ERROR,
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
   return FALSE;
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index 5257a63..26acab7 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -39,6 +39,7 @@
 #include "cogl-renderer-private.h"
 #include "cogl-onscreen-template-private.h"
 #include "cogl-gles2-context-private.h"
+#include "cogl-error-private.h"
 
 #include "cogl-private.h"
 
@@ -168,7 +169,7 @@ check_egl_extensions (CoglRenderer *renderer)
 
 CoglBool
 _cogl_winsys_egl_renderer_connect_common (CoglRenderer *renderer,
-                                          GError **error)
+                                          CoglError **error)
 {
   CoglRendererEGL *egl_renderer = renderer->winsys;
 
@@ -176,7 +177,7 @@ _cogl_winsys_egl_renderer_connect_common (CoglRenderer *renderer,
                       &egl_renderer->egl_version_major,
                       &egl_renderer->egl_version_minor))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "Couldn't initialize EGL");
       return FALSE;
@@ -189,7 +190,7 @@ _cogl_winsys_egl_renderer_connect_common (CoglRenderer *renderer,
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   /* This function must be overridden by a platform winsys */
   g_assert_not_reached ();
@@ -256,7 +257,7 @@ egl_attributes_from_framebuffer_config (CoglDisplay *display,
 static CoglBool
 try_create_context (CoglDisplay *display,
                     CoglBool with_stencil_buffer,
-                    GError **error)
+                    CoglError **error)
 {
   CoglRenderer *renderer = display->renderer;
   CoglDisplayEGL *egl_display = display->winsys;
@@ -319,7 +320,7 @@ try_create_context (CoglDisplay *display,
   return TRUE;
 
 fail:
-  g_set_error (error, COGL_WINSYS_ERROR,
+  _cogl_set_error (error, COGL_WINSYS_ERROR,
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
   return FALSE;
@@ -373,7 +374,7 @@ cleanup_context (CoglDisplay *display)
 }
 
 static CoglBool
-create_context (CoglDisplay *display, GError **error)
+create_context (CoglDisplay *display, CoglError **error)
 {
   CoglDisplayEGL *egl_display = display->winsys;
 
@@ -390,7 +391,7 @@ create_context (CoglDisplay *display, GError **error)
     }
   else
     {
-      g_clear_error (error);
+      _cogl_clear_error (error);
       cleanup_context (display);
       egl_display->stencil_disabled = TRUE;
       return try_create_context (display, FALSE, error);
@@ -416,7 +417,7 @@ _cogl_winsys_display_destroy (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_display_setup (CoglDisplay *display,
-                            GError **error)
+                            CoglError **error)
 {
   CoglDisplayEGL *egl_display;
   CoglRenderer *renderer = display->renderer;
@@ -455,7 +456,7 @@ error:
 }
 
 static CoglBool
-_cogl_winsys_context_init (CoglContext *context, GError **error)
+_cogl_winsys_context_init (CoglContext *context, CoglError **error)
 {
   CoglRenderer *renderer = context->display->renderer;
   CoglDisplayEGL *egl_display = context->display->winsys;
@@ -514,7 +515,7 @@ typedef struct _CoglGLES2ContextEGL
 } CoglGLES2ContextEGL;
 
 static void *
-_cogl_winsys_context_create_gles2_context (CoglContext *ctx, GError **error)
+_cogl_winsys_context_create_gles2_context (CoglContext *ctx, CoglError **error)
 {
   CoglRendererEGL *egl_renderer = ctx->display->renderer->winsys;
   CoglDisplayEGL *egl_display = ctx->display->winsys;
@@ -531,7 +532,7 @@ _cogl_winsys_context_create_gles2_context (CoglContext *ctx, GError **error)
                                   attribs);
   if (egl_context == EGL_NO_CONTEXT)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_GLES2_CONTEXT,
                    "%s", get_error_string ());
       return NULL;
@@ -557,7 +558,7 @@ _cogl_winsys_destroy_gles2_context (CoglGLES2Context *gles2_ctx)
 
 static CoglBool
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            GError **error)
+                            CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -585,7 +586,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
                             &config_count);
   if (status != EGL_TRUE || config_count == 0)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "Failed to find a suitable EGL configuration");
       return FALSE;
@@ -779,7 +780,7 @@ _cogl_winsys_save_context (CoglContext *ctx)
 }
 
 static CoglBool
-_cogl_winsys_set_gles2_context (CoglGLES2Context *gles2_ctx, GError **error)
+_cogl_winsys_set_gles2_context (CoglGLES2Context *gles2_ctx, CoglError **error)
 {
   CoglContext *ctx = gles2_ctx->context;
   CoglDisplayEGL *egl_display = ctx->display->winsys;
@@ -798,7 +799,7 @@ _cogl_winsys_set_gles2_context (CoglGLES2Context *gles2_ctx, GError **error)
 
   if (!status)
     {
-      g_set_error (error,
+      _cogl_set_error (error,
                    COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_MAKE_CURRENT,
                    "Failed to make gles2 context current");
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index b24ebf1..6716c7c 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -48,6 +48,7 @@
 #include "cogl-xlib-renderer.h"
 #include "cogl-util.h"
 #include "cogl-winsys-glx-private.h"
+#include "cogl-error-private.h"
 
 #include <stdlib.h>
 #include <sys/types.h>
@@ -261,7 +262,7 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 resolve_core_glx_functions (CoglRenderer *renderer,
-                            GError **error)
+                            CoglError **error)
 {
   CoglGLXRenderer *glx_renderer;
 
@@ -306,7 +307,7 @@ resolve_core_glx_functions (CoglRenderer *renderer,
        !g_module_symbol (glx_renderer->libgl_module, "glXGetProcAddressARB",
                          (void **) &glx_renderer->glXGetProcAddress)))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "Failed to resolve required GLX symbol");
       return FALSE;
@@ -317,7 +318,7 @@ resolve_core_glx_functions (CoglRenderer *renderer,
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   CoglGLXRenderer *glx_renderer;
   CoglXlibRenderer *xlib_renderer;
@@ -332,7 +333,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
 
   if (renderer->driver != COGL_DRIVER_GL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "GLX Backend can only be used in conjunction with OpenGL");
       goto error;
@@ -343,7 +344,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
 
   if (glx_renderer->libgl_module == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "Failed to dynamically open the OpenGL library");
       goto error;
@@ -356,7 +357,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                                         &glx_renderer->glx_error_base,
                                         &glx_renderer->glx_event_base))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "XServer appears to lack required GLX support");
       goto error;
@@ -370,7 +371,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                                       &glx_renderer->glx_minor)
       || !(glx_renderer->glx_major == 1 && glx_renderer->glx_minor >= 2))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "XServer appears to lack required GLX 1.2 support");
       goto error;
@@ -386,7 +387,7 @@ error:
 }
 
 static CoglBool
-update_winsys_features (CoglContext *context, GError **error)
+update_winsys_features (CoglContext *context, CoglError **error)
 {
   CoglGLXDisplay *glx_display = context->display->winsys;
   CoglXlibRenderer *xlib_renderer =
@@ -540,7 +541,7 @@ static CoglBool
 find_fbconfig (CoglDisplay *display,
                CoglFramebufferConfig *config,
                GLXFBConfig *config_ret,
-               GError **error)
+               CoglError **error)
 {
   CoglXlibRenderer *xlib_renderer =
     _cogl_xlib_renderer_get_data (display->renderer);
@@ -559,7 +560,7 @@ find_fbconfig (CoglDisplay *display,
                                              &n_configs);
   if (!configs || n_configs == 0)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Failed to find any compatible fbconfigs");
       ret = FALSE;
@@ -589,7 +590,7 @@ find_fbconfig (CoglDisplay *display,
             }
         }
 
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Unable to find fbconfig with rgba visual");
       ret = FALSE;
@@ -607,7 +608,7 @@ done:
 }
 
 static CoglBool
-create_context (CoglDisplay *display, GError **error)
+create_context (CoglDisplay *display, CoglError **error)
 {
   CoglGLXDisplay *glx_display = display->winsys;
   CoglXlibRenderer *xlib_renderer =
@@ -616,7 +617,7 @@ create_context (CoglDisplay *display, GError **error)
   CoglBool support_transparent_windows =
     display->onscreen_template->config.swap_chain->has_alpha;
   GLXFBConfig config;
-  GError *fbconfig_error = NULL;
+  CoglError *fbconfig_error = NULL;
   XSetWindowAttributes attrs;
   XVisualInfo *xvisinfo;
   GLXDrawable dummy_drawable;
@@ -629,11 +630,11 @@ create_context (CoglDisplay *display, GError **error)
                    &fbconfig_error);
   if (!glx_display->found_fbconfig)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Unable to find suitable fbconfig for the GLX context: %s",
                    fbconfig_error->message);
-      g_error_free (fbconfig_error);
+      cogl_error_free (fbconfig_error);
       return FALSE;
     }
 
@@ -651,7 +652,7 @@ create_context (CoglDisplay *display, GError **error)
                                        True);
   if (glx_display->glx_context == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Unable to create suitable GL context");
       return FALSE;
@@ -672,7 +673,7 @@ create_context (CoglDisplay *display, GError **error)
                                                      config);
   if (xvisinfo == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Unable to retrieve the X11 visual");
       return FALSE;
@@ -727,7 +728,7 @@ create_context (CoglDisplay *display, GError **error)
 
   if (_cogl_xlib_renderer_untrap_errors (display->renderer, &old_state))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Unable to select the newly created GLX context");
       return FALSE;
@@ -774,7 +775,7 @@ _cogl_winsys_display_destroy (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_display_setup (CoglDisplay *display,
-                            GError **error)
+                            CoglError **error)
 {
   CoglGLXDisplay *glx_display;
   int i;
@@ -798,7 +799,7 @@ error:
 }
 
 static CoglBool
-_cogl_winsys_context_init (CoglContext *context, GError **error)
+_cogl_winsys_context_init (CoglContext *context, CoglError **error)
 {
   context->winsys = g_new0 (CoglContextGLX, 1);
 
@@ -819,7 +820,7 @@ _cogl_winsys_context_deinit (CoglContext *context)
 
 static CoglBool
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            GError **error)
+                            CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -832,7 +833,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
   CoglOnscreenXlib *xlib_onscreen;
   CoglOnscreenGLX *glx_onscreen;
   GLXFBConfig fbconfig;
-  GError *fbconfig_error = NULL;
+  CoglError *fbconfig_error = NULL;
 
   _COGL_RETURN_VAL_IF_FAIL (glx_display->glx_context, FALSE);
 
@@ -840,11 +841,11 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
                       &fbconfig,
                       &fbconfig_error))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Unable to find suitable fbconfig for the GLX context: %s",
                    fbconfig_error->message);
-      g_error_free (fbconfig_error);
+      cogl_error_free (fbconfig_error);
       return FALSE;
     }
 
@@ -888,7 +889,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
         {
           char message[1000];
           XGetErrorText (xlib_renderer->xdpy, xerror, message, sizeof(message));
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "Unable to query geometry of foreign xid 0x%08lX: %s",
                        xwin, message);
@@ -922,7 +923,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
                                                          fbconfig);
       if (xvisinfo == NULL)
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "Unable to retrieve the X11 visual of context's "
                        "fbconfig");
@@ -961,7 +962,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
           char message[1000];
           XGetErrorText (xlib_renderer->xdpy, xerror,
                          message, sizeof (message));
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "X error while creating Window for CoglOnscreen: %s",
                        message);
@@ -1113,7 +1114,7 @@ _cogl_winsys_onscreen_bind (CoglOnscreen *onscreen)
 
   XSync (xlib_renderer->xdpy, False);
 
-  /* FIXME: We should be reporting a GError here
+  /* FIXME: We should be reporting a CoglError here
    */
   if (_cogl_xlib_renderer_untrap_errors (context->display->renderer,
                                          &old_state))
@@ -1917,7 +1918,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
   if (glx_tex_pixmap->glx_tex == NULL)
     {
       CoglPixelFormat texture_format;
-      GError *error = NULL;
+      CoglError *error = NULL;
 
       texture_format = (tex_pixmap->depth >= 32 ?
                         COGL_PIXEL_FORMAT_RGBA_8888_PRE :
@@ -1940,7 +1941,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
               COGL_NOTE (TEXTURE_PIXMAP, "Falling back for %p because a "
                          "texture rectangle could not be created: %s",
                          tex_pixmap, error->message);
-              g_error_free (error);
+              cogl_error_free (error);
               free_glx_pixmap (ctx, glx_tex_pixmap);
               return FALSE;
             }
diff --git a/cogl/winsys/cogl-winsys-private.h b/cogl/winsys/cogl-winsys-private.h
index 3262d2f..80686ef 100644
--- a/cogl/winsys/cogl-winsys-private.h
+++ b/cogl/winsys/cogl-winsys-private.h
@@ -43,7 +43,7 @@
 
 #include "cogl-poll.h"
 
-GQuark
+uint32_t
 _cogl_winsys_error_quark (void);
 
 #define COGL_WINSYS_ERROR (_cogl_winsys_error_quark ())
@@ -78,28 +78,28 @@ typedef struct _CoglWinsysVtable
                                 CoglBool in_core);
 
   CoglBool
-  (*renderer_connect) (CoglRenderer *renderer, GError **error);
+  (*renderer_connect) (CoglRenderer *renderer, CoglError **error);
 
   void
   (*renderer_disconnect) (CoglRenderer *renderer);
 
   CoglBool
-  (*display_setup) (CoglDisplay *display, GError **error);
+  (*display_setup) (CoglDisplay *display, CoglError **error);
 
   void
   (*display_destroy) (CoglDisplay *display);
 
   CoglBool
-  (*context_init) (CoglContext *context, GError **error);
+  (*context_init) (CoglContext *context, CoglError **error);
 
   void
   (*context_deinit) (CoglContext *context);
 
   void *
-  (*context_create_gles2_context) (CoglContext *ctx, GError **error);
+  (*context_create_gles2_context) (CoglContext *ctx, CoglError **error);
 
   CoglBool
-  (*onscreen_init) (CoglOnscreen *onscreen, GError **error);
+  (*onscreen_init) (CoglOnscreen *onscreen, CoglError **error);
 
   void
   (*onscreen_deinit) (CoglOnscreen *onscreen);
@@ -176,7 +176,7 @@ typedef struct _CoglWinsysVtable
   (*save_context) (CoglContext *ctx);
 
   CoglBool
-  (*set_gles2_context) (CoglGLES2Context *gles2_ctx, GError **error);
+  (*set_gles2_context) (CoglGLES2Context *gles2_ctx, CoglError **error);
 
   void
   (*restore_context) (CoglContext *ctx);
diff --git a/cogl/winsys/cogl-winsys-sdl.c b/cogl/winsys/cogl-winsys-sdl.c
index 95d5ab9..f3a71d3 100644
--- a/cogl/winsys/cogl-winsys-sdl.c
+++ b/cogl/winsys/cogl-winsys-sdl.c
@@ -37,6 +37,7 @@
 #include "cogl-context-private.h"
 #include "cogl-onscreen-private.h"
 #include "cogl-winsys-sdl-private.h"
+#include "cogl-error-private.h"
 
 typedef struct _CoglRendererSdl
 {
@@ -84,12 +85,12 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
 #ifndef COGL_HAS_SDL_GLES_SUPPORT
   if (renderer->driver != COGL_DRIVER_GL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "The SDL winsys only supports the GL driver");
       return FALSE;
@@ -98,7 +99,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
 
   if (SDL_Init (SDL_INIT_VIDEO) == -1)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "SDL_Init failed: %s",
                    SDL_GetError ());
@@ -144,7 +145,7 @@ set_gl_attribs_from_framebuffer_config (CoglFramebufferConfig *config)
 
 static CoglBool
 _cogl_winsys_display_setup (CoglDisplay *display,
-                            GError **error)
+                            CoglError **error)
 {
   CoglDisplaySdl *sdl_display;
 
@@ -189,7 +190,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
 
   if (sdl_display->surface == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "SDL_SetVideoMode failed: %s",
                    SDL_GetError ());
@@ -237,7 +238,7 @@ sdl_event_filter_cb (SDL_Event *event, void *data)
 }
 
 static CoglBool
-_cogl_winsys_context_init (CoglContext *context, GError **error)
+_cogl_winsys_context_init (CoglContext *context, CoglError **error)
 {
   CoglRenderer *renderer = context->display->renderer;
 
@@ -274,7 +275,7 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
 
 static CoglBool
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            GError **error)
+                            CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -284,7 +285,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
 
   if (sdl_display->onscreen)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "SDL winsys only supports a single onscreen window");
       return FALSE;
@@ -303,7 +304,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
 
       if (sdl_display->surface == NULL)
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "SDL_SetVideoMode failed: %s",
                        SDL_GetError ());
diff --git a/cogl/winsys/cogl-winsys-sdl2.c b/cogl/winsys/cogl-winsys-sdl2.c
index 8ea5919..fd9d7d5 100644
--- a/cogl/winsys/cogl-winsys-sdl2.c
+++ b/cogl/winsys/cogl-winsys-sdl2.c
@@ -86,11 +86,11 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   if (SDL_VideoInit (NULL) < 0)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "SDL_Init failed: %s",
                    SDL_GetError ());
@@ -140,7 +140,7 @@ set_gl_attribs_from_framebuffer_config (CoglFramebufferConfig *config)
 
 static CoglBool
 _cogl_winsys_display_setup (CoglDisplay *display,
-                            GError **error)
+                            CoglError **error)
 {
   CoglDisplaySdl2 *sdl_display;
   const char * (* get_string_func) (GLenum name);
@@ -167,7 +167,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
                                                 SDL_WINDOW_HIDDEN);
   if (sdl_display->dummy_window == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "SDL_CreateWindow failed: %s",
                    SDL_GetError ());
@@ -178,7 +178,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
 
   if (sdl_display->context == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_INIT,
                    "SDL_GL_CreateContext failed: %s",
                    SDL_GetError ());
@@ -199,7 +199,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
        * it's normal GL */
       if (!g_ascii_isdigit (gl_version[0]))
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_INIT,
                        "The GL driver was requested but SDL is using GLES");
           goto error;
@@ -209,7 +209,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
     case COGL_DRIVER_GLES2:
       if (!g_str_has_prefix (gl_version, "OpenGL ES 2"))
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_INIT,
                        "The GLES2 driver was requested but SDL is "
                        "not using GLES2");
@@ -220,7 +220,7 @@ _cogl_winsys_display_setup (CoglDisplay *display,
     case COGL_DRIVER_GLES1:
       if (!g_str_has_prefix (gl_version, "OpenGL ES 1"))
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_INIT,
                        "The GLES1 driver was requested but SDL is "
                        "not using GLES1");
@@ -240,7 +240,7 @@ error:
 }
 
 static CoglBool
-_cogl_winsys_context_init (CoglContext *context, GError **error)
+_cogl_winsys_context_init (CoglContext *context, CoglError **error)
 {
   CoglRenderer *renderer = context->display->renderer;
 
@@ -321,7 +321,7 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
 
 static CoglBool
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            GError **error)
+                            CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglOnscreenSdl2 *sdl_onscreen;
@@ -339,7 +339,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
 
   if (window == NULL)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "SDL_CreateWindow failed: %s",
                    SDL_GetError ());
diff --git a/cogl/winsys/cogl-winsys-stub.c b/cogl/winsys/cogl-winsys-stub.c
index 2648622..aee70a9 100644
--- a/cogl/winsys/cogl-winsys-stub.c
+++ b/cogl/winsys/cogl-winsys-stub.c
@@ -76,7 +76,7 @@ _cogl_winsys_renderer_disconnect (CoglRenderer *renderer)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   renderer->winsys = &_cogl_winsys_stub_dummy_ptr;
   return TRUE;
@@ -90,14 +90,14 @@ _cogl_winsys_display_destroy (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_display_setup (CoglDisplay *display,
-                            GError **error)
+                            CoglError **error)
 {
   display->winsys = &_cogl_winsys_stub_dummy_ptr;
   return TRUE;
 }
 
 static CoglBool
-_cogl_winsys_context_init (CoglContext *context, GError **error)
+_cogl_winsys_context_init (CoglContext *context, CoglError **error)
 {
   context->winsys = &_cogl_winsys_stub_dummy_ptr;
 
@@ -117,7 +117,7 @@ _cogl_winsys_context_deinit (CoglContext *context)
 
 static CoglBool
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            GError **error)
+                            CoglError **error)
 {
   return TRUE;
 }
diff --git a/cogl/winsys/cogl-winsys-wgl.c b/cogl/winsys/cogl-winsys-wgl.c
index 418e728..7e2dc5d 100644
--- a/cogl/winsys/cogl-winsys-wgl.c
+++ b/cogl/winsys/cogl-winsys-wgl.c
@@ -232,7 +232,7 @@ win32_event_filter_cb (MSG *msg, void *data)
 
 static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
-                               GError **error)
+                               CoglError **error)
 {
   renderer->winsys = g_slice_new0 (CoglRendererWgl);
 
@@ -372,7 +372,7 @@ choose_pixel_format (CoglFramebufferConfig *config,
 }
 
 static CoglBool
-create_window_class (CoglDisplay *display, GError **error)
+create_window_class (CoglDisplay *display, CoglError **error)
 {
   CoglDisplayWgl *wgl_display = display->winsys;
   char *class_name_ascii, *src;
@@ -415,7 +415,7 @@ create_window_class (CoglDisplay *display, GError **error)
 
   if (wgl_display->window_class == 0)
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_CONTEXT,
                    "Unable to register window class");
       return FALSE;
@@ -425,7 +425,7 @@ create_window_class (CoglDisplay *display, GError **error)
 }
 
 static CoglBool
-create_context (CoglDisplay *display, GError **error)
+create_context (CoglDisplay *display, CoglError **error)
 {
   CoglDisplayWgl *wgl_display = display->winsys;
 
@@ -451,7 +451,7 @@ create_context (CoglDisplay *display, GError **error)
 
       if (wgl_display->dummy_hwnd == NULL)
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_CONTEXT,
                        "Unable to create dummy window");
           return FALSE;
@@ -470,7 +470,7 @@ create_context (CoglDisplay *display, GError **error)
 
       if (pf == 0 || !SetPixelFormat (wgl_display->dummy_dc, pf, &pfd))
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_CONTEXT,
                        "Unable to find suitable GL pixel format");
           ReleaseDC (wgl_display->dummy_hwnd, wgl_display->dummy_dc);
@@ -485,7 +485,7 @@ create_context (CoglDisplay *display, GError **error)
 
       if (wgl_display->wgl_context == NULL)
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_CONTEXT,
                        "Unable to create suitable GL context");
           return FALSE;
@@ -529,7 +529,7 @@ _cogl_winsys_display_destroy (CoglDisplay *display)
 
 static CoglBool
 _cogl_winsys_display_setup (CoglDisplay *display,
-                            GError **error)
+                            CoglError **error)
 {
   CoglDisplayWgl *wgl_display;
 
@@ -587,7 +587,7 @@ get_wgl_extensions_string (HDC dc)
 }
 
 static CoglBool
-update_winsys_features (CoglContext *context, GError **error)
+update_winsys_features (CoglContext *context, CoglError **error)
 {
   CoglDisplayWgl *wgl_display = context->display->winsys;
   CoglRendererWgl *wgl_renderer = context->display->renderer->winsys;
@@ -633,7 +633,7 @@ update_winsys_features (CoglContext *context, GError **error)
 }
 
 static CoglBool
-_cogl_winsys_context_init (CoglContext *context, GError **error)
+_cogl_winsys_context_init (CoglContext *context, CoglError **error)
 {
   CoglContextWgl *wgl_context;
 
@@ -733,7 +733,7 @@ _cogl_winsys_onscreen_deinit (CoglOnscreen *onscreen)
 
 static CoglBool
 _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
-                            GError **error)
+                            CoglError **error)
 {
   CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen);
   CoglContext *context = framebuffer->context;
@@ -789,7 +789,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
 
       if (hwnd == NULL)
         {
-          g_set_error (error, COGL_WINSYS_ERROR,
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
                        COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                        "Unable to create window");
           return FALSE;
@@ -814,7 +814,7 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
 
   if (pf == 0 || !SetPixelFormat (wgl_onscreen->client_dc, pf, &pfd))
     {
-      g_set_error (error, COGL_WINSYS_ERROR,
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
                    COGL_WINSYS_ERROR_CREATE_ONSCREEN,
                    "Error setting pixel format on the window");
 
diff --git a/cogl/winsys/cogl-winsys.c b/cogl/winsys/cogl-winsys.c
index c6bcdde..8b8c6d1 100644
--- a/cogl/winsys/cogl-winsys.c
+++ b/cogl/winsys/cogl-winsys.c
@@ -30,7 +30,7 @@
 
 #include <gmodule.h>
 
-GQuark
+uint32_t
 _cogl_winsys_error_quark (void)
 {
   return g_quark_from_static_string ("cogl-winsys-error-quark");
diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-docs.xml.in b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-docs.xml.in
index 55c88f7..ddfc926 100644
--- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-docs.xml.in
+++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-docs.xml.in
@@ -62,6 +62,7 @@
     </section>
 
     <xi:include href="xml/cogl-object.xml"/>
+    <xi:include href="xml/cogl-error.xml"/>
     <xi:include href="xml/cogl-context.xml"/>
     <xi:include href="xml/cogl-poll.xml"/>
 
diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
index ee10d44..5f6f959 100644
--- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
+++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
@@ -11,6 +11,16 @@ cogl_object_set_user_data
 </SECTION>
 
 <SECTION>
+<FILE>cogl-error</FILE>
+<TITLE>Exception handling</TITLE>
+CoglError
+cogl_error_matches
+cogl_error_free
+cogl_error_copy
+COGL_GLIB_ERROR
+</SECTION>
+
+<SECTION>
 <FILE>cogl-renderer</FILE>
 <TITLE>CoglRenderer: Connect to a backend renderer</TITLE>
 cogl_renderer_new
@@ -691,7 +701,7 @@ cogl_pipeline_add_layer_snippet
 
 <SUBSECTION Private>
 cogl_blend_string_error_get_type
-cogl_blend_string_error_quark
+cogl_blend_string_error_domain
 </SECTION>
 
 <SECTION>
diff --git a/examples/android/hello/jni/main.c b/examples/android/hello/jni/main.c
index dacbbab..2c5bd9b 100644
--- a/examples/android/hello/jni/main.c
+++ b/examples/android/hello/jni/main.c
@@ -40,7 +40,7 @@ typedef struct
 static int test_init (TestData* data)
 {
   CoglOnscreen *onscreen;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglVertexP2C4 triangle_vertices[] = {
         {0, 0.7, 0xff, 0x00, 0x00, 0x80},
         {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
diff --git a/examples/cogl-crate.c b/examples/cogl-crate.c
index 9c7c20f..c23daed 100644
--- a/examples/cogl-crate.c
+++ b/examples/cogl-crate.c
@@ -144,7 +144,7 @@ main (int argc, char **argv)
   CoglContext *ctx;
   CoglOnscreen *onscreen;
   CoglFramebuffer *fb;
-  GError *error = NULL;
+  CoglError *error = NULL;
   Data data;
   PangoRectangle hello_label_size;
   float fovy, aspect, z_near, z_2d, z_far;
diff --git a/examples/cogl-gles2-context.c b/examples/cogl-gles2-context.c
index 408852a..70aed2f 100644
--- a/examples/cogl-gles2-context.c
+++ b/examples/cogl-gles2-context.c
@@ -23,7 +23,7 @@ static gboolean
 paint_cb (void *user_data)
 {
     Data *data = user_data;
-    GError *error = NULL;
+    CoglError *error = NULL;
     const CoglGLES2Vtable *gles2 = data->gles2_vtable;
 
     /* Draw scene with GLES2 */
@@ -71,7 +71,7 @@ main (int argc, char **argv)
 {
     Data data;
     CoglOnscreen *onscreen;
-    GError *error = NULL;
+    CoglError *error = NULL;
     CoglVertexP2C4 triangle_vertices[] = {
         {0, 0.7, 0xff, 0x00, 0x00, 0x80},
         {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
diff --git a/examples/cogl-gles2-gears.c b/examples/cogl-gles2-gears.c
index 2952ca6..e69447c 100644
--- a/examples/cogl-gles2-gears.c
+++ b/examples/cogl-gles2-gears.c
@@ -560,7 +560,7 @@ paint_cb (void *user_data)
     Data *data = user_data;
     double elapsed = g_timer_elapsed (data->timer, NULL);
     double dt = elapsed - data->last_elapsed;
-    GError *error = NULL;
+    CoglError *error = NULL;
 
     /* Draw scene with GLES2 */
     if (!cogl_push_gles2_context (data->ctx,
@@ -755,7 +755,7 @@ main (int argc, char **argv)
 {
     Data data;
     CoglOnscreen *onscreen;
-    GError *error = NULL;
+    CoglError *error = NULL;
     GSource *cogl_source;
     GMainLoop *loop;
     CoglRenderer *renderer;
diff --git a/examples/cogl-hello.c b/examples/cogl-hello.c
index cf0e8f6..f8265f9 100644
--- a/examples/cogl-hello.c
+++ b/examples/cogl-hello.c
@@ -40,7 +40,7 @@ main (int argc, char **argv)
 {
     Data data;
     CoglOnscreen *onscreen;
-    GError *error = NULL;
+    CoglError *error = NULL;
     CoglVertexP2C4 triangle_vertices[] = {
         {0, 0.7, 0xff, 0x00, 0x00, 0x80},
         {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
diff --git a/examples/cogl-info.c b/examples/cogl-info.c
index 7c43fe2..3eacdc3 100644
--- a/examples/cogl-info.c
+++ b/examples/cogl-info.c
@@ -170,7 +170,7 @@ main (int argc, char **argv)
   CoglRenderer *renderer;
   CoglDisplay *display;
   CoglContext *ctx;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglWinsysID winsys_id;
   const char *winsys_name;
 
diff --git a/examples/cogl-msaa.c b/examples/cogl-msaa.c
index 99f9b8d..73f9c4e 100644
--- a/examples/cogl-msaa.c
+++ b/examples/cogl-msaa.c
@@ -10,7 +10,7 @@ main (int argc, char **argv)
     CoglContext *ctx;
     CoglOnscreen *onscreen;
     CoglFramebuffer *fb;
-    GError *error = NULL;
+    CoglError *error = NULL;
     CoglVertexP2C4 triangle_vertices[] = {
         {0, 0.7, 0xff, 0x00, 0x00, 0x80},
         {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
@@ -49,7 +49,7 @@ main (int argc, char **argv)
       {
         fprintf (stderr, "Failed to allocate 4x msaa offscreen framebuffer, "
                  "disabling msaa for onscreen rendering: %s\n", error->message);
-        g_error_free (error);
+        cogl_error_free (error);
         cogl_framebuffer_set_samples_per_pixel (fb, 0);
 
         error = NULL;
@@ -70,7 +70,7 @@ main (int argc, char **argv)
     cogl_framebuffer_set_samples_per_pixel (offscreen_fb, 4);
     if (!cogl_framebuffer_allocate (offscreen_fb, &error))
       {
-        g_error_free (error);
+        cogl_error_free (error);
         error = NULL;
         fprintf (stderr, "Failed to allocate 4x msaa offscreen framebuffer, "
                  "disabling msaa for offscreen rendering");
diff --git a/examples/cogl-sdl-hello.c b/examples/cogl-sdl-hello.c
index 1525deb..41b99af 100644
--- a/examples/cogl-sdl-hello.c
+++ b/examples/cogl-sdl-hello.c
@@ -68,7 +68,7 @@ main (int argc, char **argv)
 {
   CoglContext *ctx;
   CoglOnscreen *onscreen;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglVertexP2C4 triangle_vertices[] = {
     {0, 0.7, 0xff, 0x00, 0x00, 0x80},
     {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
diff --git a/examples/cogl-sdl2-hello.c b/examples/cogl-sdl2-hello.c
index f465771..5df40ab 100644
--- a/examples/cogl-sdl2-hello.c
+++ b/examples/cogl-sdl2-hello.c
@@ -77,7 +77,7 @@ main (int argc, char **argv)
 {
   CoglContext *ctx;
   CoglOnscreen *onscreen;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglVertexP2C4 triangle_vertices[] = {
     {0, 0.7, 0xff, 0x00, 0x00, 0x80},
     {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
diff --git a/examples/cogl-x11-foreign.c b/examples/cogl-x11-foreign.c
index 9397f4d..ca9e3ed 100644
--- a/examples/cogl-x11-foreign.c
+++ b/examples/cogl-x11-foreign.c
@@ -53,7 +53,7 @@ main (int argc, char **argv)
   CoglOnscreen *onscreen;
   CoglFramebuffer *fb;
   CoglPipeline *pipeline;
-  GError *error = NULL;
+  CoglError *error = NULL;
   uint32_t visual;
   XVisualInfo template, *xvisinfo;
   int visinfos_count;
diff --git a/examples/cogl-x11-tfp.c b/examples/cogl-x11-tfp.c
index d42bcb1..dd19366 100644
--- a/examples/cogl-x11-tfp.c
+++ b/examples/cogl-x11-tfp.c
@@ -49,7 +49,7 @@ main (int argc, char **argv)
   CoglContext *ctx;
   CoglOnscreen *onscreen;
   CoglFramebuffer *fb;
-  GError *error = NULL;
+  CoglError *error = NULL;
   uint32_t visual;
   XVisualInfo template, *xvisinfo;
   int visinfos_count;
diff --git a/examples/cogland.c b/examples/cogland.c
index d6f7bf8..9273831 100644
--- a/examples/cogland.c
+++ b/examples/cogland.c
@@ -299,7 +299,7 @@ cogland_surface_attach_buffer (struct wl_client *wayland_client,
 
   if (!buffer->texture)
     {
-      GError *error = NULL;
+      CoglError *error = NULL;
 
       buffer->texture =
         cogl_wayland_texture_2d_new_from_buffer (compositor->cogl_context,
@@ -453,7 +453,7 @@ cogland_compositor_create_output (CoglandCompositor *compositor,
 {
   CoglandOutput *output = g_slice_new0 (CoglandOutput);
   CoglFramebuffer *fb;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglandMode *mode;
 
   output->x = x;
@@ -694,7 +694,7 @@ main (int argc, char **argv)
 {
   CoglandCompositor compositor;
   GMainLoop *loop;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglVertexP2C4 triangle_vertices[] = {
       {0, 0.7, 0xff, 0x00, 0x00, 0x80},
       {-0.7, -0.7, 0x00, 0xff, 0x00, 0xff},
diff --git a/tests/conform/test-blend-strings.c b/tests/conform/test-blend-strings.c
index 967d53a..e85e0de 100644
--- a/tests/conform/test-blend-strings.c
+++ b/tests/conform/test-blend-strings.c
@@ -55,7 +55,7 @@ test_blend (TestState *state,
   CoglHandle material;
   CoglPipeline *pipeline;
   CoglBool status;
-  GError *error = NULL;
+  CoglError *error = NULL;
   int y_off;
   int x_off;
 
@@ -230,7 +230,7 @@ test_tex_combine (TestState *state,
 
   CoglHandle material;
   CoglBool status;
-  GError *error = NULL;
+  CoglError *error = NULL;
   int y_off;
   int x_off;
 
diff --git a/tests/conform/test-gles2-context.c b/tests/conform/test-gles2-context.c
index d84c78e..4f1e390 100644
--- a/tests/conform/test-gles2-context.c
+++ b/tests/conform/test-gles2-context.c
@@ -21,7 +21,7 @@ test_push_pop_single_context (void)
   CoglPipeline *pipeline;
   CoglGLES2Context *gles2_ctx;
   const CoglGLES2Vtable *gles2;
-  GError *error = NULL;
+  CoglError *error = NULL;
 
   offscreen_texture = COGL_TEXTURE (
     cogl_texture_2d_new_with_size (ctx,
@@ -146,7 +146,7 @@ create_gles2_context (CoglTexture **offscreen_texture,
                       CoglGLES2Context **gles2_ctx,
                       const CoglGLES2Vtable **gles2)
 {
-  GError *error = NULL;
+  CoglError *error = NULL;
 
   *offscreen_texture = COGL_TEXTURE (
     cogl_texture_2d_new_with_size (ctx,
@@ -179,7 +179,7 @@ test_push_pop_multi_context (void)
   CoglPipeline *pipeline1;
   CoglGLES2Context *gles2_ctx1;
   const CoglGLES2Vtable *gles21;
-  GError *error = NULL;
+  CoglError *error = NULL;
 
   create_gles2_context (&offscreen_texture0,
                         &offscreen0,
@@ -278,7 +278,7 @@ test_gles2_read_pixels (void)
   CoglPipeline *pipeline;
   CoglGLES2Context *gles2_ctx;
   const CoglGLES2Vtable *gles2;
-  GError *error = NULL;
+  CoglError *error = NULL;
   GLubyte pixel[3];
   GLuint fbo_handle;
 
@@ -684,7 +684,7 @@ test_gles2_context_fbo (void)
       CoglPipeline *pipeline;
       CoglGLES2Context *gles2_ctx;
       GLuint program;
-      GError *error = NULL;
+      CoglError *error = NULL;
 
       create_gles2_context (&offscreen_texture,
                             &offscreen,
@@ -814,7 +814,7 @@ test_gles2_context_copy_tex_image (void)
   CoglPipeline *pipeline;
   CoglGLES2Context *gles2_ctx;
   const CoglGLES2Vtable *gles2;
-  GError *error = NULL;
+  CoglError *error = NULL;
   GLuint tex;
   GLint tex_uniform_location;
   GLint pos_location;
diff --git a/tests/conform/test-just-vertex-shader.c b/tests/conform/test-just-vertex-shader.c
index 908fade..d42b8b5 100644
--- a/tests/conform/test-just-vertex-shader.c
+++ b/tests/conform/test-just-vertex-shader.c
@@ -30,7 +30,7 @@ paint_legacy (TestState *state)
   CoglHandle material = cogl_material_new ();
   CoglTexture *tex;
   CoglColor color;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglHandle shader, program;
 
   cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
@@ -100,7 +100,7 @@ paint (TestState *state)
   CoglPipeline *pipeline = cogl_pipeline_new (ctx);
   CoglTexture *tex;
   CoglColor color;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglHandle shader, program;
 
   cogl_color_init_from_4ub (&color, 0, 0, 0, 255);
diff --git a/tests/conform/test-multitexture.c b/tests/conform/test-multitexture.c
index aeb409c..6eab806 100644
--- a/tests/conform/test-multitexture.c
+++ b/tests/conform/test-multitexture.c
@@ -104,7 +104,7 @@ on_paint (ClutterActor *actor, TestState *state)
   CoglHandle tex0, tex1;
   CoglHandle material;
   CoglBool status;
-  GError *error = NULL;
+  CoglError *error = NULL;
   float tex_coords[] = {
     0, 0, 0.5, 0.5, /* tex0 */
     0.5, 0.5, 1, 1 /* tex1 */
diff --git a/tests/conform/test-pipeline-user-matrix.c b/tests/conform/test-pipeline-user-matrix.c
index c9d18f6..6bf6ed2 100644
--- a/tests/conform/test-pipeline-user-matrix.c
+++ b/tests/conform/test-pipeline-user-matrix.c
@@ -54,7 +54,7 @@ paint (TestState *state)
   CoglTexture *tex0, *tex1;
   CoglPipeline *pipeline;
   CoglMatrix matrix;
-  GError *error = NULL;
+  CoglError *error = NULL;
 
   cogl_framebuffer_orthographic (fb,
                                  0, 0,
diff --git a/tests/conform/test-point-sprite.c b/tests/conform/test-point-sprite.c
index d50611f..5aa5b44 100644
--- a/tests/conform/test-point-sprite.c
+++ b/tests/conform/test-point-sprite.c
@@ -24,7 +24,7 @@ do_test (CoglBool check_orientation)
   int fb_width = cogl_framebuffer_get_width (fb);
   int fb_height = cogl_framebuffer_get_height (fb);
   CoglPrimitive *prim;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglTexture2D *tex_2d;
   CoglPipeline *pipeline, *solid_pipeline;
   CoglBool res;
diff --git a/tests/conform/test-sub-texture.c b/tests/conform/test-sub-texture.c
index dd86438..fb6f740 100644
--- a/tests/conform/test-sub-texture.c
+++ b/tests/conform/test-sub-texture.c
@@ -31,7 +31,6 @@ create_source (TestState *state)
   int dx, dy;
   uint8_t *data = g_malloc (SOURCE_SIZE * SOURCE_SIZE * 4);
   CoglTexture2D *tex;
-  GError *error = NULL;
 
   /* Create a texture with a different coloured rectangle at each
      corner */
@@ -61,8 +60,7 @@ create_source (TestState *state)
                                        COGL_PIXEL_FORMAT_ANY,
                                        SOURCE_SIZE * 4,
                                        data,
-                                       &error);
-  g_assert_no_error (error);
+                                       NULL);
   return tex;
 }
 
@@ -72,7 +70,6 @@ create_test_texture (TestState *state)
   CoglTexture2D *tex;
   uint8_t *data = g_malloc (256 * 256 * 4), *p = data;
   int x, y;
-  GError *error = NULL;
 
   /* Create a texture that is 256x256 where the red component ranges
      from 0->255 along the x axis and the green component ranges from
@@ -93,9 +90,7 @@ create_test_texture (TestState *state)
                                        COGL_PIXEL_FORMAT_ANY,
                                        256 * 4,
                                        data,
-                                       &error);
-  g_assert_no_error (error);
-
+                                       NULL);
   g_free (data);
 
   return tex;
diff --git a/tests/conform/test-texture-3d.c b/tests/conform/test-texture-3d.c
index 547e532..a493326 100644
--- a/tests/conform/test-texture-3d.c
+++ b/tests/conform/test-texture-3d.c
@@ -24,7 +24,7 @@ create_texture_3d (CoglContext *context)
   uint8_t *data = g_malloc (TEX_IMAGE_STRIDE * TEX_DEPTH);
   uint8_t *p = data;
   CoglTexture3D *tex;
-  GError *error = NULL;
+  CoglError *error = NULL;
 
   for (z = 0; z < TEX_DEPTH; z++)
     {
diff --git a/tests/conform/test-utils.c b/tests/conform/test-utils.c
index e712d14..bbf9b05 100644
--- a/tests/conform/test-utils.c
+++ b/tests/conform/test-utils.c
@@ -16,7 +16,7 @@ void
 test_utils_init (TestFlags flags)
 {
   static int counter = 0;
-  GError *error = NULL;
+  CoglError *error = NULL;
   CoglOnscreen *onscreen = NULL;
   CoglDisplay *display;
   CoglRenderer *renderer;



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