commit 6dfd3cdec7ba56fbcccdf23dffe7a3ce22a57e29
parent 2ccabcc25c322c5db28f547efd4139baf1e3702a
Author: Michael Forney <mforney@mforney.org>
Date: Fri, 12 Jul 2013 19:21:28 -0700
Initial import
Diffstat:
| A | .gitignore | | | 30 | ++++++++++++++++++++++++++++++ |
| A | Makefile.am | | | 46 | ++++++++++++++++++++++++++++++++++++++++++++++ |
| A | TODO | | | 7 | +++++++ |
| A | autogen.sh | | | 13 | +++++++++++++ |
| A | color.c | | | 849 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | configure.ac | | | 136 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | drawable.c | | | 78 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | drm-private.h | | | 50 | ++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | font.c | | | 222 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | intel.c | | | 226 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | intel.h | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | pixman.c | | | 248 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | pixman.h | | | 54 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | protocol/Makefile.am | | | 7 | +++++++ |
| A | protocol/wayland-drm.xml | | | 182 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wayland-drm.c | | | 312 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wayland-drm.h | | | 70 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wayland-private.h | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wayland-shm.c | | | 221 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wayland-shm.h | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wayland.c | | | 283 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wayland.h | | | 93 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wld-private.h | | | 135 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wld.h | | | 144 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| A | wld.pc.in | | | 14 | ++++++++++++++ |
25 files changed, 3610 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,30 @@
+*.o
+*.lo
+.*.swp
+
+.deps/
+.libs/
+
+Makefile
+Makefile.in
+
+/aclocal.m4
+/ar-lib
+/autom4te.cache/
+/config.guess
+/config.log
+/config.status
+/config.sub
+/configure
+/depcomp
+/install-sh
+/libtool
+/ltmain.sh
+/m4/
+/missing
+
+/libwld.la
+/wld.pc
+/protocol/wayland-drm-client-protocol.h
+/protocol/wayland-drm-protocol.c
+
diff --git a/Makefile.am b/Makefile.am
@@ -0,0 +1,46 @@
+# wld: Makefile.am
+
+ACLOCAL_AMFLAGS = -I m4
+AM_CFLAGS = $(fontconfig_CFLAGS) $(freetype_CFLAGS) $(pixman_CFLAGS)
+
+lib_LTLIBRARIES = libwld.la
+pkginclude_HEADERS = wld.h
+
+pkgconfigdir = $(libdir)/pkgconfig
+pkgconfig_DATA = wld.pc
+
+libwld_la_SOURCES = color.c drawable.c font.c
+libwld_la_LIBADD = $(fontconfig_LIBS) $(freetype_LIBS) $(pixman_LIBS)
+
+if WITH_WAYLAND
+ AM_CFLAGS += $(wayland_client_CFLAGS)
+ libwld_la_SOURCES += wayland.c
+ libwld_la_LIBADD += $(wayland_client_LIBS)
+ pkginclude_HEADERS += wayland.h
+endif
+
+if ENABLE_WAYLAND_DRM
+ AM_CPPFLAGS = -I$(top_builddir)/protocol
+ libwld_la_SOURCES += wayland-drm.c protocol/wayland-drm-protocol.c
+ pkginclude_HEADERS += wayland-drm.h
+endif
+
+if ENABLE_WAYLAND_SHM
+ libwld_la_SOURCES += wayland-shm.c
+ pkginclude_HEADERS += wayland-shm.h
+endif
+
+if ENABLE_INTEL
+ AM_CFLAGS += $(drm_intel_CFLAGS) $(intelbatch_CFLAGS)
+ libwld_la_SOURCES += intel.c
+ libwld_la_LIBADD += $(drm_intel_LIBS) $(intelbatch_LIBS)
+ pkginclude_HEADERS += intel.h
+endif
+
+if ENABLE_PIXMAN
+ libwld_la_SOURCES += pixman.c
+ pkginclude_HEADERS += pixman.h
+endif
+
+SUBDIRS = protocol
+
diff --git a/TODO b/TODO
@@ -0,0 +1,7 @@
+TODO
+====
+- Non-monochrome text rendering
+ - Probably requires 3d engine blending for intel backend
+- Optional damage tracking and handling for Wayland drawables
+- Add doxygen documentation
+
diff --git a/autogen.sh b/autogen.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+set -ex
+
+rm -rf autom4te.cache
+
+libtoolize
+aclocal -I m4 --force
+autoconf -f -W all
+automake -f -a -c -W all
+
+rm -rf autom4te.cache
+
diff --git a/color.c b/color.c
@@ -0,0 +1,849 @@
+/* Adapted from xorg-server */
+
+/***********************************************************
+
+Copyright 1987, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of Digital not be
+used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
+ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
+DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
+ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
+SOFTWARE.
+
+******************************************************************/
+
+#include "wld-private.h"
+
+#include <strings.h>
+
+struct named_color
+{
+ const char * name;
+ uint32_t color;
+};
+
+static const struct named_color named_colors[] = {
+ { "alice blue", 0xfff0f8ff },
+ { "AliceBlue", 0xfff0f8ff },
+ { "antique white", 0xfffaebd7 },
+ { "AntiqueWhite", 0xfffaebd7 },
+ { "AntiqueWhite1", 0xffffefdb },
+ { "AntiqueWhite2", 0xffeedfcc },
+ { "AntiqueWhite3", 0xffcdc0b0 },
+ { "AntiqueWhite4", 0xff8b8378 },
+ { "aquamarine", 0xff7fffd4 },
+ { "aquamarine1", 0xff7fffd4 },
+ { "aquamarine2", 0xff76eec6 },
+ { "aquamarine3", 0xff66cdaa },
+ { "aquamarine4", 0xff458b74 },
+ { "azure", 0xfff0ffff },
+ { "azure1", 0xfff0ffff },
+ { "azure2", 0xffe0eeee },
+ { "azure3", 0xffc1cdcd },
+ { "azure4", 0xff838b8b },
+ { "beige", 0xfff5f5dc },
+ { "bisque", 0xffffe4c4 },
+ { "bisque1", 0xffffe4c4 },
+ { "bisque2", 0xffeed5b7 },
+ { "bisque3", 0xffcdb79e },
+ { "bisque4", 0xff8b7d6b },
+ { "black", 0xff000000 },
+ { "blanched almond", 0xffffebcd },
+ { "BlanchedAlmond", 0xffffebcd },
+ { "blue", 0xff0000ff },
+ { "blue violet", 0xff8a2be2 },
+ { "blue1", 0xff0000ff },
+ { "blue2", 0xff0000ee },
+ { "blue3", 0xff0000cd },
+ { "blue4", 0xff00008b },
+ { "BlueViolet", 0xff8a2be2 },
+ { "brown", 0xffa52a2a },
+ { "brown1", 0xffff4040 },
+ { "brown2", 0xffee3b3b },
+ { "brown3", 0xffcd3333 },
+ { "brown4", 0xff8b2323 },
+ { "burlywood", 0xffdeb887 },
+ { "burlywood1", 0xffffd39b },
+ { "burlywood2", 0xffeec591 },
+ { "burlywood3", 0xffcdaa7d },
+ { "burlywood4", 0xff8b7355 },
+ { "cadet blue", 0xff5f9ea0 },
+ { "CadetBlue", 0xff5f9ea0 },
+ { "CadetBlue1", 0xff98f5ff },
+ { "CadetBlue2", 0xff8ee5ee },
+ { "CadetBlue3", 0xff7ac5cd },
+ { "CadetBlue4", 0xff53868b },
+ { "chartreuse", 0xff7fff00 },
+ { "chartreuse1", 0xff7fff00 },
+ { "chartreuse2", 0xff76ee00 },
+ { "chartreuse3", 0xff66cd00 },
+ { "chartreuse4", 0xff458b00 },
+ { "chocolate", 0xffd2691e },
+ { "chocolate1", 0xffff7f24 },
+ { "chocolate2", 0xffee7621 },
+ { "chocolate3", 0xffcd661d },
+ { "chocolate4", 0xff8b4513 },
+ { "coral", 0xffff7f50 },
+ { "coral1", 0xffff7256 },
+ { "coral2", 0xffee6a50 },
+ { "coral3", 0xffcd5b45 },
+ { "coral4", 0xff8b3e2f },
+ { "cornflower blue", 0xff6495ed },
+ { "CornflowerBlue", 0xff6495ed },
+ { "cornsilk", 0xfffff8dc },
+ { "cornsilk1", 0xfffff8dc },
+ { "cornsilk2", 0xffeee8cd },
+ { "cornsilk3", 0xffcdc8b1 },
+ { "cornsilk4", 0xff8b8878 },
+ { "cyan", 0xff00ffff },
+ { "cyan1", 0xff00ffff },
+ { "cyan2", 0xff00eeee },
+ { "cyan3", 0xff00cdcd },
+ { "cyan4", 0xff008b8b },
+ { "dark blue", 0xff00008b },
+ { "dark cyan", 0xff008b8b },
+ { "dark goldenrod", 0xffb8860b },
+ { "dark gray", 0xffa9a9a9 },
+ { "dark green", 0xff006400 },
+ { "dark grey", 0xffa9a9a9 },
+ { "dark khaki", 0xffbdb76b },
+ { "dark magenta", 0xff8b008b },
+ { "dark olive green", 0xff556b2f },
+ { "dark orange", 0xffff8c00 },
+ { "dark orchid", 0xff9932cc },
+ { "dark red", 0xff8b0000 },
+ { "dark salmon", 0xffe9967a },
+ { "dark sea green", 0xff8fbc8f },
+ { "dark slate blue", 0xff483d8b },
+ { "dark slate gray", 0xff2f4f4f },
+ { "dark slate grey", 0xff2f4f4f },
+ { "dark turquoise", 0xff00ced1 },
+ { "dark violet", 0xff9400d3 },
+ { "DarkBlue", 0xff00008b },
+ { "DarkCyan", 0xff008b8b },
+ { "DarkGoldenrod", 0xffb8860b },
+ { "DarkGoldenrod1", 0xffffb90f },
+ { "DarkGoldenrod2", 0xffeead0e },
+ { "DarkGoldenrod3", 0xffcd950c },
+ { "DarkGoldenrod4", 0xff8b6508 },
+ { "DarkGray", 0xffa9a9a9 },
+ { "DarkGreen", 0xff006400 },
+ { "DarkGrey", 0xffa9a9a9 },
+ { "DarkKhaki", 0xffbdb76b },
+ { "DarkMagenta", 0xff8b008b },
+ { "DarkOliveGreen", 0xff556b2f },
+ { "DarkOliveGreen1", 0xffcaff70 },
+ { "DarkOliveGreen2", 0xffbcee68 },
+ { "DarkOliveGreen3", 0xffa2cd5a },
+ { "DarkOliveGreen4", 0xff6e8b3d },
+ { "DarkOrange", 0xffff8c00 },
+ { "DarkOrange1", 0xffff7f00 },
+ { "DarkOrange2", 0xffee7600 },
+ { "DarkOrange3", 0xffcd6600 },
+ { "DarkOrange4", 0xff8b4500 },
+ { "DarkOrchid", 0xff9932cc },
+ { "DarkOrchid1", 0xffbf3eff },
+ { "DarkOrchid2", 0xffb23aee },
+ { "DarkOrchid3", 0xff9a32cd },
+ { "DarkOrchid4", 0xff68228b },
+ { "DarkRed", 0xff8b0000 },
+ { "DarkSalmon", 0xffe9967a },
+ { "DarkSeaGreen", 0xff8fbc8f },
+ { "DarkSeaGreen1", 0xffc1ffc1 },
+ { "DarkSeaGreen2", 0xffb4eeb4 },
+ { "DarkSeaGreen3", 0xff9bcd9b },
+ { "DarkSeaGreen4", 0xff698b69 },
+ { "DarkSlateBlue", 0xff483d8b },
+ { "DarkSlateGray", 0xff2f4f4f },
+ { "DarkSlateGray1", 0xff97ffff },
+ { "DarkSlateGray2", 0xff8deeee },
+ { "DarkSlateGray3", 0xff79cdcd },
+ { "DarkSlateGray4", 0xff528b8b },
+ { "DarkSlateGrey", 0xff2f4f4f },
+ { "DarkTurquoise", 0xff00ced1 },
+ { "DarkViolet", 0xff9400d3 },
+ { "deep pink", 0xffff1493 },
+ { "deep sky blue", 0xff00bfff },
+ { "DeepPink", 0xffff1493 },
+ { "DeepPink1", 0xffff1493 },
+ { "DeepPink2", 0xffee1289 },
+ { "DeepPink3", 0xffcd1076 },
+ { "DeepPink4", 0xff8b0a50 },
+ { "DeepSkyBlue", 0xff00bfff },
+ { "DeepSkyBlue1", 0xff00bfff },
+ { "DeepSkyBlue2", 0xff00b2ee },
+ { "DeepSkyBlue3", 0xff009acd },
+ { "DeepSkyBlue4", 0xff00688b },
+ { "dim gray", 0xff696969 },
+ { "dim grey", 0xff696969 },
+ { "DimGray", 0xff696969 },
+ { "DimGrey", 0xff696969 },
+ { "dodger blue", 0xff1e90ff },
+ { "DodgerBlue", 0xff1e90ff },
+ { "DodgerBlue1", 0xff1e90ff },
+ { "DodgerBlue2", 0xff1c86ee },
+ { "DodgerBlue3", 0xff1874cd },
+ { "DodgerBlue4", 0xff104e8b },
+ { "firebrick", 0xffb22222 },
+ { "firebrick1", 0xffff3030 },
+ { "firebrick2", 0xffee2c2c },
+ { "firebrick3", 0xffcd2626 },
+ { "firebrick4", 0xff8b1a1a },
+ { "floral white", 0xfffffaf0 },
+ { "FloralWhite", 0xfffffaf0 },
+ { "forest green", 0xff228b22 },
+ { "ForestGreen", 0xff228b22 },
+ { "gainsboro", 0xffdcdcdc },
+ { "ghost white", 0xfff8f8ff },
+ { "GhostWhite", 0xfff8f8ff },
+ { "gold", 0xffffd700 },
+ { "gold1", 0xffffd700 },
+ { "gold2", 0xffeec900 },
+ { "gold3", 0xffcdad00 },
+ { "gold4", 0xff8b7500 },
+ { "goldenrod", 0xffdaa520 },
+ { "goldenrod1", 0xffffc125 },
+ { "goldenrod2", 0xffeeb422 },
+ { "goldenrod3", 0xffcd9b1d },
+ { "goldenrod4", 0xff8b6914 },
+ { "gray", 0xffbebebe },
+ { "gray0", 0xff000000 },
+ { "gray1", 0xff030303 },
+ { "gray10", 0xff1a1a1a },
+ { "gray100", 0xffffffff },
+ { "gray11", 0xff1c1c1c },
+ { "gray12", 0xff1f1f1f },
+ { "gray13", 0xff212121 },
+ { "gray14", 0xff242424 },
+ { "gray15", 0xff262626 },
+ { "gray16", 0xff292929 },
+ { "gray17", 0xff2b2b2b },
+ { "gray18", 0xff2e2e2e },
+ { "gray19", 0xff303030 },
+ { "gray2", 0xff050505 },
+ { "gray20", 0xff333333 },
+ { "gray21", 0xff363636 },
+ { "gray22", 0xff383838 },
+ { "gray23", 0xff3b3b3b },
+ { "gray24", 0xff3d3d3d },
+ { "gray25", 0xff404040 },
+ { "gray26", 0xff424242 },
+ { "gray27", 0xff454545 },
+ { "gray28", 0xff474747 },
+ { "gray29", 0xff4a4a4a },
+ { "gray3", 0xff080808 },
+ { "gray30", 0xff4d4d4d },
+ { "gray31", 0xff4f4f4f },
+ { "gray32", 0xff525252 },
+ { "gray33", 0xff545454 },
+ { "gray34", 0xff575757 },
+ { "gray35", 0xff595959 },
+ { "gray36", 0xff5c5c5c },
+ { "gray37", 0xff5e5e5e },
+ { "gray38", 0xff616161 },
+ { "gray39", 0xff636363 },
+ { "gray4", 0xff0a0a0a },
+ { "gray40", 0xff666666 },
+ { "gray41", 0xff696969 },
+ { "gray42", 0xff6b6b6b },
+ { "gray43", 0xff6e6e6e },
+ { "gray44", 0xff707070 },
+ { "gray45", 0xff737373 },
+ { "gray46", 0xff757575 },
+ { "gray47", 0xff787878 },
+ { "gray48", 0xff7a7a7a },
+ { "gray49", 0xff7d7d7d },
+ { "gray5", 0xff0d0d0d },
+ { "gray50", 0xff7f7f7f },
+ { "gray51", 0xff828282 },
+ { "gray52", 0xff858585 },
+ { "gray53", 0xff878787 },
+ { "gray54", 0xff8a8a8a },
+ { "gray55", 0xff8c8c8c },
+ { "gray56", 0xff8f8f8f },
+ { "gray57", 0xff919191 },
+ { "gray58", 0xff949494 },
+ { "gray59", 0xff969696 },
+ { "gray6", 0xff0f0f0f },
+ { "gray60", 0xff999999 },
+ { "gray61", 0xff9c9c9c },
+ { "gray62", 0xff9e9e9e },
+ { "gray63", 0xffa1a1a1 },
+ { "gray64", 0xffa3a3a3 },
+ { "gray65", 0xffa6a6a6 },
+ { "gray66", 0xffa8a8a8 },
+ { "gray67", 0xffababab },
+ { "gray68", 0xffadadad },
+ { "gray69", 0xffb0b0b0 },
+ { "gray7", 0xff121212 },
+ { "gray70", 0xffb3b3b3 },
+ { "gray71", 0xffb5b5b5 },
+ { "gray72", 0xffb8b8b8 },
+ { "gray73", 0xffbababa },
+ { "gray74", 0xffbdbdbd },
+ { "gray75", 0xffbfbfbf },
+ { "gray76", 0xffc2c2c2 },
+ { "gray77", 0xffc4c4c4 },
+ { "gray78", 0xffc7c7c7 },
+ { "gray79", 0xffc9c9c9 },
+ { "gray8", 0xff141414 },
+ { "gray80", 0xffcccccc },
+ { "gray81", 0xffcfcfcf },
+ { "gray82", 0xffd1d1d1 },
+ { "gray83", 0xffd4d4d4 },
+ { "gray84", 0xffd6d6d6 },
+ { "gray85", 0xffd9d9d9 },
+ { "gray86", 0xffdbdbdb },
+ { "gray87", 0xffdedede },
+ { "gray88", 0xffe0e0e0 },
+ { "gray89", 0xffe3e3e3 },
+ { "gray9", 0xff171717 },
+ { "gray90", 0xffe5e5e5 },
+ { "gray91", 0xffe8e8e8 },
+ { "gray92", 0xffebebeb },
+ { "gray93", 0xffededed },
+ { "gray94", 0xfff0f0f0 },
+ { "gray95", 0xfff2f2f2 },
+ { "gray96", 0xfff5f5f5 },
+ { "gray97", 0xfff7f7f7 },
+ { "gray98", 0xfffafafa },
+ { "gray99", 0xfffcfcfc },
+ { "green", 0xff00ff00 },
+ { "green yellow", 0xffadff2f },
+ { "green1", 0xff00ff00 },
+ { "green2", 0xff00ee00 },
+ { "green3", 0xff00cd00 },
+ { "green4", 0xff008b00 },
+ { "GreenYellow", 0xffadff2f },
+ { "grey", 0xffbebebe },
+ { "grey0", 0xff000000 },
+ { "grey1", 0xff030303 },
+ { "grey10", 0xff1a1a1a },
+ { "grey100", 0xffffffff },
+ { "grey11", 0xff1c1c1c },
+ { "grey12", 0xff1f1f1f },
+ { "grey13", 0xff212121 },
+ { "grey14", 0xff242424 },
+ { "grey15", 0xff262626 },
+ { "grey16", 0xff292929 },
+ { "grey17", 0xff2b2b2b },
+ { "grey18", 0xff2e2e2e },
+ { "grey19", 0xff303030 },
+ { "grey2", 0xff050505 },
+ { "grey20", 0xff333333 },
+ { "grey21", 0xff363636 },
+ { "grey22", 0xff383838 },
+ { "grey23", 0xff3b3b3b },
+ { "grey24", 0xff3d3d3d },
+ { "grey25", 0xff404040 },
+ { "grey26", 0xff424242 },
+ { "grey27", 0xff454545 },
+ { "grey28", 0xff474747 },
+ { "grey29", 0xff4a4a4a },
+ { "grey3", 0xff080808 },
+ { "grey30", 0xff4d4d4d },
+ { "grey31", 0xff4f4f4f },
+ { "grey32", 0xff525252 },
+ { "grey33", 0xff545454 },
+ { "grey34", 0xff575757 },
+ { "grey35", 0xff595959 },
+ { "grey36", 0xff5c5c5c },
+ { "grey37", 0xff5e5e5e },
+ { "grey38", 0xff616161 },
+ { "grey39", 0xff636363 },
+ { "grey4", 0xff0a0a0a },
+ { "grey40", 0xff666666 },
+ { "grey41", 0xff696969 },
+ { "grey42", 0xff6b6b6b },
+ { "grey43", 0xff6e6e6e },
+ { "grey44", 0xff707070 },
+ { "grey45", 0xff737373 },
+ { "grey46", 0xff757575 },
+ { "grey47", 0xff787878 },
+ { "grey48", 0xff7a7a7a },
+ { "grey49", 0xff7d7d7d },
+ { "grey5", 0xff0d0d0d },
+ { "grey50", 0xff7f7f7f },
+ { "grey51", 0xff828282 },
+ { "grey52", 0xff858585 },
+ { "grey53", 0xff878787 },
+ { "grey54", 0xff8a8a8a },
+ { "grey55", 0xff8c8c8c },
+ { "grey56", 0xff8f8f8f },
+ { "grey57", 0xff919191 },
+ { "grey58", 0xff949494 },
+ { "grey59", 0xff969696 },
+ { "grey6", 0xff0f0f0f },
+ { "grey60", 0xff999999 },
+ { "grey61", 0xff9c9c9c },
+ { "grey62", 0xff9e9e9e },
+ { "grey63", 0xffa1a1a1 },
+ { "grey64", 0xffa3a3a3 },
+ { "grey65", 0xffa6a6a6 },
+ { "grey66", 0xffa8a8a8 },
+ { "grey67", 0xffababab },
+ { "grey68", 0xffadadad },
+ { "grey69", 0xffb0b0b0 },
+ { "grey7", 0xff121212 },
+ { "grey70", 0xffb3b3b3 },
+ { "grey71", 0xffb5b5b5 },
+ { "grey72", 0xffb8b8b8 },
+ { "grey73", 0xffbababa },
+ { "grey74", 0xffbdbdbd },
+ { "grey75", 0xffbfbfbf },
+ { "grey76", 0xffc2c2c2 },
+ { "grey77", 0xffc4c4c4 },
+ { "grey78", 0xffc7c7c7 },
+ { "grey79", 0xffc9c9c9 },
+ { "grey8", 0xff141414 },
+ { "grey80", 0xffcccccc },
+ { "grey81", 0xffcfcfcf },
+ { "grey82", 0xffd1d1d1 },
+ { "grey83", 0xffd4d4d4 },
+ { "grey84", 0xffd6d6d6 },
+ { "grey85", 0xffd9d9d9 },
+ { "grey86", 0xffdbdbdb },
+ { "grey87", 0xffdedede },
+ { "grey88", 0xffe0e0e0 },
+ { "grey89", 0xffe3e3e3 },
+ { "grey9", 0xff171717 },
+ { "grey90", 0xffe5e5e5 },
+ { "grey91", 0xffe8e8e8 },
+ { "grey92", 0xffebebeb },
+ { "grey93", 0xffededed },
+ { "grey94", 0xfff0f0f0 },
+ { "grey95", 0xfff2f2f2 },
+ { "grey96", 0xfff5f5f5 },
+ { "grey97", 0xfff7f7f7 },
+ { "grey98", 0xfffafafa },
+ { "grey99", 0xfffcfcfc },
+ { "honeydew", 0xfff0fff0 },
+ { "honeydew1", 0xfff0fff0 },
+ { "honeydew2", 0xffe0eee0 },
+ { "honeydew3", 0xffc1cdc1 },
+ { "honeydew4", 0xff838b83 },
+ { "hot pink", 0xffff69b4 },
+ { "HotPink", 0xffff69b4 },
+ { "HotPink1", 0xffff6eb4 },
+ { "HotPink2", 0xffee6aa7 },
+ { "HotPink3", 0xffcd6090 },
+ { "HotPink4", 0xff8b3a62 },
+ { "indian red", 0xffcd5c5c },
+ { "IndianRed", 0xffcd5c5c },
+ { "IndianRed1", 0xffff6a6a },
+ { "IndianRed2", 0xffee6363 },
+ { "IndianRed3", 0xffcd5555 },
+ { "IndianRed4", 0xff8b3a3a },
+ { "ivory", 0xfffffff0 },
+ { "ivory1", 0xfffffff0 },
+ { "ivory2", 0xffeeeee0 },
+ { "ivory3", 0xffcdcdc1 },
+ { "ivory4", 0xff8b8b83 },
+ { "khaki", 0xfff0e68c },
+ { "khaki1", 0xfffff68f },
+ { "khaki2", 0xffeee685 },
+ { "khaki3", 0xffcdc673 },
+ { "khaki4", 0xff8b864e },
+ { "lavender", 0xffe6e6fa },
+ { "lavender blush", 0xfffff0f5 },
+ { "LavenderBlush", 0xfffff0f5 },
+ { "LavenderBlush1", 0xfffff0f5 },
+ { "LavenderBlush2", 0xffeee0e5 },
+ { "LavenderBlush3", 0xffcdc1c5 },
+ { "LavenderBlush4", 0xff8b8386 },
+ { "lawn green", 0xff7cfc00 },
+ { "LawnGreen", 0xff7cfc00 },
+ { "lemon chiffon", 0xfffffacd },
+ { "LemonChiffon", 0xfffffacd },
+ { "LemonChiffon1", 0xfffffacd },
+ { "LemonChiffon2", 0xffeee9bf },
+ { "LemonChiffon3", 0xffcdc9a5 },
+ { "LemonChiffon4", 0xff8b8970 },
+ { "light blue", 0xffadd8e6 },
+ { "light coral", 0xfff08080 },
+ { "light cyan", 0xffe0ffff },
+ { "light goldenrod", 0xffeedd82 },
+ { "light goldenrod yellow", 0xfffafad2 },
+ { "light gray", 0xffd3d3d3 },
+ { "light green", 0xff90ee90 },
+ { "light grey", 0xffd3d3d3 },
+ { "light pink", 0xffffb6c1 },
+ { "light salmon", 0xffffa07a },
+ { "light sea green", 0xff20b2aa },
+ { "light sky blue", 0xff87cefa },
+ { "light slate blue", 0xff8470ff },
+ { "light slate gray", 0xff778899 },
+ { "light slate grey", 0xff778899 },
+ { "light steel blue", 0xffb0c4de },
+ { "light yellow", 0xffffffe0 },
+ { "LightBlue", 0xffadd8e6 },
+ { "LightBlue1", 0xffbfefff },
+ { "LightBlue2", 0xffb2dfee },
+ { "LightBlue3", 0xff9ac0cd },
+ { "LightBlue4", 0xff68838b },
+ { "LightCoral", 0xfff08080 },
+ { "LightCyan", 0xffe0ffff },
+ { "LightCyan1", 0xffe0ffff },
+ { "LightCyan2", 0xffd1eeee },
+ { "LightCyan3", 0xffb4cdcd },
+ { "LightCyan4", 0xff7a8b8b },
+ { "LightGoldenrod", 0xffeedd82 },
+ { "LightGoldenrod1", 0xffffec8b },
+ { "LightGoldenrod2", 0xffeedc82 },
+ { "LightGoldenrod3", 0xffcdbe70 },
+ { "LightGoldenrod4", 0xff8b814c },
+ { "LightGoldenrodYellow", 0xfffafad2 },
+ { "LightGray", 0xffd3d3d3 },
+ { "LightGreen", 0xff90ee90 },
+ { "LightGrey", 0xffd3d3d3 },
+ { "LightPink", 0xffffb6c1 },
+ { "LightPink1", 0xffffaeb9 },
+ { "LightPink2", 0xffeea2ad },
+ { "LightPink3", 0xffcd8c95 },
+ { "LightPink4", 0xff8b5f65 },
+ { "LightSalmon", 0xffffa07a },
+ { "LightSalmon1", 0xffffa07a },
+ { "LightSalmon2", 0xffee9572 },
+ { "LightSalmon3", 0xffcd8162 },
+ { "LightSalmon4", 0xff8b5742 },
+ { "LightSeaGreen", 0xff20b2aa },
+ { "LightSkyBlue", 0xff87cefa },
+ { "LightSkyBlue1", 0xffb0e2ff },
+ { "LightSkyBlue2", 0xffa4d3ee },
+ { "LightSkyBlue3", 0xff8db6cd },
+ { "LightSkyBlue4", 0xff607b8b },
+ { "LightSlateBlue", 0xff8470ff },
+ { "LightSlateGray", 0xff778899 },
+ { "LightSlateGrey", 0xff778899 },
+ { "LightSteelBlue", 0xffb0c4de },
+ { "LightSteelBlue1", 0xffcae1ff },
+ { "LightSteelBlue2", 0xffbcd2ee },
+ { "LightSteelBlue3", 0xffa2b5cd },
+ { "LightSteelBlue4", 0xff6e7b8b },
+ { "LightYellow", 0xffffffe0 },
+ { "LightYellow1", 0xffffffe0 },
+ { "LightYellow2", 0xffeeeed1 },
+ { "LightYellow3", 0xffcdcdb4 },
+ { "LightYellow4", 0xff8b8b7a },
+ { "lime green", 0xff32cd32 },
+ { "LimeGreen", 0xff32cd32 },
+ { "linen", 0xfffaf0e6 },
+ { "magenta", 0xffff00ff },
+ { "magenta1", 0xffff00ff },
+ { "magenta2", 0xffee00ee },
+ { "magenta3", 0xffcd00cd },
+ { "magenta4", 0xff8b008b },
+ { "maroon", 0xffb03060 },
+ { "maroon1", 0xffff34b3 },
+ { "maroon2", 0xffee30a7 },
+ { "maroon3", 0xffcd2990 },
+ { "maroon4", 0xff8b1c62 },
+ { "medium aquamarine", 0xff66cdaa },
+ { "medium blue", 0xff0000cd },
+ { "medium orchid", 0xffba55d3 },
+ { "medium purple", 0xff9370db },
+ { "medium sea green", 0xff3cb371 },
+ { "medium slate blue", 0xff7b68ee },
+ { "medium spring green", 0xff00fa9a },
+ { "medium turquoise", 0xff48d1cc },
+ { "medium violet red", 0xffc71585 },
+ { "MediumAquamarine", 0xff66cdaa },
+ { "MediumBlue", 0xff0000cd },
+ { "MediumOrchid", 0xffba55d3 },
+ { "MediumOrchid1", 0xffe066ff },
+ { "MediumOrchid2", 0xffd15fee },
+ { "MediumOrchid3", 0xffb452cd },
+ { "MediumOrchid4", 0xff7a378b },
+ { "MediumPurple", 0xff9370db },
+ { "MediumPurple1", 0xffab82ff },
+ { "MediumPurple2", 0xff9f79ee },
+ { "MediumPurple3", 0xff8968cd },
+ { "MediumPurple4", 0xff5d478b },
+ { "MediumSeaGreen", 0xff3cb371 },
+ { "MediumSlateBlue", 0xff7b68ee },
+ { "MediumSpringGreen", 0xff00fa9a },
+ { "MediumTurquoise", 0xff48d1cc },
+ { "MediumVioletRed", 0xffc71585 },
+ { "midnight blue", 0xff191970 },
+ { "MidnightBlue", 0xff191970 },
+ { "mint cream", 0xfff5fffa },
+ { "MintCream", 0xfff5fffa },
+ { "misty rose", 0xffffe4e1 },
+ { "MistyRose", 0xffffe4e1 },
+ { "MistyRose1", 0xffffe4e1 },
+ { "MistyRose2", 0xffeed5d2 },
+ { "MistyRose3", 0xffcdb7b5 },
+ { "MistyRose4", 0xff8b7d7b },
+ { "moccasin", 0xffffe4b5 },
+ { "navajo white", 0xffffdead },
+ { "NavajoWhite", 0xffffdead },
+ { "NavajoWhite1", 0xffffdead },
+ { "NavajoWhite2", 0xffeecfa1 },
+ { "NavajoWhite3", 0xffcdb38b },
+ { "NavajoWhite4", 0xff8b795e },
+ { "navy", 0xff000080 },
+ { "navy blue", 0xff000080 },
+ { "NavyBlue", 0xff000080 },
+ { "old lace", 0xfffdf5e6 },
+ { "OldLace", 0xfffdf5e6 },
+ { "olive drab", 0xff6b8e23 },
+ { "OliveDrab", 0xff6b8e23 },
+ { "OliveDrab1", 0xffc0ff3e },
+ { "OliveDrab2", 0xffb3ee3a },
+ { "OliveDrab3", 0xff9acd32 },
+ { "OliveDrab4", 0xff698b22 },
+ { "orange", 0xffffa500 },
+ { "orange red", 0xffff4500 },
+ { "orange1", 0xffffa500 },
+ { "orange2", 0xffee9a00 },
+ { "orange3", 0xffcd8500 },
+ { "orange4", 0xff8b5a00 },
+ { "OrangeRed", 0xffff4500 },
+ { "OrangeRed1", 0xffff4500 },
+ { "OrangeRed2", 0xffee4000 },
+ { "OrangeRed3", 0xffcd3700 },
+ { "OrangeRed4", 0xff8b2500 },
+ { "orchid", 0xffda70d6 },
+ { "orchid1", 0xffff83fa },
+ { "orchid2", 0xffee7ae9 },
+ { "orchid3", 0xffcd69c9 },
+ { "orchid4", 0xff8b4789 },
+ { "pale goldenrod", 0xffeee8aa },
+ { "pale green", 0xff98fb98 },
+ { "pale turquoise", 0xffafeeee },
+ { "pale violet red", 0xffdb7093 },
+ { "PaleGoldenrod", 0xffeee8aa },
+ { "PaleGreen", 0xff98fb98 },
+ { "PaleGreen1", 0xff9aff9a },
+ { "PaleGreen2", 0xff90ee90 },
+ { "PaleGreen3", 0xff7ccd7c },
+ { "PaleGreen4", 0xff548b54 },
+ { "PaleTurquoise", 0xffafeeee },
+ { "PaleTurquoise1", 0xffbbffff },
+ { "PaleTurquoise2", 0xffaeeeee },
+ { "PaleTurquoise3", 0xff96cdcd },
+ { "PaleTurquoise4", 0xff668b8b },
+ { "PaleVioletRed", 0xffdb7093 },
+ { "PaleVioletRed1", 0xffff82ab },
+ { "PaleVioletRed2", 0xffee799f },
+ { "PaleVioletRed3", 0xffcd6889 },
+ { "PaleVioletRed4", 0xff8b475d },
+ { "papaya whip", 0xffffefd5 },
+ { "PapayaWhip", 0xffffefd5 },
+ { "peach puff", 0xffffdab9 },
+ { "PeachPuff", 0xffffdab9 },
+ { "PeachPuff1", 0xffffdab9 },
+ { "PeachPuff2", 0xffeecbad },
+ { "PeachPuff3", 0xffcdaf95 },
+ { "PeachPuff4", 0xff8b7765 },
+ { "peru", 0xffcd853f },
+ { "pink", 0xffffc0cb },
+ { "pink1", 0xffffb5c5 },
+ { "pink2", 0xffeea9b8 },
+ { "pink3", 0xffcd919e },
+ { "pink4", 0xff8b636c },
+ { "plum", 0xffdda0dd },
+ { "plum1", 0xffffbbff },
+ { "plum2", 0xffeeaeee },
+ { "plum3", 0xffcd96cd },
+ { "plum4", 0xff8b668b },
+ { "powder blue", 0xffb0e0e6 },
+ { "PowderBlue", 0xffb0e0e6 },
+ { "purple", 0xffa020f0 },
+ { "purple1", 0xff9b30ff },
+ { "purple2", 0xff912cee },
+ { "purple3", 0xff7d26cd },
+ { "purple4", 0xff551a8b },
+ { "red", 0xffff0000 },
+ { "red1", 0xffff0000 },
+ { "red2", 0xffee0000 },
+ { "red3", 0xffcd0000 },
+ { "red4", 0xff8b0000 },
+ { "rosy brown", 0xffbc8f8f },
+ { "RosyBrown", 0xffbc8f8f },
+ { "RosyBrown1", 0xffffc1c1 },
+ { "RosyBrown2", 0xffeeb4b4 },
+ { "RosyBrown3", 0xffcd9b9b },
+ { "RosyBrown4", 0xff8b6969 },
+ { "royal blue", 0xff4169e1 },
+ { "RoyalBlue", 0xff4169e1 },
+ { "RoyalBlue1", 0xff4876ff },
+ { "RoyalBlue2", 0xff436eee },
+ { "RoyalBlue3", 0xff3a5fcd },
+ { "RoyalBlue4", 0xff27408b },
+ { "saddle brown", 0xff8b4513 },
+ { "SaddleBrown", 0xff8b4513 },
+ { "salmon", 0xfffa8072 },
+ { "salmon1", 0xffff8c69 },
+ { "salmon2", 0xffee8262 },
+ { "salmon3", 0xffcd7054 },
+ { "salmon4", 0xff8b4c39 },
+ { "sandy brown", 0xfff4a460 },
+ { "SandyBrown", 0xfff4a460 },
+ { "sea green", 0xff2e8b57 },
+ { "SeaGreen", 0xff2e8b57 },
+ { "SeaGreen1", 0xff54ff9f },
+ { "SeaGreen2", 0xff4eee94 },
+ { "SeaGreen3", 0xff43cd80 },
+ { "SeaGreen4", 0xff2e8b57 },
+ { "seashell", 0xfffff5ee },
+ { "seashell1", 0xfffff5ee },
+ { "seashell2", 0xffeee5de },
+ { "seashell3", 0xffcdc5bf },
+ { "seashell4", 0xff8b8682 },
+ { "sienna", 0xffa0522d },
+ { "sienna1", 0xffff8247 },
+ { "sienna2", 0xffee7942 },
+ { "sienna3", 0xffcd6839 },
+ { "sienna4", 0xff8b4726 },
+ { "sky blue", 0xff87ceeb },
+ { "SkyBlue", 0xff87ceeb },
+ { "SkyBlue1", 0xff87ceff },
+ { "SkyBlue2", 0xff7ec0ee },
+ { "SkyBlue3", 0xff6ca6cd },
+ { "SkyBlue4", 0xff4a708b },
+ { "slate blue", 0xff6a5acd },
+ { "slate gray", 0xff708090 },
+ { "slate grey", 0xff708090 },
+ { "SlateBlue", 0xff6a5acd },
+ { "SlateBlue1", 0xff836fff },
+ { "SlateBlue2", 0xff7a67ee },
+ { "SlateBlue3", 0xff6959cd },
+ { "SlateBlue4", 0xff473c8b },
+ { "SlateGray", 0xff708090 },
+ { "SlateGray1", 0xffc6e2ff },
+ { "SlateGray2", 0xffb9d3ee },
+ { "SlateGray3", 0xff9fb6cd },
+ { "SlateGray4", 0xff6c7b8b },
+ { "SlateGrey", 0xff708090 },
+ { "snow", 0xfffffafa },
+ { "snow1", 0xfffffafa },
+ { "snow2", 0xffeee9e9 },
+ { "snow3", 0xffcdc9c9 },
+ { "snow4", 0xff8b8989 },
+ { "spring green", 0xff00ff7f },
+ { "SpringGreen", 0xff00ff7f },
+ { "SpringGreen1", 0xff00ff7f },
+ { "SpringGreen2", 0xff00ee76 },
+ { "SpringGreen3", 0xff00cd66 },
+ { "SpringGreen4", 0xff008b45 },
+ { "steel blue", 0xff4682b4 },
+ { "SteelBlue", 0xff4682b4 },
+ { "SteelBlue1", 0xff63b8ff },
+ { "SteelBlue2", 0xff5cacee },
+ { "SteelBlue3", 0xff4f94cd },
+ { "SteelBlue4", 0xff36648b },
+ { "tan", 0xffd2b48c },
+ { "tan1", 0xffffa54f },
+ { "tan2", 0xffee9a49 },
+ { "tan3", 0xffcd853f },
+ { "tan4", 0xff8b5a2b },
+ { "thistle", 0xffd8bfd8 },
+ { "thistle1", 0xffffe1ff },
+ { "thistle2", 0xffeed2ee },
+ { "thistle3", 0xffcdb5cd },
+ { "thistle4", 0xff8b7b8b },
+ { "tomato", 0xffff6347 },
+ { "tomato1", 0xffff6347 },
+ { "tomato2", 0xffee5c42 },
+ { "tomato3", 0xffcd4f39 },
+ { "tomato4", 0xff8b3626 },
+ { "turquoise", 0xff40e0d0 },
+ { "turquoise1", 0xff00f5ff },
+ { "turquoise2", 0xff00e5ee },
+ { "turquoise3", 0xff00c5cd },
+ { "turquoise4", 0xff00868b },
+ { "violet", 0xffee82ee },
+ { "violet red", 0xffd02090 },
+ { "VioletRed", 0xffd02090 },
+ { "VioletRed1", 0xffff3e96 },
+ { "VioletRed2", 0xffee3a8c },
+ { "VioletRed3", 0xffcd3278 },
+ { "VioletRed4", 0xff8b2252 },
+ { "wheat", 0xfff5deb3 },
+ { "wheat1", 0xffffe7ba },
+ { "wheat2", 0xffeed8ae },
+ { "wheat3", 0xffcdba96 },
+ { "wheat4", 0xff8b7e66 },
+ { "white", 0xffffffff },
+ { "white smoke", 0xfff5f5f5 },
+ { "WhiteSmoke", 0xfff5f5f5 },
+ { "yellow", 0xffffff00 },
+ { "yellow green", 0xff9acd32 },
+ { "yellow1", 0xffffff00 },
+ { "yellow2", 0xffeeee00 },
+ { "yellow3", 0xffcdcd00 },
+ { "yellow4", 0xff8b8b00 },
+ { "YellowGreen", 0xff9acd32 }
+};
+
+bool wld_lookup_named_color(const char * name, uint32_t * color)
+{
+ char * end;
+ int low = 0, mid, high = ARRAY_LENGTH(named_colors);
+ int r;
+
+ if (name[0] == '#' && name[1] != '\0')
+ {
+ *color = strtoul(name + 1, &end, 16);
+
+ /* Set alpha channel to opaque. */
+ *color |= 0xff << 24;
+
+ if (*end == '\0')
+ return true;
+ }
+
+ while (low <= high)
+ {
+ mid = (low + high) / 2;
+ r = strcasecmp(named_colors[mid].name, name);
+
+ if (r == 0)
+ {
+ *color = named_colors[mid].color;
+ return true;
+ }
+ if (r < 0)
+ low = mid + 1;
+ else
+ high = mid - 1;
+ }
+
+ return false;
+}
+
diff --git a/configure.ac b/configure.ac
@@ -0,0 +1,136 @@
+dnl wld: configure.ac
+
+AC_PREREQ([2.59])
+
+AC_INIT([wld], [0.0.1], [mforney@mforney.org])
+AM_INIT_AUTOMAKE([foreign nostdinc -Wall -Werror])
+AC_LANG([C])
+
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+
+AC_PROG_CC_C99
+AC_USE_SYSTEM_EXTENSIONS
+
+AM_PROG_AR
+LT_INIT
+
+AC_CONFIG_SRCDIR([wld.h])
+AC_CONFIG_MACRO_DIR([m4])
+
+PKG_PROG_PKG_CONFIG([0.9.0])
+
+dnl Options {{{
+# Debugging
+AC_ARG_ENABLE([debug],
+ AS_HELP_STRING([--enable-debug],
+ [Enable debugging messages]),
+ enable_debug=$enableval,
+ enable_debug=no)
+if test "x$enable_debug" = "xyes" ; then
+ AC_DEFINE([ENABLE_DEBUG], [1], [Enable debug messages])
+fi
+
+# Wayland
+AC_ARG_WITH([wayland],
+ AS_HELP_STRING([--without-wayland],
+ [Disable Wayland support]),
+ with_wayland=$withval,
+ with_wayland=yes)
+if test "x$with_wayland" = "xyes" ; then
+ PKG_CHECK_MODULES([wayland_client], [wayland-client],,
+ AC_MSG_ERROR([Wayland client libraries not found. Specify
+ --without-wayland to build without wayland
+ support]))
+ AC_DEFINE([WITH_WAYLAND], [1], [Build Wayland support])
+ PKGCONFIG_EXTRA_REQUIRES="wayland-client $PKGCONFIG_EXTRA_REQUIRES"
+
+fi
+AM_CONDITIONAL([WITH_WAYLAND], test "x$with_wayland" = "xyes")
+
+# Wayland DRM
+AC_ARG_ENABLE([drm],
+ AS_HELP_STRING([--disable-drm],
+ [Disable Wayland DRM support]),
+ enable_drm=$enableval,
+ enable_drm=$with_wayland)
+if test "x$enable_drm" = "xyes" ; then
+ if test "x$with_wayland" != "xyes" ; then
+ AC_MSG_ERROR([--enable-drm requires --with-wayland])
+ fi
+ AC_DEFINE([ENABLE_WAYLAND_DRM], [1], [Enable Wayland DRM support])
+fi
+AM_CONDITIONAL([ENABLE_WAYLAND_DRM], test "x$enable_drm" = "xyes")
+
+# Wayland SHM
+AC_ARG_ENABLE([shm],
+ AS_HELP_STRING([--disable-shm],
+ [Disable Wayland SHM support]),
+ enable_shm=$enableval,
+ enable_shm=$with_wayland)
+if test "x$enable_shm" = "xyes" ; then
+ if test "x$with_wayland" != "xyes" ; then
+ AC_MSG_ERROR([--enable-shm requires --with-wayland])
+ fi
+ AC_DEFINE([ENABLE_WAYLAND_SHM], [1], [Enable Wayland SHM support])
+fi
+AM_CONDITIONAL([ENABLE_WAYLAND_SHM], test "x$enable_shm" = "xyes")
+
+# Intel
+AC_ARG_ENABLE([intel],
+ AS_HELP_STRING([--disable-intel],
+ [Disable Intel drawable support]),
+ enable_intel=$enableval,
+ enable_intel=auto)
+if test "x$enable_intel" = "xyes" -o "x$enable_intel" = "xauto" ; then
+ PKG_CHECK_MODULES([drm_intel], [libdrm_intel], have_drm_intel=yes,
+ if test "x$enable_intel" = "xyes" ; then
+ AC_MSG_ERROR([--enable-intel requires libdrm_intel])
+ fi
+ )
+ PKG_CHECK_MODULES([intelbatch], [intelbatch], have_intelbatch=yes,
+ if test "x$enable_intel" = "xyes" ; then
+ AC_MSG_ERROR([--enable-intel requires libintelbatch])
+ fi
+ )
+
+ if test "x$enable_intel" = "xauto" \
+ -a "x$have_drm_intel" = "xyes" -a "x$have_intelbatch" = "xyes"
+ then
+ enable_intel=yes
+ fi
+
+ if test "x$enable_intel" = "xyes" ; then
+ AC_DEFINE([ENABLE_INTEL], [1], [Enable Intel DRM support])
+ PKGCONFIG_REQUIRES_PRIVATE="libdrm_intel $PKGCONFIG_REQUIRES_PRIVATE"
+ PKGCONFIG_REQUIRES_PRIVATE="intelbatch $PKGCONFIG_REQUIRES_PRIVATE"
+ fi
+fi
+AM_CONDITIONAL([ENABLE_INTEL], test "x$enable_intel" = "xyes")
+
+# Pixman
+AC_ARG_ENABLE([pixman],
+ AS_HELP_STRING([--disable-pixman],
+ [Disable pixman drawable support]),
+ enable_pixman=$enableval,
+ enable_pixman=yes)
+if test "x$enable_pixman" = "xyes" ; then
+ AC_DEFINE([ENABLE_PIXMAN], [1], [Enable Pixman support])
+fi
+AM_CONDITIONAL([ENABLE_PIXMAN], test "x$enable_pixman" = "xyes")
+dnl }}}
+
+dnl Check for libraries {{{
+PKG_CHECK_MODULES([pixman], [pixman-1])
+PKG_CHECK_MODULES([fontconfig], [fontconfig])
+PKG_CHECK_MODULES([freetype], [freetype2])
+dnl }}}
+
+dnl Wayland protocol
+WAYLAND_SCANNER_RULES(['$(top_srcdir)/protocol'])
+
+dnl pkgconfig
+AC_SUBST([PKGCONFIG_REQUIRES_PRIVATE])
+
+AC_CONFIG_FILES([Makefile protocol/Makefile wld.pc])
+AC_OUTPUT
+
diff --git a/drawable.c b/drawable.c
@@ -0,0 +1,78 @@
+/* wld: drawable.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "wld-private.h"
+
+void default_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle)
+{
+ wld_fill_rectangles(drawable, color, rectangle, 1);
+}
+
+void default_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles)
+{
+ while (num_rectangles--)
+ wld_fill_rectangle(drawable, color, &rectangles[num_rectangles]);
+}
+
+void default_flush(struct wld_drawable * drawable)
+{
+}
+
+void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle)
+{
+ drawable->interface->fill_rectangle(drawable, color, rectangle);
+}
+
+void wld_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles)
+{
+ drawable->interface->fill_rectangles(drawable, color, rectangles,
+ num_rectangles);
+}
+
+void wld_draw_text_utf8_n(struct wld_drawable * drawable,
+ struct wld_font * font_base, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length)
+{
+ struct font * font = container_of(font_base, typeof(*font), base);
+
+ drawable->interface->draw_text_utf8(drawable, font, color, x, y,
+ text, length);
+}
+
+void wld_destroy_drawable(struct wld_drawable * drawable)
+{
+ drawable->interface->destroy(drawable);
+}
+
+void wld_flush(struct wld_drawable * drawable)
+{
+ drawable->interface->flush(drawable);
+}
+
diff --git a/drm-private.h b/drm-private.h
@@ -0,0 +1,50 @@
+/* wld: drm-private.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_DRM_PRIVATE_H
+#define WLD_DRM_PRIVATE_H 1
+
+typedef bool (* drm_device_supported_func_t)(uint32_t vendor_id,
+ uint32_t device_id);
+typedef void * (* drm_create_context_func_t)(int drm_fd);
+typedef void (* drm_destroy_context_func_t)(void * context);
+typedef struct wld_drawable * (* drm_create_drawable_func_t)
+ (void * context, uint32_t width, uint32_t height, uint32_t format);
+typedef void (* drm_get_drawable_info_func_t)
+ (struct wld_drawable * drawable, uint32_t * name, uint32_t * pitch);
+
+struct wld_drm_interface
+{
+ drm_device_supported_func_t device_supported;
+ drm_create_context_func_t create_context;
+ drm_destroy_context_func_t destroy_context;
+ drm_create_drawable_func_t create_drawable;
+ drm_get_drawable_info_func_t get_drawable_info;
+};
+
+#if ENABLE_INTEL
+extern const struct wld_drm_interface intel_drm;
+#endif
+
+#endif
+
diff --git a/font.c b/font.c
@@ -0,0 +1,222 @@
+/* wld: font.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "wld-private.h"
+
+#include <fontconfig/fcfreetype.h>
+
+struct wld_font_context * wld_font_create_context()
+{
+ struct wld_font_context * context;
+
+ context = malloc(sizeof *context);
+
+ if (!context)
+ goto error0;
+
+ if (FT_Init_FreeType(&context->library) != 0)
+ {
+ printf("failed to initialize ft library\n");
+
+ goto error1;
+ }
+
+ return context;
+
+ error1:
+ free(context);
+ error0:
+ return NULL;
+}
+
+struct wld_font * wld_font_open_name(struct wld_font_context * context,
+ const char * name)
+{
+ FcPattern * pattern, * match;
+ FcResult result;
+
+ printf("name: %s\n", name);
+
+ pattern = FcNameParse((const FcChar8 *) name);
+ FcConfigSubstitute(NULL, pattern, FcMatchPattern);
+ FcDefaultSubstitute(pattern);
+
+ match = FcFontMatch(NULL, pattern, &result);
+
+ if (!match)
+ return NULL;
+
+ return wld_font_open_pattern(context, match);
+}
+
+struct wld_font * wld_font_open_pattern(struct wld_font_context * context,
+ FcPattern * match)
+{
+ char * filename;
+ struct font * font;
+ FcResult result;
+ double pixel_size, aspect;
+
+ font = malloc(sizeof *font);
+
+ if (!font)
+ goto error0;
+
+ font->context = context;
+
+ result = FcPatternGetString(match, FC_FILE, 0, (FcChar8 **) &filename);
+
+ if (result == FcResultMatch)
+ {
+ FT_Error error;
+
+ DEBUG("Loading font file: %s\n", filename);
+
+ error = FT_New_Face(context->library, filename, 0, &font->face);
+
+ if (error == 0)
+ goto load_face;
+ }
+
+ result = FcPatternGetFTFace(match, FC_FT_FACE, 0, &font->face);
+
+ if (result != FcResultMatch)
+ {
+ DEBUG("Couldn't determine font filename or FreeType face\n");
+ goto error1;
+ }
+
+ load_face:
+ result = FcPatternGetDouble(match, FC_PIXEL_SIZE, 0, &pixel_size);
+
+ result = FcPatternGetDouble(match, FC_ASPECT, 0, &aspect);
+
+ if (result == FcResultNoMatch)
+ aspect = 1.0;
+
+ if (font->face->face_flags & FT_FACE_FLAG_SCALABLE)
+ {
+ FT_F26Dot6 width, height;
+
+ width = ((unsigned int) pixel_size) << 6;
+ height = ((unsigned int) (pixel_size * aspect)) << 6;
+
+ FT_Set_Char_Size(font->face, width, height, 0, 0);
+ }
+ else
+ {
+ FT_Set_Pixel_Sizes(font->face, (unsigned int) pixel_size,
+ (unsigned int) (pixel_size * aspect));
+ }
+
+ font->base.ascent = font->face->size->metrics.ascender >> 6;
+ font->base.descent = -font->face->size->metrics.descender >> 6;
+ font->base.height = font->base.ascent + font->base.descent;
+ font->base.max_advance = font->face->size->metrics.max_advance >> 6;
+
+ font->glyphs = calloc(font->face->num_glyphs, sizeof(struct glyph *));
+
+ return &font->base;
+
+ error1:
+ free(font);
+ error0:
+ return NULL;
+}
+
+void wld_font_close(struct wld_font * font_base)
+{
+ struct font * font = container_of(font_base, typeof(*font), base);
+
+ FT_Done_Face(font->face);
+ free(font);
+}
+
+bool font_ensure_glyph(struct font * font, FT_UInt glyph_index)
+{
+ if (glyph_index)
+ {
+ if (!font->glyphs[glyph_index])
+ {
+ struct glyph * glyph;
+
+ glyph = malloc(sizeof *glyph);
+
+ if (!glyph)
+ return false;
+
+ FT_Load_Glyph(font->face, glyph_index, FT_LOAD_RENDER
+ | FT_LOAD_MONOCHROME | FT_LOAD_TARGET_MONO);
+
+ FT_Bitmap_New(&glyph->bitmap);
+
+ FT_Bitmap_Copy(font->context->library,
+ &font->face->glyph->bitmap, &glyph->bitmap);
+
+ glyph->advance = font->face->glyph->metrics.horiAdvance >> 6;
+ glyph->x = font->face->glyph->bitmap_left;
+ glyph->y = -font->face->glyph->bitmap_top;
+
+ font->glyphs[glyph_index] = glyph;
+ }
+
+ return true;
+ }
+
+ return false;
+}
+
+bool wld_font_ensure_char(struct wld_font * font_base, uint32_t character)
+{
+ struct font * font = container_of(font_base, typeof(*font), base);
+ FT_UInt glyph_index;
+
+ glyph_index = FT_Get_Char_Index(font->face, character);
+
+ return font_ensure_glyph(font, glyph_index);
+}
+
+void wld_font_text_extents_utf8_n(struct wld_font * font_base,
+ const char * text, int32_t length,
+ struct wld_extents * extents)
+{
+ struct font * font = container_of(font_base, typeof(*font), base);
+ int ret;
+ uint32_t c;
+ FT_UInt glyph_index;
+
+ extents->advance = 0;
+
+ while ((ret = FcUtf8ToUcs4((FcChar8 *) text, &c, length) > 0))
+ {
+ length -= ret;
+ text += ret;
+ glyph_index = FT_Get_Char_Index(font->face, c);
+
+ if (!font_ensure_glyph(font, glyph_index))
+ continue;
+
+ extents->advance += font->glyphs[glyph_index]->advance;
+ }
+}
+
diff --git a/intel.c b/intel.c
@@ -0,0 +1,226 @@
+/* wld: intel.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "intel.h"
+#include "drm-private.h"
+#include "wld-private.h"
+
+#include <intelbatch/batch.h>
+#include <intelbatch/blt.h>
+#include <intelbatch/mi.h>
+#include <intel_bufmgr.h>
+#include <i915_drm.h>
+
+struct wld_intel_context
+{
+ drm_intel_bufmgr * bufmgr;
+ struct intel_batch batch;
+};
+
+struct intel_drawable
+{
+ struct wld_drawable base;
+
+ struct wld_intel_context * context;
+ uint32_t name;
+ unsigned long pitch;
+
+ drm_intel_bo * bo;
+};
+
+static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle);
+static void intel_draw_text_utf8(struct wld_drawable * drawable,
+ struct font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length);
+static void intel_flush(struct wld_drawable * drawable);
+static void intel_destroy(struct wld_drawable * drawable);
+
+const static struct wld_draw_interface intel_draw = {
+ .fill_rectangle = &intel_fill_rectangle,
+ .fill_rectangles = &default_fill_rectangles,
+ .draw_text_utf8 = &intel_draw_text_utf8,
+ .flush = &intel_flush,
+ .destroy = &intel_destroy
+};
+
+const struct wld_drm_interface intel_drm = {
+ .device_supported = &wld_intel_device_supported,
+ .create_context = (drm_create_context_func_t) &wld_intel_create_context,
+ .destroy_context = (drm_destroy_context_func_t) &wld_intel_destroy_context,
+ .create_drawable = (drm_create_drawable_func_t) &wld_intel_create_drawable,
+ .get_drawable_info = &wld_intel_get_drawable_info
+};
+
+bool wld_intel_device_supported(uint32_t vendor_id, uint32_t device_id)
+{
+ return vendor_id == 0x8086;
+}
+
+struct wld_intel_context * wld_intel_create_context(int drm_fd)
+{
+ struct wld_intel_context * context;
+
+ context = malloc(sizeof *context);
+
+ if (!context)
+ return NULL;
+
+ context->bufmgr = drm_intel_bufmgr_gem_init(drm_fd, INTEL_BATCH_SIZE);
+ intel_batch_initialize(&context->batch, context->bufmgr);
+
+ return context;
+}
+
+void wld_intel_destroy_context(struct wld_intel_context * context)
+{
+ drm_intel_bufmgr_destroy(context->bufmgr);
+ free(context);
+}
+
+struct wld_drawable * wld_intel_create_drawable
+ (struct wld_intel_context * context, uint32_t width, uint32_t height,
+ uint32_t format)
+{
+ struct intel_drawable * intel;
+ uint32_t tiling_mode = I915_TILING_X, pitch;
+
+ intel = malloc(sizeof *intel);
+
+ if (!intel)
+ return NULL;
+
+ intel->base.interface = &intel_draw;
+ intel->base.width = width;
+ intel->base.height = height;
+
+ intel->context = context;
+ intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable",
+ width, height, 4,
+ &tiling_mode, &intel->pitch, 0);
+
+ drm_intel_bo_flink(intel->bo, &intel->name);
+
+ return &intel->base;
+}
+
+void wld_intel_get_drawable_info(struct wld_drawable * drawable,
+ uint32_t * name, uint32_t * pitch)
+{
+ struct intel_drawable * intel;
+
+ intel = container_of(drawable, typeof(*intel), base);
+ *name = intel->name;
+ *pitch = intel->pitch;
+}
+
+void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle)
+{
+ struct intel_drawable * intel;
+
+ intel = container_of(drawable, typeof(*intel), base);
+ xy_color_blt(&intel->context->batch, intel->bo, intel->pitch,
+ rectangle->x, rectangle->y,
+ rectangle->x + rectangle->width,
+ rectangle->y + rectangle->height, color);
+}
+
+void intel_draw_text_utf8(struct wld_drawable * drawable,
+ struct font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length)
+{
+ struct intel_drawable * intel;
+ int ret;
+ struct glyph * glyph;
+ uint32_t row;
+ FT_UInt glyph_index;
+ uint32_t c;
+ uint8_t immediate[512];
+ uint8_t * byte;
+ uint8_t byte_index;
+
+ intel = container_of(drawable, typeof(*intel), base);
+
+ /* For some reason the text doesn't render if we don't flush the command
+ * buffer first. */
+ intel_batch_flush(&intel->context->batch);
+
+ xy_setup_blt(&intel->context->batch, true, INTEL_BLT_RASTER_OPERATION_SRC,
+ 0, color, intel->bo, intel->pitch);
+
+ while ((ret = FcUtf8ToUcs4((FcChar8 *) text, &c, length)) > 0 && c != '\0')
+ {
+ text += ret;
+ length -= ret;
+ glyph_index = FT_Get_Char_Index(font->face, c);
+
+ if (!font_ensure_glyph(font, glyph_index))
+ continue;
+
+ glyph = font->glyphs[glyph_index];
+
+ if (glyph->bitmap.width == 0 || glyph->bitmap.rows == 0)
+ goto advance;
+
+ byte = immediate;
+
+ /* XY_TEXT_IMMEDIATE requires a pitch with no extra bytes */
+ for (row = 0; row < glyph->bitmap.rows; ++row)
+ {
+ memcpy(byte, glyph->bitmap.buffer + (row * glyph->bitmap.pitch),
+ (glyph->bitmap.width + 7) / 8);
+ byte += (glyph->bitmap.width + 7) / 8;
+ }
+
+ xy_text_immediate_blt(&intel->context->batch, intel->bo,
+ x + glyph->x, y + glyph->y,
+ x + glyph->x + glyph->bitmap.width,
+ y + glyph->y + glyph->bitmap.rows,
+ (byte - immediate + 3) / 4,
+ (uint32_t *) immediate);
+
+ advance:
+ x += glyph->advance;
+ }
+}
+
+void intel_flush(struct wld_drawable * drawable)
+{
+ struct intel_drawable * intel;
+
+ intel = container_of(drawable, typeof(*intel), base);
+ intel_batch_flush(&intel->context->batch);
+}
+
+void intel_destroy(struct wld_drawable * drawable)
+{
+ struct intel_drawable * intel;
+
+ intel = container_of(drawable, typeof(*intel), base);
+ drm_intel_bo_unreference(intel->bo);
+ free(intel);
+}
+
diff --git a/intel.h b/intel.h
@@ -0,0 +1,65 @@
+/* wld: intel.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_INTEL_H
+#define WLD_INTEL_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct wld_intel_context;
+struct wld_drawable;
+enum wld_format;
+
+/**
+ * Create a new drawing context which uses Intel Graphics hardware accelerated
+ * operations.
+ */
+struct wld_intel_context * wld_intel_create_context(int drm_fd);
+
+/**
+ * Destroy an Intel context
+ */
+void wld_intel_destroy_context(struct wld_intel_context * context);
+
+/**
+ * Check if the device with the given vendor and device ID is supported by the
+ * Intel drawing backend.
+ */
+bool wld_intel_device_supported(uint32_t vendor_id, uint32_t device_id);
+
+/**
+ * Create a new Intel drawable with the specified dimensions.
+ */
+struct wld_drawable * wld_intel_create_drawable
+ (struct wld_intel_context * context, uint32_t width, uint32_t height,
+ enum wld_format format);
+
+/**
+ * Get the name and pitch of the underlying BO for this Intel drawable.
+ */
+void wld_intel_get_drawable_info(struct wld_drawable * drawable,
+ uint32_t * name, uint32_t * pitch);
+
+#endif
+
diff --git a/pixman.c b/pixman.c
@@ -0,0 +1,248 @@
+/* wld: pixman.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "pixman.h"
+#include "wld-private.h"
+
+#define PIXMAN_COLOR(c) { \
+ .alpha = ((c >> 24) & 0xff) * 0x101, \
+ .red = ((c >> 16) & 0xff) * 0x101, \
+ .green = ((c >> 8) & 0xff) * 0x101, \
+ .blue = ((c >> 0) & 0xff) * 0x101, \
+}
+
+struct wld_pixman_context
+{
+ pixman_glyph_cache_t * glyph_cache;
+};
+
+struct pixman_drawable
+{
+ struct wld_drawable base;
+ pixman_image_t * image;
+ struct wld_pixman_context * context;
+};
+
+static void pixman_fill_rectangles(struct wld_drawable * drawable,
+ uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles);
+static void pixman_draw_text_utf8(struct wld_drawable * drawable,
+ struct font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length);
+static void pixman_destroy(struct wld_drawable * drawable);
+
+const static struct wld_draw_interface pixman_draw = {
+ .fill_rectangle = &default_fill_rectangle,
+ .fill_rectangles = &pixman_fill_rectangles,
+ .draw_text_utf8 = &pixman_draw_text_utf8,
+ .flush = &default_flush,
+ .destroy = &pixman_destroy
+};
+
+static inline pixman_format_code_t pixman_format(uint32_t format)
+{
+ switch (format)
+ {
+ case WLD_FORMAT_ARGB8888:
+ return PIXMAN_a8r8g8b8;
+ case WLD_FORMAT_XRGB8888:
+ return PIXMAN_x8r8g8b8;
+ default:
+ return 0;
+ }
+}
+
+struct wld_pixman_context * wld_pixman_create_context()
+{
+ struct wld_pixman_context * context;
+
+ context = malloc(sizeof *context);
+
+ if (!context)
+ return NULL;
+
+ context->glyph_cache = pixman_glyph_cache_create();
+
+ return context;
+}
+
+void wld_pixman_destroy_context(struct wld_pixman_context * context)
+{
+ pixman_glyph_cache_destroy(context->glyph_cache);
+ free(context);
+}
+
+struct wld_drawable * wld_pixman_create_drawable
+ (struct wld_pixman_context * context, uint32_t width, uint32_t height,
+ void * data, uint32_t pitch, enum wld_format format)
+{
+ struct pixman_drawable * pixman;
+
+ pixman = malloc(sizeof *pixman);
+
+ if (!pixman)
+ goto error0;
+
+ pixman->base.interface = &pixman_draw;
+ pixman->base.width = width;
+ pixman->base.height = height;
+
+ pixman->context = context;
+ pixman->image = pixman_image_create_bits(pixman_format(format),
+ width, height,
+ (uint32_t *) data, pitch);
+
+ if (!pixman->image)
+ goto error1;
+
+ return &pixman->base;
+
+ error1:
+ free(pixman);
+ error0:
+ return NULL;
+}
+
+static void pixman_fill_rectangles(struct wld_drawable * drawable,
+ uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles)
+{
+ struct pixman_drawable * pixman;
+ pixman_color_t pixman_color = PIXMAN_COLOR(color);
+
+ pixman = container_of(drawable, typeof(*pixman), base);
+ pixman_image_fill_rectangles(PIXMAN_OP_SRC, pixman->image, &pixman_color,
+ num_rectangles, rectangles);
+}
+
+static inline uint8_t reverse(uint8_t byte)
+{
+ byte = ((byte << 1) & 0xaa) | ((byte >> 1) & 0x55);
+ byte = ((byte << 2) & 0xcc) | ((byte >> 2) & 0x33);
+ byte = ((byte << 4) & 0xf0) | ((byte >> 4) & 0x0f);
+
+ return byte;
+}
+
+static void pixman_draw_text_utf8(struct wld_drawable * drawable,
+ struct font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length)
+{
+ struct pixman_drawable * pixman;
+ int ret;
+ uint32_t c;
+ struct glyph * glyph;
+ FT_UInt glyph_index;
+ pixman_glyph_t glyphs[strlen(text)];
+ uint32_t index = 0, glyph_x = 0;
+ pixman_color_t pixman_color = PIXMAN_COLOR(color);
+ pixman_image_t * solid;
+
+ pixman = container_of(drawable, typeof(*pixman), base);
+ solid = pixman_image_create_solid_fill(&pixman_color);
+
+ while ((ret = FcUtf8ToUcs4((FcChar8 *) text, &c, length)) > 0 && c != '\0')
+ {
+ text += ret;
+ length -= ret;
+ glyph_index = FT_Get_Char_Index(font->face, c);
+
+ if (!font_ensure_glyph(font, glyph_index))
+ continue;
+
+ glyph = font->glyphs[glyph_index];
+
+ glyphs[index].x = glyph_x;
+ glyphs[index].y = 0;
+ glyphs[index].glyph = pixman_glyph_cache_lookup
+ (pixman->context->glyph_cache, font, glyph);
+
+ /* If we don't have the glyph in our cache, do some conversions to make
+ * pixman happy, and then insert it. */
+ if (!glyphs[index].glyph)
+ {
+ uint8_t * src, * dst;
+ uint32_t row, byte_index, bytes_per_row, pitch;
+ pixman_image_t * image;
+ FT_Bitmap * bitmap;
+
+ bitmap = &glyph->bitmap;
+ image = pixman_image_create_bits
+ (PIXMAN_a1, bitmap->width, bitmap->rows, NULL, bitmap->pitch);
+
+ if (!image)
+ goto advance;
+
+ pitch = pixman_image_get_stride(image);
+ bytes_per_row = (bitmap->width + 7) / 8;
+ src = bitmap->buffer;
+ dst = (uint8_t *) pixman_image_get_data(image);
+
+ for (row = 0; row < bitmap->rows; ++row)
+ {
+ /* Pixman's A1 format expects the bits in the opposite order
+ * that Freetype gives us. Sigh... */
+ for (byte_index = 0; byte_index < bytes_per_row; ++byte_index)
+ dst[byte_index] = reverse(src[byte_index]);
+
+ dst += pitch;
+ src += bitmap->pitch;
+ }
+
+ /* Insert the glyph into the cache. */
+ pixman_glyph_cache_freeze(pixman->context->glyph_cache);
+ glyphs[index].glyph = pixman_glyph_cache_insert
+ (pixman->context->glyph_cache, font, glyph,
+ -glyph->x, -glyph->y, image);
+ pixman_glyph_cache_thaw(pixman->context->glyph_cache);
+
+ /* The glyph cache copies the contents of the glyph bitmap. */
+ pixman_image_unref(image);
+ }
+
+ ++index;
+
+ advance:
+ glyph_x += glyph->advance;
+ }
+
+ pixman_composite_glyphs_no_mask(PIXMAN_OP_OVER, solid, pixman->image, 0, 0,
+ x, y, pixman->context->glyph_cache,
+ index, glyphs);
+
+ pixman_image_unref(solid);
+}
+
+void pixman_destroy(struct wld_drawable * drawable)
+{
+ struct pixman_drawable * pixman;
+
+ pixman = container_of(drawable, typeof(*pixman), base);
+ pixman_image_unref(pixman->image);
+ free(pixman);
+}
+
diff --git a/pixman.h b/pixman.h
@@ -0,0 +1,54 @@
+/* wld: pixman.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_PIXMAN_H
+#define WLD_PIXMAN_H 1
+
+#include <stdint.h>
+
+struct wld_pixman_context;
+struct wld_drawable;
+enum wld_format;
+
+/**
+ * Create a new drawing context which uses Pixman to do software rendering on
+ * buffers in memory.
+ */
+struct wld_pixman_context * wld_pixman_create_context();
+
+/**
+ * Destroy a Pixman context.
+ */
+void wld_pixman_destroy_context(struct wld_pixman_context * context);
+
+/**
+ * Create a new Pixman drawable with the specified dimensions.
+ *
+ * If data is NULL, new backing memory will be allocated.
+ */
+struct wld_drawable * wld_pixman_create_drawable
+ (struct wld_pixman_context * context, uint32_t width, uint32_t height,
+ void * data, uint32_t pitch, enum wld_format format);
+
+#endif
+
diff --git a/protocol/Makefile.am b/protocol/Makefile.am
@@ -0,0 +1,7 @@
+# wld: protocol/Makefile.am
+
+BUILT_SOURCES = wayland-drm-protocol.c wayland-drm-client-protocol.h
+CLEANFILES = $(BUILT_SOURCES)
+
+@wayland_scanner_rules@
+
diff --git a/protocol/wayland-drm.xml b/protocol/wayland-drm.xml
@@ -0,0 +1,182 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<protocol name="drm">
+
+ <copyright>
+ Copyright © 2008-2011 Kristian Høgsberg
+ Copyright © 2010-2011 Intel Corporation
+
+ Permission to use, copy, modify, distribute, and sell this
+ software and its documentation for any purpose is hereby granted
+ without fee, provided that\n the above copyright notice appear in
+ all copies and that both that copyright notice and this permission
+ notice appear in supporting documentation, and that the name of
+ the copyright holders not be used in advertising or publicity
+ pertaining to distribution of the software without specific,
+ written prior permission. The copyright holders make no
+ representations about the suitability of this software for any
+ purpose. It is provided "as is" without express or implied
+ warranty.
+
+ THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ THIS SOFTWARE.
+ </copyright>
+
+ <!-- drm support. This object is created by the server and published
+ using the display's global event. -->
+ <interface name="wl_drm" version="2">
+ <enum name="error">
+ <entry name="authenticate_fail" value="0"/>
+ <entry name="invalid_format" value="1"/>
+ <entry name="invalid_name" value="2"/>
+ </enum>
+
+ <enum name="format">
+ <!-- The drm format codes match the #defines in drm_fourcc.h.
+ The formats actually supported by the compositor will be
+ reported by the format event. -->
+ <entry name="c8" value="0x20203843"/>
+ <entry name="rgb332" value="0x38424752"/>
+ <entry name="bgr233" value="0x38524742"/>
+ <entry name="xrgb4444" value="0x32315258"/>
+ <entry name="xbgr4444" value="0x32314258"/>
+ <entry name="rgbx4444" value="0x32315852"/>
+ <entry name="bgrx4444" value="0x32315842"/>
+ <entry name="argb4444" value="0x32315241"/>
+ <entry name="abgr4444" value="0x32314241"/>
+ <entry name="rgba4444" value="0x32314152"/>
+ <entry name="bgra4444" value="0x32314142"/>
+ <entry name="xrgb1555" value="0x35315258"/>
+ <entry name="xbgr1555" value="0x35314258"/>
+ <entry name="rgbx5551" value="0x35315852"/>
+ <entry name="bgrx5551" value="0x35315842"/>
+ <entry name="argb1555" value="0x35315241"/>
+ <entry name="abgr1555" value="0x35314241"/>
+ <entry name="rgba5551" value="0x35314152"/>
+ <entry name="bgra5551" value="0x35314142"/>
+ <entry name="rgb565" value="0x36314752"/>
+ <entry name="bgr565" value="0x36314742"/>
+ <entry name="rgb888" value="0x34324752"/>
+ <entry name="bgr888" value="0x34324742"/>
+ <entry name="xrgb8888" value="0x34325258"/>
+ <entry name="xbgr8888" value="0x34324258"/>
+ <entry name="rgbx8888" value="0x34325852"/>
+ <entry name="bgrx8888" value="0x34325842"/>
+ <entry name="argb8888" value="0x34325241"/>
+ <entry name="abgr8888" value="0x34324241"/>
+ <entry name="rgba8888" value="0x34324152"/>
+ <entry name="bgra8888" value="0x34324142"/>
+ <entry name="xrgb2101010" value="0x30335258"/>
+ <entry name="xbgr2101010" value="0x30334258"/>
+ <entry name="rgbx1010102" value="0x30335852"/>
+ <entry name="bgrx1010102" value="0x30335842"/>
+ <entry name="argb2101010" value="0x30335241"/>
+ <entry name="abgr2101010" value="0x30334241"/>
+ <entry name="rgba1010102" value="0x30334152"/>
+ <entry name="bgra1010102" value="0x30334142"/>
+ <entry name="yuyv" value="0x56595559"/>
+ <entry name="yvyu" value="0x55595659"/>
+ <entry name="uyvy" value="0x59565955"/>
+ <entry name="vyuy" value="0x59555956"/>
+ <entry name="ayuv" value="0x56555941"/>
+ <entry name="nv12" value="0x3231564e"/>
+ <entry name="nv21" value="0x3132564e"/>
+ <entry name="nv16" value="0x3631564e"/>
+ <entry name="nv61" value="0x3136564e"/>
+ <entry name="yuv410" value="0x39565559"/>
+ <entry name="yvu410" value="0x39555659"/>
+ <entry name="yuv411" value="0x31315559"/>
+ <entry name="yvu411" value="0x31315659"/>
+ <entry name="yuv420" value="0x32315559"/>
+ <entry name="yvu420" value="0x32315659"/>
+ <entry name="yuv422" value="0x36315559"/>
+ <entry name="yvu422" value="0x36315659"/>
+ <entry name="yuv444" value="0x34325559"/>
+ <entry name="yvu444" value="0x34325659"/>
+ </enum>
+
+ <!-- Call this request with the magic received from drmGetMagic().
+ It will be passed on to the drmAuthMagic() or
+ DRIAuthConnection() call. This authentication must be
+ completed before create_buffer could be used. -->
+ <request name="authenticate">
+ <arg name="id" type="uint"/>
+ </request>
+
+ <!-- Create a wayland buffer for the named DRM buffer. The DRM
+ surface must have a name using the flink ioctl -->
+ <request name="create_buffer">
+ <arg name="id" type="new_id" interface="wl_buffer"/>
+ <arg name="name" type="uint"/>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ <arg name="stride" type="uint"/>
+ <arg name="format" type="uint"/>
+ </request>
+
+ <!-- Create a wayland buffer for the named DRM buffer. The DRM
+ surface must have a name using the flink ioctl -->
+ <request name="create_planar_buffer">
+ <arg name="id" type="new_id" interface="wl_buffer"/>
+ <arg name="name" type="uint"/>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ <arg name="format" type="uint"/>
+ <arg name="offset0" type="int"/>
+ <arg name="stride0" type="int"/>
+ <arg name="offset1" type="int"/>
+ <arg name="stride1" type="int"/>
+ <arg name="offset2" type="int"/>
+ <arg name="stride2" type="int"/>
+ </request>
+
+ <!-- Create a wayland buffer for the prime fd. Use for regular and planar
+ buffers. Pass 0 for offset and stride for unused planes. -->
+ <request name="create_prime_buffer" since="2">
+ <arg name="id" type="new_id" interface="wl_buffer"/>
+ <arg name="name" type="fd"/>
+ <arg name="width" type="int"/>
+ <arg name="height" type="int"/>
+ <arg name="format" type="uint"/>
+ <arg name="offset0" type="int"/>
+ <arg name="stride0" type="int"/>
+ <arg name="offset1" type="int"/>
+ <arg name="stride1" type="int"/>
+ <arg name="offset2" type="int"/>
+ <arg name="stride2" type="int"/>
+ </request>
+
+ <!-- Notification of the path of the drm device which is used by
+ the server. The client should use this device for creating
+ local buffers. Only buffers created from this device should
+ be be passed to the server using this drm object's
+ create_buffer request. -->
+ <event name="device">
+ <arg name="name" type="string"/>
+ </event>
+
+ <event name="format">
+ <arg name="format" type="uint"/>
+ </event>
+
+ <!-- Raised if the authenticate request succeeded -->
+ <event name="authenticated"/>
+
+ <enum name="capability" since="2">
+ <description summary="wl_drm capability bitmask">
+ Bitmask of capabilities.
+ </description>
+ <entry name="prime" value="1" summary="wl_drm prime available"/>
+ </enum>
+
+ <event name="capabilities">
+ <arg name="value" type="uint"/>
+ </event>
+ </interface>
+
+</protocol>
diff --git a/wayland-drm.c b/wayland-drm.c
@@ -0,0 +1,312 @@
+/* wld: wayland-drm.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "wayland-drm.h"
+#include "wayland-drm-client-protocol.h"
+#include "wayland.h"
+#include "wayland-private.h"
+#include "wld-private.h"
+#include "drm-private.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <xf86drm.h>
+
+#include <stdio.h>
+
+struct wld_drm_context
+{
+ struct wl_drm * wl;
+ struct wl_registry * registry;
+ struct wl_event_queue * queue;
+ struct wl_array formats;
+ int fd;
+ bool authenticated;
+
+ const struct wld_drm_interface * interface;
+ void * context;
+};
+
+static void registry_global(void * data, struct wl_registry * registry,
+ uint32_t name, const char * interface,
+ uint32_t version);
+
+static void drm_device(void * data, struct wl_drm * wl, const char * name);
+static void drm_format(void * data, struct wl_drm * wl, uint32_t format);
+static void drm_authenticated(void * data, struct wl_drm * wl);
+
+const struct wld_wayland_interface wayland_drm_interface = {
+ .create_context = (wayland_create_context_func_t) &wld_drm_create_context,
+ .destroy_context
+ = (wayland_destroy_context_func_t) &wld_drm_destroy_context,
+ .create_drawable = (wayland_create_drawable_func_t) &wld_drm_create_drawable
+};
+
+const static struct wl_registry_listener registry_listener = {
+ .global = ®istry_global
+};
+
+const static struct wl_drm_listener drm_listener = {
+ .device = &drm_device,
+ .format = &drm_format,
+ .authenticated = &drm_authenticated
+};
+
+const static struct wld_drm_interface * drm_interfaces[] = {
+#if ENABLE_INTEL
+ &intel_drm
+#endif
+};
+
+static const struct wld_drm_interface * find_drm_interface(int fd)
+{
+ char path[64], id[32];
+ uint32_t vendor_id, device_id;
+ char * path_part;
+ struct stat st;
+ FILE * file;
+ uint32_t index;
+
+ if (fstat(fd, &st) == -1)
+ return NULL;
+
+ snprintf(path, sizeof path, "/sys/dev/char/%u:%u/",
+ major(st.st_rdev), minor(st.st_rdev));
+ path_part = path + strlen(path);
+
+ strcpy(path_part, "device/vendor");
+ puts(path);
+ file = fopen(path, "r");
+ fgets(id, sizeof id, file);
+ fclose(file);
+ vendor_id = strtoul(id, NULL, 0);
+
+ strcpy(path_part, "device/device");
+ puts(path);
+ file = fopen(path, "r");
+ fgets(id, sizeof id, file);
+ fclose(file);
+ device_id = strtoul(id, NULL, 0);
+
+ for (index = 0; index < ARRAY_LENGTH(drm_interfaces); ++index)
+ {
+ if (drm_interfaces[index]->device_supported(vendor_id, device_id))
+ return drm_interfaces[index];
+ }
+
+ return NULL;
+}
+
+struct wld_drm_context * wld_drm_create_context(struct wl_display * display)
+{
+ struct wld_drm_context * drm;
+
+ drm = malloc(sizeof *drm);
+
+ if (!drm)
+ return 0;
+
+ drm->wl = NULL;
+ drm->fd = -1;
+ wl_array_init(&drm->formats);
+
+ drm->queue = wl_display_create_queue(display);
+
+ if (!drm->queue)
+ goto error2;
+
+ drm->registry = wl_display_get_registry(display);
+
+ if (!drm->registry)
+ goto error3;
+
+ wl_registry_add_listener(drm->registry, ®istry_listener, drm);
+ wl_proxy_set_queue((struct wl_proxy *) drm->registry, drm->queue);
+
+ /* Wait for wl_drm global. */
+ wayland_roundtrip(display, drm->queue);
+
+ if (!drm->wl)
+ {
+ DEBUG("No wl_drm global\n");
+ goto error3;
+ }
+
+ wl_drm_add_listener(drm->wl, &drm_listener, drm);
+
+ /* Wait for DRM device. */
+ wayland_roundtrip(display, drm->queue);
+
+ if (drm->fd == -1)
+ {
+ DEBUG("No DRM device\n");
+ goto error4;
+ }
+
+ /* Wait for DRM authentication. */
+ wayland_roundtrip(display, drm->queue);
+
+ if (!drm->authenticated)
+ {
+ DEBUG("DRM authentication failed\n");
+ goto error5;
+ }
+
+ drm->interface = find_drm_interface(drm->fd);
+
+ if (!drm->interface)
+ {
+ DEBUG("Couldn't find drawable implementation for DRM device\n");
+ goto error5;
+ }
+
+ drm->context = drm->interface->create_context(drm->fd);
+
+ if (!drm->context)
+ {
+ DEBUG("Couldn't create context for DRM drawable implementation\n");
+ goto error5;
+ }
+
+ return drm;
+
+ error5:
+ close(drm->fd);
+ error4:
+ wl_drm_destroy(drm->wl);
+ error3:
+ wl_registry_destroy(drm->registry);
+ error2:
+ wl_event_queue_destroy(drm->queue);
+ error1:
+ wl_array_release(&drm->formats);
+ free(drm);
+ error0:
+ return NULL;
+}
+
+void wld_drm_destroy_context(struct wld_drm_context * drm)
+{
+ drm->interface->destroy_context(drm->context);
+ close(drm->fd);
+ wl_drm_destroy(drm->wl);
+ wl_registry_destroy(drm->registry);
+ wl_event_queue_destroy(drm->queue);
+ wl_array_release(&drm->formats);
+
+ free(drm);
+}
+
+bool wld_drm_has_format(struct wld_drm_context * drm, uint32_t format)
+{
+ uint32_t * supported_format;
+
+ wl_array_for_each(supported_format, &drm->formats)
+ {
+ if (*supported_format == format)
+ return true;
+ }
+
+ return false;
+}
+
+int wld_drm_get_fd(struct wld_drm_context * drm)
+{
+ return drm->authenticated ? drm->fd : -1;
+}
+
+struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm,
+ struct wl_surface * surface,
+ uint32_t width, uint32_t height,
+ uint32_t format)
+{
+ struct wld_drawable * drawable0, * drawable1;
+ uint32_t name0, name1, pitch0, pitch1;
+ struct wl_buffer * buffer0, * buffer1;
+
+ if (!wld_drm_has_format(drm, format))
+ return NULL;
+
+ drawable0 = drm->interface->create_drawable(drm->context, width, height,
+ format);
+ drawable1 = drm->interface->create_drawable(drm->context, width, height,
+ format);
+
+ drm->interface->get_drawable_info(drawable0, &name0, &pitch0);
+ drm->interface->get_drawable_info(drawable1, &name1, &pitch1);
+
+ buffer0 = wl_drm_create_buffer(drm->wl, name0, width, height,
+ pitch0, format);
+ buffer1 = wl_drm_create_buffer(drm->wl, name1, width, height,
+ pitch1, format);
+
+ return wld_wayland_create_drawable_from_buffers(surface,
+ buffer0, drawable0,
+ buffer1, drawable1);
+}
+
+void registry_global(void * data, struct wl_registry * registry, uint32_t name,
+ const char * interface, uint32_t version)
+{
+ struct wld_drm_context * drm = data;
+
+ if (strcmp(interface, "wl_drm") == 0)
+ {
+ drm->wl = wl_registry_bind(registry, name, &wl_drm_interface, 1);
+ wl_proxy_set_queue((struct wl_proxy *) drm->wl, drm->queue);
+ }
+}
+
+void drm_device(void * data, struct wl_drm * wl, const char * name)
+{
+ struct wld_drm_context * drm = data;
+ drm_magic_t magic;
+
+ drm->fd = open(name, O_RDWR);
+
+ if (drm->fd == -1)
+ {
+ DEBUG("Couldn't open DRM device '%s'\n", name);
+ return;
+ }
+
+ drmGetMagic(drm->fd, &magic);
+ wl_drm_authenticate(wl, magic);
+}
+
+void drm_format(void * data, struct wl_drm * wl, uint32_t format)
+{
+ struct wld_drm_context * drm = data;
+
+ *((uint32_t *) wl_array_add(&drm->formats, sizeof format)) = format;
+}
+
+void drm_authenticated(void * data, struct wl_drm * wl)
+{
+ struct wld_drm_context * drm = data;
+
+ drm->authenticated = true;
+}
+
diff --git a/wayland-drm.h b/wayland-drm.h
@@ -0,0 +1,70 @@
+/* wld: wayland-drm.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_WAYLAND_DRM_H
+#define WLD_WAYLAND_DRM_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct wld_context;
+struct wld_drawable;
+enum wld_format;
+
+struct wl_display;
+struct wl_surface;
+
+/**
+ * Create a new drawable context which creates Wayland buffers through the
+ * wl_drm interface, backed by hardware specific drawable implementations.
+ */
+struct wld_drm_context * wld_drm_create_context(struct wl_display * display);
+
+/**
+ * Destroy a DRM context.
+ */
+void wld_drm_destroy_context(struct wld_drm_context * context);
+
+/**
+ * Check if the wl_drm global has the specified pixel format.
+ *
+ * @see enum wld_format
+ */
+bool wld_drm_has_format(struct wld_drm_context * context,
+ enum wld_format format);
+
+/**
+ * Get the opened file descriptor for the DRM device.
+ */
+int wld_drm_get_fd(struct wld_drm_context * context);
+
+/**
+ * Create a new DRM drawable with the specified dimensions.
+ */
+struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * context,
+ struct wl_surface * surface,
+ uint32_t width, uint32_t height,
+ enum wld_format format);
+
+#endif
+
diff --git a/wayland-private.h b/wayland-private.h
@@ -0,0 +1,60 @@
+/* wld: wayland-private.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_WAYLAND_PRIVATE_H
+#define WLD_WAYLAND_PRIVATE_H 1
+
+#include <stdint.h>
+
+struct wld_drawable;
+enum wld_format format;
+
+struct wl_display;
+struct wl_event_queue;
+
+typedef void * (* wayland_create_context_func_t)(struct wl_display * display);
+typedef void (* wayland_destroy_context_func_t)(void * context);
+typedef struct wld_drawable * (* wayland_create_drawable_func_t)
+ (void * context, struct wl_surface * surface,
+ uint32_t width, uint32_t height, enum wld_format format);
+
+struct wld_wayland_interface
+{
+ wayland_create_context_func_t create_context;
+ wayland_destroy_context_func_t destroy_context;
+ wayland_create_drawable_func_t create_drawable;
+};
+
+#if ENABLE_WAYLAND_DRM
+extern const struct wld_wayland_interface wayland_drm_interface;
+#endif
+
+#if ENABLE_WAYLAND_SHM
+extern const struct wld_wayland_interface wayland_shm_interface;
+#endif
+
+int wayland_roundtrip(struct wl_display * display,
+ struct wl_event_queue * queue);
+
+#endif
+
diff --git a/wayland-shm.c b/wayland-shm.c
@@ -0,0 +1,221 @@
+/* wld: wayland-shm.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "wayland-shm.h"
+#include "wayland.h"
+#include "wayland-private.h"
+#include "wld-private.h"
+#include "pixman.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <wayland-client.h>
+
+struct wld_shm_context
+{
+ struct wl_registry * registry;
+ struct wl_event_queue * queue;
+ struct wl_shm * wl;
+ struct wl_array formats;
+
+ struct wld_pixman_context * pixman_context;
+};
+
+static void registry_global(void * data, struct wl_registry * registry,
+ uint32_t name, const char * interface,
+ uint32_t version);
+
+static void shm_format(void * data, struct wl_shm * wl, uint32_t format);
+
+const struct wld_wayland_interface wayland_shm_interface = {
+ .create_context = (wayland_create_context_func_t) &wld_shm_create_context,
+ .destroy_context
+ = (wayland_destroy_context_func_t) &wld_shm_destroy_context,
+ .create_drawable = (wayland_create_drawable_func_t) &wld_shm_create_drawable
+};
+
+const static struct wl_registry_listener registry_listener = {
+ .global = ®istry_global
+};
+
+const static struct wl_shm_listener shm_listener = {
+ .format = &shm_format,
+};
+
+static inline uint32_t wayland_format(enum wld_format format)
+{
+ switch (format)
+ {
+ case WLD_FORMAT_ARGB8888:
+ return WL_SHM_FORMAT_ARGB8888;
+ case WLD_FORMAT_XRGB8888:
+ return WL_SHM_FORMAT_XRGB8888;
+ default:
+ return 0;
+ }
+}
+
+struct wld_shm_context * wld_shm_create_context(struct wl_display * display)
+{
+ struct wld_shm_context * shm;
+
+ shm = malloc(sizeof *shm);
+
+ if (!shm)
+ return 0;
+
+ shm->wl = NULL;
+ wl_array_init(&shm->formats);
+
+ shm->queue = wl_display_create_queue(display);
+ shm->registry = wl_display_get_registry(display);
+ wl_registry_add_listener(shm->registry, ®istry_listener, shm);
+ wl_proxy_set_queue((struct wl_proxy *) shm->registry, shm->queue);
+
+ shm->pixman_context = wld_pixman_create_context();
+
+ /* Wait for wl_shm global. */
+ wayland_roundtrip(display, shm->queue);
+
+ if (!shm->wl)
+ {
+ DEBUG("No wl_shm global\n");
+ goto error2;
+ }
+
+ wl_shm_add_listener(shm->wl, &shm_listener, shm);
+
+ /* Wait for SHM formats. */
+ wayland_roundtrip(display, shm->queue);
+
+ return shm;
+
+ error2:
+ wl_registry_destroy(shm->registry);
+ wl_event_queue_destroy(shm->queue);
+ error1:
+ wl_array_release(&shm->formats);
+ free(shm);
+ error0:
+ return NULL;
+}
+
+void wld_shm_destroy_context(struct wld_shm_context * shm)
+{
+ wld_pixman_destroy_context(shm->pixman_context);
+ wl_shm_destroy(shm->wl);
+ wl_registry_destroy(shm->registry);
+ wl_event_queue_destroy(shm->queue);
+ wl_array_release(&shm->formats);
+
+ free(shm);
+}
+
+bool wld_shm_has_format(struct wld_shm_context * shm, uint32_t format)
+{
+ uint32_t * supported_format;
+
+ wl_array_for_each(supported_format, &shm->formats)
+ {
+ if (*supported_format == format)
+ return true;
+ }
+
+ return false;
+}
+
+struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * shm,
+ struct wl_surface * surface,
+ uint32_t width, uint32_t height,
+ uint32_t format)
+{
+ char name[] = "/tmp/wld-XXXXXX";
+ uint32_t pitch = width * format_bytes_per_pixel(format);
+ uint32_t size = height * pitch;
+ int fd;
+ void * data;
+ struct wl_shm_pool * pool;
+ struct wl_buffer * buffer0, * buffer1;
+ struct wld_drawable * drawable0, * drawable1;
+ uint32_t shm_format = wayland_format(format);
+
+ fd = mkostemp(name, O_CLOEXEC);
+
+ if (fd < 0)
+ goto error0;
+
+ unlink(name);
+
+ if (ftruncate(fd, size * 2) < 0)
+ goto error1;
+
+ data = mmap(NULL, size * 2, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+
+ if (data == MAP_FAILED)
+ goto error1;
+
+ pool = wl_shm_create_pool(shm->wl, fd, size * 2);
+ buffer0 = wl_shm_pool_create_buffer(pool, 0, width, height, pitch,
+ shm_format);
+ buffer1 = wl_shm_pool_create_buffer(pool, size, width, height, pitch,
+ shm_format);
+ wl_shm_pool_destroy(pool);
+ close(fd);
+
+ drawable0 = wld_pixman_create_drawable(shm->pixman_context, width, height,
+ data, pitch, format);
+ drawable1 = wld_pixman_create_drawable(shm->pixman_context, width, height,
+ data + size, pitch, format);
+
+ return wld_wayland_create_drawable_from_buffers(surface,
+ buffer0, drawable0,
+ buffer1, drawable1);
+
+ error1:
+ close(fd);
+ error0:
+ return NULL;
+}
+
+void registry_global(void * data, struct wl_registry * registry, uint32_t name,
+ const char * interface, uint32_t version)
+{
+ struct wld_shm_context * shm = data;
+
+ if (strcmp(interface, "wl_shm") == 0)
+ {
+ shm->wl = wl_registry_bind(registry, name, &wl_shm_interface, 1);
+ wl_proxy_set_queue((struct wl_proxy *) shm->wl, shm->queue);
+ }
+}
+
+void shm_format(void * data, struct wl_shm * wl, uint32_t format)
+{
+ struct wld_shm_context * shm = data;
+
+ *((uint32_t *) wl_array_add(&shm->formats, sizeof format)) = format;
+}
+
diff --git a/wayland-shm.h b/wayland-shm.h
@@ -0,0 +1,65 @@
+/* wld: wayland-shm.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_WAYLAND_SHM_H
+#define WLD_WAYLAND_SHM_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct wld_shm_context;
+struct wld_drawable;
+enum wld_format;
+
+struct wl_display;
+struct wl_surface;
+
+/**
+ * Create a new drawable context which creates Wayland buffers through the
+ * wl_shm interface, back by Pixman drawables.
+ */
+struct wld_shm_context * wld_shm_create_context(struct wl_display * display);
+
+/**
+ * Destroy an SHM context.
+ */
+void wld_shm_destroy_context(struct wld_shm_context * context);
+
+/**
+ * Check if the wl_shm global has the specified pixel format.
+ *
+ * @see enum wld_format
+ */
+bool wld_shm_has_format(struct wld_shm_context * context,
+ enum wld_format format);
+
+/**
+ * Create a new SHM drawable with the specified dimensions.
+ */
+struct wld_drawable * wld_shm_create_drawable(struct wld_shm_context * context,
+ struct wl_surface * surface,
+ uint32_t width, uint32_t height,
+ enum wld_format format);
+
+#endif
+
diff --git a/wayland.c b/wayland.c
@@ -0,0 +1,283 @@
+/* wld: wayland.c
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include "wayland.h"
+#include "wayland-private.h"
+#include "wld-private.h"
+
+#include <stdlib.h>
+#include <wayland-client.h>
+
+#define BACKBUF(drawable) (drawable)->buffers[(drawable)->front_buffer ^ 1]
+#define FRONTBUF(drawable) (drawable)->buffers[(drawable)->front_buffer]
+
+struct wld_wayland_context
+{
+ const struct wld_wayland_interface * interface;
+ void * context;
+};
+
+struct wayland_drawable
+{
+ struct wld_drawable base;
+ struct wl_surface * surface;
+ struct
+ {
+ struct wl_buffer * buffer;
+ struct wld_drawable * drawable;
+ } buffers[2];
+ uint8_t front_buffer;
+};
+
+static void callback_done(void * data, struct wl_callback * callback,
+ uint32_t msecs);
+
+static void wayland_fill_rectangle(struct wld_drawable * drawable,
+ uint32_t color,
+ pixman_rectangle16_t * rectangles);
+static void wayland_fill_rectangles(struct wld_drawable * drawable,
+ uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles);
+static void wayland_draw_text_utf8(struct wld_drawable * drawable,
+ struct font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length);
+static void wayland_flush(struct wld_drawable * drawable);
+static void wayland_destroy(struct wld_drawable * drawable);
+
+const struct wl_callback_listener callback_listener = {
+ .done = &callback_done
+};
+
+const struct wld_draw_interface wayland_draw = {
+ .fill_rectangle = &wayland_fill_rectangle,
+ .fill_rectangles = &wayland_fill_rectangles,
+ .draw_text_utf8 = &wayland_draw_text_utf8,
+ .flush = &wayland_flush,
+ .destroy = &wayland_destroy
+};
+
+const static struct wld_wayland_interface * interfaces[] = {
+#if ENABLE_WAYLAND_DRM
+ [WLD_DRM] = &wayland_drm_interface,
+#endif
+
+#if ENABLE_WAYLAND_SHM
+ [WLD_SHM] = &wayland_shm_interface
+#endif
+};
+
+struct wld_wayland_context * wld_wayland_create_context
+ (struct wl_display * display, enum wld_wayland_interface_id id, ...)
+{
+ struct wld_wayland_context * wayland;
+ va_list requested_interfaces;
+ bool interfaces_tried[ARRAY_LENGTH(interfaces)] = {};
+
+ wayland = malloc(sizeof *wayland);
+
+ if (!wayland)
+ goto error0;
+
+ wayland->context = NULL;
+ wayland->interface = NULL;
+
+ va_start(requested_interfaces, id);
+
+ while (id >= 0)
+ {
+ if (interfaces_tried[id] || !interfaces[id])
+ continue;
+
+ if ((wayland->context = interfaces[id]->create_context(display)))
+ {
+ wayland->interface = interfaces[id];
+ break;
+ }
+
+ interfaces_tried[id] = true;
+ id = va_arg(requested_interfaces, enum wld_wayland_interface_id);
+ }
+
+ va_end(requested_interfaces);
+
+ /* If the user specified WLD_ANY, try any remaining interfaces. */
+ if (!wayland->context && id == WLD_ANY)
+ {
+ for (id = 0; id < ARRAY_LENGTH(interfaces); ++id)
+ {
+ if (interfaces_tried[id] || !interfaces[id])
+ continue;
+
+ if ((wayland->context = interfaces[id]->create_context(display)))
+ {
+ wayland->interface = interfaces[id];
+ break;
+ }
+ }
+ }
+
+ if (!wayland->context)
+ {
+ DEBUG("Could not initialize any of the specified interfaces");
+ goto error1;
+ }
+
+ return wayland;
+
+ error1:
+ free(wayland);
+ error0:
+ return NULL;
+}
+
+void wld_wayland_destroy_context(struct wld_wayland_context * wayland)
+{
+ wayland->interface->destroy_context(wayland->context);
+ free(wayland);
+}
+
+struct wld_drawable * wld_wayland_create_drawable
+ (struct wld_wayland_context * context, struct wl_surface * surface,
+ uint32_t width, uint32_t height, enum wld_format format)
+{
+ return context->interface->create_drawable(context->context, surface,
+ width, height, format);
+}
+
+struct wld_drawable * wld_wayland_create_drawable_from_buffers
+ (struct wl_surface * surface,
+ struct wl_buffer * buffer0, struct wld_drawable * drawable0,
+ struct wl_buffer * buffer1, struct wld_drawable * drawable1)
+{
+ struct wayland_drawable * wayland;
+ uint32_t * data;
+
+ if (drawable0->width != drawable1->width
+ || drawable0->height != drawable1->height)
+ {
+ DEBUG("Drawables aren't the same dimensions\n");
+ return NULL;
+ }
+
+ wayland = malloc(sizeof *wayland);
+
+ if (!wayland)
+ return NULL;
+
+ wayland->buffers[0].buffer = buffer0;
+ wayland->buffers[1].buffer = buffer1;
+ wayland->buffers[0].drawable = drawable0;
+ wayland->buffers[1].drawable = drawable1;
+ wayland->front_buffer = 0;
+ wayland->surface = surface;
+
+ wayland->base.interface = &wayland_draw;
+ wayland->base.width = drawable0->width;
+ wayland->base.height = drawable0->height;
+
+ return &wayland->base;
+}
+
+int wayland_roundtrip(struct wl_display * display,
+ struct wl_event_queue * queue)
+{
+ struct wl_callback * callback;
+ bool done = false;
+ int ret = 0;
+
+ callback = wl_display_sync(display);
+ wl_callback_add_listener(callback, &callback_listener, &done);
+ wl_proxy_set_queue((struct wl_proxy *) callback, queue);
+
+ while (!done && ret >= 0)
+ ret = wl_display_dispatch_queue(display, queue);
+
+ if (ret == -1 && !done)
+ wl_callback_destroy(callback);
+
+ return ret;
+}
+
+void callback_done(void * data, struct wl_callback * callback, uint32_t msecs)
+{
+ bool * done = data;
+
+ *done = true;
+}
+void wayland_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle)
+{
+ struct wayland_drawable * wayland;
+
+ wayland = container_of(drawable, typeof(*wayland), base);
+ wld_fill_rectangle(BACKBUF(wayland).drawable, color, rectangle);
+}
+
+void wayland_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles)
+{
+ struct wayland_drawable * wayland;
+
+ wayland = container_of(drawable, typeof(*wayland), base);
+ wld_fill_rectangles(BACKBUF(wayland).drawable, color,
+ rectangles, num_rectangles);
+}
+
+void wayland_draw_text_utf8(struct wld_drawable * drawable,
+ struct font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length)
+{
+ struct wayland_drawable * wayland;
+
+ wayland = container_of(drawable, typeof(*wayland), base);
+ wld_draw_text_utf8_n(BACKBUF(wayland).drawable, &font->base, color,
+ x, y, text, length);
+}
+
+void wayland_flush(struct wld_drawable * drawable)
+{
+ struct wayland_drawable * wayland;
+
+ wayland = container_of(drawable, typeof(*wayland), base);
+
+ wld_flush(BACKBUF(wayland).drawable);
+ wl_surface_attach(wayland->surface, BACKBUF(wayland).buffer, 0, 0);
+ wl_surface_commit(wayland->surface);
+ wayland->front_buffer ^= 1;
+}
+
+void wayland_destroy(struct wld_drawable * drawable)
+{
+ struct wayland_drawable * wayland;
+
+ wayland = container_of(drawable, typeof(*wayland), base);
+ wl_buffer_destroy(wayland->buffers[0].buffer);
+ wl_buffer_destroy(wayland->buffers[1].buffer);
+ wld_destroy_drawable(wayland->buffers[0].drawable);
+ wld_destroy_drawable(wayland->buffers[1].drawable);
+}
+
diff --git a/wayland.h b/wayland.h
@@ -0,0 +1,93 @@
+/* wld: wayland.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_WAYLAND_H
+#define WLD_WAYLAND_H 1
+
+#include <stdint.h>
+
+struct wl_display;
+struct wl_surface;
+struct wl_buffer;
+
+struct wld_wayland_context;
+enum wld_format;
+
+enum wld_wayland_interface_id
+{
+ /**
+ * Give up on trying any new interfaces. This can be considered as a
+ * sentinel for wld_wayland_create_context.
+ */
+ WLD_NONE = -2,
+
+ /**
+ * Try any available interface.
+ */
+ WLD_ANY = -1,
+ WLD_DRM,
+ WLD_SHM
+};
+
+/**
+ * Create a new drawing context which uses various available Wayland interfaces
+ * (such as wl_shm and wl_drm) to create buffers backed by drawables specific
+ * to the interface.
+ *
+ * You can specify the particular interface you want to use by specifying them
+ * as arguments. Interfaces will be tried in the order they are given.
+ *
+ * The last argument must be either WLD_NONE or WLD_ANY.
+ *
+ * @see enum wld_wayland_interface_id
+ */
+struct wld_wayland_context * wld_wayland_create_context
+ (struct wl_display * display, enum wld_wayland_interface_id id, ...);
+
+/**
+ * Destroy a Wayland context.
+ */
+void wld_wayland_destroy_context(struct wld_wayland_context * context);
+
+/**
+ * Create a new Wayland drawable for the given surface with a particular pixel
+ * format.
+ */
+struct wld_drawable * wld_wayland_create_drawable
+ (struct wld_wayland_context * context, struct wl_surface * surface,
+ uint32_t width, uint32_t height, enum wld_format format);
+
+/**
+ * Create a new Wayland drawable for the given surface, using the given buffers
+ * and drawables as backing for the surface.
+ *
+ * This method does not require a Wayland context to be created because buffers
+ * and drawables are passed to it explicitly.
+ */
+struct wld_drawable * wld_wayland_create_drawable_from_buffers
+ (struct wl_surface * surface,
+ struct wl_buffer * buffer0, struct wld_drawable * drawable0,
+ struct wl_buffer * buffer1, struct wld_drawable * drawable1);
+
+#endif
+
diff --git a/wld-private.h b/wld-private.h
@@ -0,0 +1,135 @@
+/* wld: wld-private.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_PRIVATE_H
+#define WLD_PRIVATE_H 1
+
+#include "wld.h"
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_BITMAP_H
+
+#ifndef offsetof
+# define offsetof __builtin_offsetof
+#endif
+
+#define container_of(ptr, type, member) ({ \
+ const typeof(((type *) 0)->member) *__mptr = (ptr); \
+ ((type *) ((uintptr_t) __mptr - offsetof(type, member))); \
+})
+
+#define ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0])
+#if ENABLE_DEBUG
+# define DEBUG(format, args...) \
+ fprintf(stderr, "# %s: " format, __func__, ## args)
+#else
+# define DEBUG(format, args...)
+#endif
+
+struct wld_font_context
+{
+ FT_Library library;
+};
+
+struct glyph
+{
+ FT_Bitmap bitmap;
+
+ /**
+ * The offset from the origin to the top left corner of the bitmap.
+ */
+ int16_t x, y;
+
+ /**
+ * The width to advance to the origin of the next character.
+ */
+ uint16_t advance;
+};
+
+struct font
+{
+ struct wld_font base;
+
+ struct wld_font_context * context;
+ FT_Face face;
+ struct glyph ** glyphs;
+};
+
+struct wld_draw_interface
+{
+ void (* fill_rectangle)(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle);
+ void (* fill_rectangles)(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle,
+ uint32_t num_rectangles);
+ void (* draw_text_utf8)(struct wld_drawable * drawable,
+ struct font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length);
+ void (* flush)(struct wld_drawable * drawable);
+ void (* destroy)(struct wld_drawable * drawable);
+};
+
+
+bool font_ensure_glyph(struct font * font, FT_UInt glyph_index);
+
+/**
+ * Returns the number of bytes per pixel for the given format.
+ */
+static inline uint8_t format_bytes_per_pixel(enum wld_format format)
+{
+ switch (format)
+ {
+ case WLD_FORMAT_ARGB8888:
+ case WLD_FORMAT_XRGB8888:
+ return 4;
+ default:
+ return 0;
+ }
+}
+
+/**
+ * This default fill_rectangle method is implemented as fill_rectangles with a
+ * length parameter of 1.
+ */
+void default_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle);
+
+/**
+ * This default fill_rectangles method is implemented in terms of the singular
+ * fill_rectangle.
+ */
+void default_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles);
+
+/**
+ * This is a NO-OP for implementations that do not require flushing.
+ */
+void default_flush(struct wld_drawable * drawable);
+
+#endif
+
diff --git a/wld.h b/wld.h
@@ -0,0 +1,144 @@
+/* wld: wld.h
+ *
+ * Copyright (c) 2013 Michael Forney
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef WLD_H
+#define WLD_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <pixman.h>
+#include <fontconfig/fontconfig.h>
+
+#define __WLD_FOURCC(a, b, c, d) ( (a) \
+ | ((b) << 8) \
+ | ((c) << 16) \
+ | ((d) << 24) )
+
+/**
+ * Supported pixel formats.
+ *
+ * These formats can safely be interchanged with GBM and wl_drm formats.
+ */
+enum wld_format
+{
+ WLD_FORMAT_XRGB8888 = __WLD_FOURCC('X', 'R', '2', '4'),
+ WLD_FORMAT_ARGB8888 = __WLD_FOURCC('A', 'R', '2', '4')
+};
+
+bool wld_lookup_named_color(const char * name, uint32_t * color);
+
+/* Font Handling */
+struct wld_extents
+{
+ uint32_t advance;
+};
+
+struct wld_font
+{
+ uint32_t ascent, descent;
+ uint32_t height;
+ uint32_t max_advance;
+};
+
+/**
+ * Create a new font context.
+ *
+ * This sets up the underlying FreeType library.
+ */
+struct wld_font_context * wld_font_create_context();
+
+/**
+ * Open a new font from the given fontconfig match.
+ */
+struct wld_font * wld_font_open_pattern(struct wld_font_context * context,
+ FcPattern * match);
+
+/**
+ * Open a new font from a fontconfig pattern string.
+ */
+struct wld_font * wld_font_open_name(struct wld_font_context * context,
+ const char * name);
+
+/**
+ * Close a font.
+ */
+void wld_font_close(struct wld_font * font);
+
+/**
+ * Check if the given font has a particular character (in UTF-32), and if so,
+ * load the glyph.
+ */
+bool wld_font_ensure_char(struct wld_font * font, uint32_t character);
+
+/**
+ * Calculate the text extents of the given UTF-8 string.
+ *
+ * @param length The maximum number of bytes in the string to process
+ */
+void wld_font_text_extents_utf8_n(struct wld_font * font,
+ const char * text, int32_t length,
+ struct wld_extents * extents);
+
+static inline void wld_font_text_extents_utf8(struct wld_font * font,
+ const char * text,
+ struct wld_extents * extents)
+{
+ wld_font_text_extents_utf8_n(font, text, INT32_MAX, extents);
+}
+
+/* Drawables */
+struct wld_drawable
+{
+ const struct wld_draw_interface * interface;
+ uint32_t width, height;
+};
+
+/**
+ * Destroy a drawable (created with any context).
+ */
+void wld_destroy_drawable(struct wld_drawable * drawable);
+
+void wld_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangle);
+
+void wld_fill_rectangles(struct wld_drawable * drawable, uint32_t color,
+ pixman_rectangle16_t * rectangles,
+ uint32_t num_rectangles);
+
+void wld_draw_text_utf8_n(struct wld_drawable * drawable,
+ struct wld_font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text, int32_t length);
+
+static inline void wld_draw_text_utf8(struct wld_drawable * drawable,
+ struct wld_font * font, uint32_t color,
+ int32_t x, int32_t y,
+ const char * text)
+{
+ wld_draw_text_utf8_n(drawable, font, color, x, y, text, INT32_MAX);
+}
+
+void wld_flush(struct wld_drawable * drawable);
+
+#endif
+
diff --git a/wld.pc.in b/wld.pc.in
@@ -0,0 +1,14 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: wld
+Description: A primitive drawing library library targeted at Wayland
+Version: @PACKAGE_VERSION@
+Cflags: -I${includedir}
+Libs: -L${libdir} -lwld
+
+Requires: fontconfig pixman-1
+Requires.private: freetype2 @PKGCONFIG_REQUIRES_PRIVATE@
+