Index: uspace/lib/gfx/include/gfx/coord.h
===================================================================
--- uspace/lib/gfx/include/gfx/coord.h	(revision a40ae0d786e6716313eec18bc48f28cfe11babcf)
+++ uspace/lib/gfx/include/gfx/coord.h	(revision 6c2aba3fef6f293d95c6f25efe30068d7cf8a73f)
@@ -42,4 +42,5 @@
 extern void gfx_coord2_add(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
 extern void gfx_coord2_subtract(gfx_coord2_t *, gfx_coord2_t *, gfx_coord2_t *);
+extern void gfx_coord2_clip(gfx_coord2_t *, gfx_rect_t *, gfx_coord2_t *);
 extern void gfx_span_points_sort(gfx_coord_t, gfx_coord_t, gfx_coord_t *,
     gfx_coord_t *);
Index: uspace/lib/gfx/src/coord.c
===================================================================
--- uspace/lib/gfx/src/coord.c	(revision a40ae0d786e6716313eec18bc48f28cfe11babcf)
+++ uspace/lib/gfx/src/coord.c	(revision 6c2aba3fef6f293d95c6f25efe30068d7cf8a73f)
@@ -62,4 +62,18 @@
 }
 
+void gfx_coord2_clip(gfx_coord2_t *a, gfx_rect_t *clip, gfx_coord2_t *d)
+{
+	gfx_rect_t sclip;
+	gfx_coord2_t t;
+
+	gfx_rect_points_sort(clip, &sclip);
+
+	t.x = min(a->x, clip->p1.x - 1);
+	t.y = min(a->y, clip->p1.y - 1);
+
+	d->x = max(clip->p0.x, t.x);
+	d->y = max(clip->p0.y, t.y);
+}
+
 /** Sort points of a span.
  *
Index: uspace/lib/gfx/test/coord.c
===================================================================
--- uspace/lib/gfx/test/coord.c	(revision a40ae0d786e6716313eec18bc48f28cfe11babcf)
+++ uspace/lib/gfx/test/coord.c	(revision 6c2aba3fef6f293d95c6f25efe30068d7cf8a73f)
@@ -68,4 +68,67 @@
 }
 
+/** gfx_coord2_clip with point to lower-left of clipping rectangle */
+PCUT_TEST(coord2_clip_ll)
+{
+	gfx_coord2_t p;
+	gfx_coord2_t cp;
+	gfx_rect_t rect;
+
+	p.x = 1;
+	p.y = 2;
+
+	rect.p0.x = 3;
+	rect.p0.y = 4;
+	rect.p1.x = 5;
+	rect.p1.y = 6;
+
+	gfx_coord2_clip(&p, &rect, &cp);
+
+	PCUT_ASSERT_INT_EQUALS(3, cp.x);
+	PCUT_ASSERT_INT_EQUALS(4, cp.y);
+}
+
+/** gfx_coord2_clip with point inside the clipping rectangle */
+PCUT_TEST(coord2_clip_mm)
+{
+	gfx_coord2_t p;
+	gfx_coord2_t cp;
+	gfx_rect_t rect;
+
+	p.x = 2;
+	p.y = 3;
+
+	rect.p0.x = 1;
+	rect.p0.y = 2;
+	rect.p1.x = 3;
+	rect.p1.y = 4;
+
+	gfx_coord2_clip(&p, &rect, &cp);
+
+	PCUT_ASSERT_INT_EQUALS(2, cp.x);
+	PCUT_ASSERT_INT_EQUALS(3, cp.y);
+}
+
+/** gfx_coord2_clip with point to upper-right of clipping rectangle */
+PCUT_TEST(coord2_clip_hh)
+{
+	gfx_coord2_t p;
+	gfx_coord2_t cp;
+	gfx_rect_t rect;
+
+	p.x = 5;
+	p.y = 6;
+
+	rect.p0.x = 1;
+	rect.p0.y = 2;
+	rect.p1.x = 3;
+	rect.p1.y = 4;
+
+	gfx_coord2_clip(&p, &rect, &cp);
+
+	PCUT_ASSERT_INT_EQUALS(2, cp.x);
+	PCUT_ASSERT_INT_EQUALS(3, cp.y);
+}
+
 /** gfx_rect_translate should translate rectangle */
 PCUT_TEST(rect_translate)
