Index: .gitignore
===================================================================
--- .gitignore	(revision d6dc9a121d673c915860fb0070e7ac23defa2d45)
+++ .gitignore	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -105,4 +105,5 @@
 uspace/app/fontviewer/fontviewer
 uspace/app/getterm/getterm
+uspace/app/gfxdemo/gfxdemo
 uspace/app/gunzip/gunzip
 uspace/app/hbench/hbench
@@ -386,4 +387,5 @@
 uspace/lib/c/arch/sparc64/_link.ld
 uspace/lib/c/test-libc
+uspace/lib/gfx/test-libgfx
 uspace/lib/label/test-liblabel
 uspace/lib/math/test-libmath
Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision d6dc9a121d673c915860fb0070e7ac23defa2d45)
+++ boot/Makefile.common	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -191,4 +191,5 @@
 	edit \
 	fdisk \
+	gfxdemo \
 	gunzip \
 	hbench \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision d6dc9a121d673c915860fb0070e7ac23defa2d45)
+++ uspace/Makefile	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -49,4 +49,5 @@
 	app/fontviewer \
 	app/getterm \
+	app/gfxdemo \
 	app/gunzip \
 	app/hbench \
Index: uspace/app/gfxdemo/Makefile
===================================================================
--- uspace/app/gfxdemo/Makefile	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
+++ uspace/app/gfxdemo/Makefile	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2019 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+
+LIBS = gfx
+
+BINARY = gfxdemo
+
+SOURCES = \
+	gfxdemo.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/gfxdemo/doc/doxygroups.h
===================================================================
--- uspace/app/gfxdemo/doc/doxygroups.h	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
+++ uspace/app/gfxdemo/doc/doxygroups.h	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -0,0 +1,4 @@
+/** @addtogroup vdemo vdemo
+ * @brief Demo application
+ * @ingroup apps
+ */
Index: uspace/app/gfxdemo/gfxdemo.c
===================================================================
--- uspace/app/gfxdemo/gfxdemo.c	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
+++ uspace/app/gfxdemo/gfxdemo.c	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2019 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup gfxdemo
+ * @{
+ */
+/** @file Graphic demo
+ */
+
+#include <gfx/color.h>
+#include <gfx/render.h>
+
+int main(int argc, char *argv[])
+{
+}
+
+/** @}
+ */
Index: uspace/lib/gfx/Makefile
===================================================================
--- uspace/lib/gfx/Makefile	(revision d6dc9a121d673c915860fb0070e7ac23defa2d45)
+++ uspace/lib/gfx/Makefile	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -33,4 +33,5 @@
 SOURCES = \
 	src/color.c \
+	src/context.c \
 	src/render.c
 
Index: uspace/lib/gfx/include/gfx/context.h
===================================================================
--- uspace/lib/gfx/include/gfx/context.h	(revision d6dc9a121d673c915860fb0070e7ac23defa2d45)
+++ uspace/lib/gfx/include/gfx/context.h	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -41,5 +41,11 @@
 #define _GFX_CONTEXT_H
 
+#include <errno.h>
 #include <types/gfx/context.h>
+#include <types/gfx/ops/context.h>
+
+extern errno_t gfx_context_new(gfx_context_ops_t *, void *,
+    gfx_context_t **);
+extern errno_t gfx_context_delete(gfx_context_t *);
 
 #endif
Index: uspace/lib/gfx/include/types/gfx/ops/context.h
===================================================================
--- uspace/lib/gfx/include/types/gfx/ops/context.h	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
+++ uspace/lib/gfx/include/types/gfx/ops/context.h	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2019 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libgfx
+ * @{
+ */
+/**
+ * @file Graphics context ops
+ *
+ * The ops structure describing an implementation of a graphics context.
+ */
+
+#ifndef _GFX_TYPES_OPS_CONTEXT_H
+#define _GFX_TYPES_OPS_CONTEXT_H
+
+#include <errno.h>
+#include <types/gfx/color.h>
+#include <types/gfx/coord.h>
+#include <types/gfx/context.h>
+
+/** Graphics context ops */
+typedef struct {
+	/** Set drawing collor */
+	errno_t (*set_color)(void *, gfx_color_t *);
+	/** Fill rectangle using the current drawing color */
+	errno_t (*fill_rect)(void *, gfx_rect_t *);
+} gfx_context_ops_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/gfx/private/context.h
===================================================================
--- uspace/lib/gfx/private/context.h	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
+++ uspace/lib/gfx/private/context.h	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2019 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libgfx
+ * @{
+ */
+/**
+ * @file Graphics context structure
+ *
+ */
+
+#ifndef _GFX_PRIVATE_CONTEXT_H
+#define _GFX_PRIVATE_CONTEXT_H
+
+#include <types/gfx/ops/context.h>
+
+/** Actual structure of graphics context.
+ *
+ * This is private to libgfx. It is not visible to clients nor backends.
+ */
+struct gfx_context {
+	/** Graphics context ops */
+	gfx_context_ops_t *ops;
+	/** Instance argument */
+	void *arg;
+};
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/gfx/src/context.c
===================================================================
--- uspace/lib/gfx/src/context.c	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
+++ uspace/lib/gfx/src/context.c	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2019 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libgfx
+ * @{
+ */
+/**
+ * @file Graphics context
+ */
+
+#include <gfx/context.h>
+#include <stdlib.h>
+#include "../private/context.h"
+
+/** Create new graphics context.
+ *
+ * Create new graphics context with the specified ops and argument.
+ *
+ * @param ops Graphics context ops
+ * @param arg Instance argument
+ * @param rgc Place to store pointer to new graphics context on success
+ * @return EOK on success, ENOMEM if out of memory
+ */
+errno_t gfx_context_new(gfx_context_ops_t *ops, void *arg,
+    gfx_context_t **rgc)
+{
+	gfx_context_t *gc;
+
+	gc = calloc(1, sizeof(gfx_context_t));
+	if (gc == NULL)
+		return ENOMEM;
+
+	gc->ops = ops;
+	gc->arg = arg;
+	*rgc = gc;
+	return EOK;
+}
+
+/** Delete graphics context.
+ *
+ * @param gc Graphics context
+ */
+errno_t gfx_context_delete(gfx_context_t *gc)
+{
+	free(gc);
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/gfx/src/render.c
===================================================================
--- uspace/lib/gfx/src/render.c	(revision d6dc9a121d673c915860fb0070e7ac23defa2d45)
+++ uspace/lib/gfx/src/render.c	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -35,4 +35,5 @@
 
 #include <gfx/render.h>
+#include "../private/context.h"
 
 /** Set drawing color.
@@ -46,5 +47,5 @@
 errno_t gfx_set_color(gfx_context_t *gc, gfx_color_t *color)
 {
-	return EOK;
+	return gc->ops->set_color(gc->arg, color);
 }
 
@@ -59,5 +60,5 @@
 errno_t gfx_fill_rect(gfx_context_t *gc, gfx_rect_t *rect)
 {
-	return EOK;
+	return gc->ops->fill_rect(gc->arg, rect);
 }
 
Index: uspace/lib/gfx/test/render.c
===================================================================
--- uspace/lib/gfx/test/render.c	(revision d6dc9a121d673c915860fb0070e7ac23defa2d45)
+++ uspace/lib/gfx/test/render.c	(revision 045186b0aef93f3aa6d7952248a1db55a0c08b5e)
@@ -28,10 +28,26 @@
 
 #include <gfx/color.h>
+#include <gfx/context.h>
 #include <gfx/render.h>
 #include <pcut/pcut.h>
+#include <mem.h>
 
 PCUT_INIT;
 
 PCUT_TEST_SUITE(render);
+
+static errno_t testgc_set_color(void *, gfx_color_t *);
+static errno_t testgc_fill_rect(void *, gfx_rect_t *);
+
+static gfx_context_ops_t ops = {
+	.set_color = testgc_set_color,
+	.fill_rect = testgc_fill_rect
+};
+
+/** Test graphics context data */
+typedef struct {
+	gfx_color_t *dclr;
+	gfx_rect_t *rect;
+} test_gc_t;
 
 PCUT_TEST(set_color)
@@ -40,4 +56,10 @@
 	gfx_color_t *color;
 	gfx_context_t *gc = NULL;
+	test_gc_t tgc;
+
+	memset(&tgc, 0, sizeof(tgc));
+
+	rc = gfx_context_new(&ops, &tgc, &gc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 
 	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
@@ -46,6 +68,11 @@
 	rc = gfx_set_color(gc, color);
 	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+	PCUT_ASSERT_EQUALS(color, tgc.dclr);
+	PCUT_ASSERT_NULL(tgc.rect);
 
 	gfx_color_delete(color);
+
+	rc = gfx_context_delete(gc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 }
 
@@ -56,4 +83,10 @@
 	gfx_rect_t rect;
 	gfx_context_t *gc = NULL;
+	test_gc_t tgc;
+
+	memset(&tgc, 0, sizeof(tgc));
+
+	rc = gfx_context_new(&ops, &tgc, &gc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
 
 	rc = gfx_color_new_rgb_i16(0xffff, 0xffff, 0xffff, &color);
@@ -62,9 +95,32 @@
 	rc = gfx_set_color(gc, color);
 	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+	PCUT_ASSERT_EQUALS(color, tgc.dclr);
 
 	rc = gfx_fill_rect(gc, &rect);
 	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+	PCUT_ASSERT_EQUALS(&rect, tgc.rect);
 
 	gfx_color_delete(color);
+
+	rc = gfx_context_delete(gc);
+	PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+}
+
+errno_t testgc_set_color(void *arg, gfx_color_t *color)
+{
+	test_gc_t *tgc = (test_gc_t *) arg;
+
+	/* Technically we should copy the data */
+	tgc->dclr = color;
+	return EOK;
+}
+
+errno_t testgc_fill_rect(void *arg, gfx_rect_t *rect)
+{
+	test_gc_t *tgc = (test_gc_t *) arg;
+
+	/* Technically we should copy the data */
+	tgc->rect = rect;
+	return EOK;
 }
 
