<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">
<div>From 1f85ff3b349a7fbc1217e30f4278c174c93b549b Mon Sep 17 00:00:00 2001</div>
<div>From: Henry Song <hsong@sisa.samsung.com></div>
<div>Date: Mon, 31 Dec 2012 12:48:09 -0800</div>
<div>Subject: [PATCH] gl: bind cairo-gl backend to apple's NSOpenGL and apple's</div>
<div> OpenGL instead of mesa's GLX and GL.  It is not possible to create</div>
<div> cairo_gl_surface to use apple's OpenGL directly.</div>
<div><br>
</div>
<div>Few notes:</div>
<div>1. disabled gl-surface-source test because it uses GLX, need to revise the</div>
<div>test</div>
<div>2. offscreen and NSView-based surface work fine, I have not implemented for</div>
<div>virtual screen yet.</div>
<div>3. After install macport's mesa package, it is possible to use GLX on mac,</div>
<div>but GLX and NSOpenGL are mutually execlusive.</div>
<div>4. To use NSOpenGL "./configure --enable-gl=yes --enable-glx=no</div>
<div>--enable-nsgl=yes</div>
<div>5. To use GLX "./configure --enable-gl-yes --enable-nsgl=no</div>
<div>--enable-glx=yes"</div>
<div>6. make test on NSOpenGL "make test TARGETS=nsgl"</div>
<div>---</div>
<div> boilerplate/Makefile.sources         |   1 +</div>
<div> boilerplate/Makefile.win32.features  |  12 +++</div>
<div> boilerplate/cairo-boilerplate-nsgl.m | 150 +++++++++++++++++++++++++++</div>
<div> build/Makefile.win32.features        |   1 +</div>
<div> build/Makefile.win32.features-h      |   3 +</div>
<div> build/configure.ac.features          |   1 +</div>
<div> configure.ac                         |  24 ++++-</div>
<div> perf/Makefile.am                     |  12 +++</div>
<div> src/Makefile.sources                 |   2 +</div>
<div> src/Makefile.win32.features          |  16 +++</div>
<div> src/cairo-gl.h                       |  16 +++</div>
<div> src/cairo-nsgl-context.m             | 193 +++++++++++++++++++++++++++++++++++</div>
<div> test/Makefile.am                     |  10 ++</div>
<div> test/Makefile.sources                |   2 +-</div>
<div> 14 files changed, 439 insertions(+), 4 deletions(-)</div>
<div> create mode 100644 boilerplate/cairo-boilerplate-nsgl.m</div>
<div> create mode 100644 src/cairo-nsgl-context.m</div>
<div><br>
</div>
<div>diff --git a/boilerplate/Makefile.sources b/boilerplate/Makefile.sources</div>
<div>index 101e997..77b77b5 100644</div>
<div>--- a/boilerplate/Makefile.sources</div>
<div>+++ b/boilerplate/Makefile.sources</div>
<div>@@ -25,6 +25,7 @@ cairo_boilerplate_drm_sources = cairo-boilerplate-drm.c</div>
<div> cairo_boilerplate_glx_sources = cairo-boilerplate-glx.c</div>
<div> cairo_boilerplate_wgl_sources = cairo-boilerplate-wgl.c</div>
<div> cairo_boilerplate_egl_sources = cairo-boilerplate-egl.c</div>
<div>+cairo_boilerplate_nsgl_sources = cairo-boilerplate-nsgl.m</div>
<div> cairo_boilerplate_pdf_sources = cairo-boilerplate-pdf.c</div>
<div> cairo_boilerplate_ps_sources = cairo-boilerplate-ps.c</div>
<div> cairo_boilerplate_qt_cxx_sources = cairo-boilerplate-qt.cpp</div>
<div>diff --git a/boilerplate/Makefile.win32.features b/boilerplate/Makefile.win32.features</div>
<div>index e60a95b..11e3be7 100644</div>
<div>--- a/boilerplate/Makefile.win32.features</div>
<div>+++ b/boilerplate/Makefile.win32.features</div>
<div>@@ -319,6 +319,18 @@ enabled_cairo_boilerplate_cxx_sources += $(cairo_boilerplate_wgl_cxx_sources)</div>
<div> enabled_cairo_boilerplate_sources += $(cairo_boilerplate_wgl_sources)</div>
<div> endif</div>
<div> </div>
<div>+supported_cairo_boilerplate_headers += $(cairo_boilerplate_nsgl_headers)</div>
<div>+all_cairo_boilerplate_headers += $(cairo_boilerplate_nsgl_headers)</div>
<div>+all_cairo_boilerplate_private += $(cairo_boilerplate_nsgl_private)</div>
<div>+all_cairo_boilerplate_cxx_sources += $(cairo_boilerplate_nsgl_cxx_sources)</div>
<div>+all_cairo_boilerplate_sources += $(cairo_boilerplate_nsgl_sources)</div>
<div>+ifeq ($(CAIRO_HAS_NSGL_FUNCTIONS),1)</div>
<div>+enabled_cairo_boilerplate_headers += $(cairo_boilerplate_nsgl_headers)</div>
<div>+enabled_cairo_boilerplate_private += $(cairo_boilerplate_nsgl_private)</div>
<div>+enabled_cairo_boilerplate_cxx_sources += $(cairo_boilerplate_nsgl_cxx_sources)</div>
<div>+enabled_cairo_boilerplate_sources += $(cairo_boilerplate_nsgl_sources)</div>
<div>+endif</div>
<div>+</div>
<div> supported_cairo_boilerplate_headers += $(cairo_boilerplate_script_headers)</div>
<div> all_cairo_boilerplate_headers += $(cairo_boilerplate_script_headers)</div>
<div> all_cairo_boilerplate_private += $(cairo_boilerplate_script_private)</div>
<div>diff --git a/boilerplate/cairo-boilerplate-nsgl.m b/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>new file mode 100644</div>
<div>index 0000000..0d6d458</div>
<div>--- /dev/null</div>
<div>+++ b/boilerplate/cairo-boilerplate-nsgl.m</div>
<div>@@ -0,0 +1,150 @@</div>
<div>+/* Cairo - a vector graphics library with display and print output</div>
<div>+ *</div>
<div>+ * Copyright © 2009 Chris Wilson</div>
<div>+ * Copyright © 2012 Henry Song</div>
<div>+ *</div>
<div>+ * This library is free software; you can redistribute it and/or</div>
<div>+ * modify it either under the terms of the GNU Lesser General Public</div>
<div>+ * License version 2.1 as published by the Free Software Foundation</div>
<div>+ * (the "LGPL") or, at your option, under the terms of the Mozilla</div>
<div>+ * Public License Version 1.1 (the "MPL"). If you do not alter this</div>
<div>+ * notice, a recipient may use your version of this file under either</div>
<div>+ * the MPL or the LGPL.</div>
<div>+ *</div>
<div>+ * You should have received a copy of the LGPL along with this library</div>
<div>+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software</div>
<div>+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA</div>
<div>+ * You should have received a copy of the MPL along with this library</div>
<div>+ * in the file COPYING-MPL-1.1</div>
<div>+ *</div>
<div>+ * The contents of this file are subject to the Mozilla Public License</div>
<div>+ * Version 1.1 (the "License"); you may not use this file except in</div>
<div>+ * compliance with the License. You may obtain a copy of the License at</div>
<div>+ * http://www.mozilla.org/MPL/</div>
<div>+ *</div>
<div>+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY</div>
<div>+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for</div>
<div>+ * the specific language governing rights and limitations.</div>
<div>+ *</div>
<div>+ * The Original Code is the cairo graphics library.</div>
<div>+ *</div>
<div>+ * The Initial Developer of the Original Code is Chris Wilson.</div>
<div>+ *</div>
<div>+ * Contributors</div>
<div>+ *<span class="Apple-tab-span" style="white-space:pre"> </span>Henry Song <henry.song@samsung.com></div>
<div>+ */</div>
<div>+</div>
<div>+#import "cairo-boilerplate-private.h"</div>
<div>+</div>
<div>+#import <cairo-gl.h></div>
<div>+</div>
<div>+#import <AppKit/NSOpenGL.h></div>
<div>+#import <Foundation/NSAutoreleasePool.h></div>
<div>+</div>
<div>+static const cairo_user_data_key_t gl_closure_key;</div>
<div>+</div>
<div>+typedef struct _nsgl_target_closure {</div>
<div>+    NSOpenGLContext *ctx;</div>
<div>+    NSAutoreleasePool *pool;</div>
<div>+</div>
<div>+    cairo_device_t *device;</div>
<div>+    cairo_surface_t *surface;</div>
<div>+} nsgl_target_closure_t;</div>
<div>+</div>
<div>+static void</div>
<div>+_cairo_boilerplate_nsgl_cleanup (void *closure)</div>
<div>+{</div>
<div>+    nsgl_target_closure_t *gltc = closure;</div>
<div>+</div>
<div>+    cairo_device_finish (gltc->device);</div>
<div>+    cairo_device_destroy (gltc->device);</div>
<div>+</div>
<div>+    [NSOpenGLContext clearCurrentContext];</div>
<div>+    [gltc->pool release];</div>
<div>+</div>
<div>+    free (gltc);</div>
<div>+}</div>
<div>+</div>
<div>+static cairo_surface_t *</div>
<div>+_cairo_boilerplate_nsgl_create_surface (const char<span class="Apple-tab-span" style="white-space:pre">
</span>*name,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      cairo_content_t<span class="Apple-tab-span" style="white-space:pre">
</span> content,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      double<span class="Apple-tab-span" style="white-space:pre">
</span> width,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      double<span class="Apple-tab-span" style="white-space:pre">
</span> height,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      double<span class="Apple-tab-span" style="white-space:pre">
</span> max_width,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      double<span class="Apple-tab-span" style="white-space:pre">
</span> max_height,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      cairo_boilerplate_mode_t   mode,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      void<span class="Apple-tab-span" style="white-space:pre">
</span>**closure)</div>
<div>+{</div>
<div>+    nsgl_target_closure_t *gltc;</div>
<div>+    cairo_surface_t *surface;</div>
<div>+    NSOpenGLPixelFormat *pixelFormat;</div>
<div>+</div>
<div>+    NSOpenGLPixelFormatAttribute attrs[] = {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFADepthSize, 24,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFAStencilSize, 8,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NSOpenGLPFAAlphaSize, 8,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>0</div>
<div>+    };</div>
<div>+</div>
<div>+    gltc = xcalloc (1, sizeof (nsgl_target_closure_t));</div>
<div>+    *closure = gltc;</div>
<div>+    gltc->pool = [[NSAutoreleasePool alloc] init];</div>
<div>+</div>
<div>+    pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes: attrs];</div>
<div>+    if (!pixelFormat)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return NULL;</div>
<div>+</div>
<div>+    gltc->ctx = [[NSOpenGLContext alloc] initWithFormat: pixelFormat</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> shareContext: nil];</div>
<div>+</div>
<div>+    if (!gltc->ctx)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return NULL;</div>
<div>+</div>
<div>+    [gltc->ctx makeCurrentContext];</div>
<div>+    gltc->device = cairo_nsgl_device_create (gltc->ctx);</div>
<div>+</div>
<div>+    if (width < 1)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>width = 1;</div>
<div>+    if (height < 1)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>height = 1;</div>
<div>+</div>
<div>+    gltc->surface = surface = cairo_gl_surface_create (gltc->device,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      content,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      ceil (width),</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>      ceil (height));</div>
<div>+    if (cairo_surface_status (surface))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_cleanup (gltc);</div>
<div>+</div>
<div>+    return surface;</div>
<div>+}</div>
<div>+</div>
<div>+static void</div>
<div>+_cairo_boilerplate_nsgl_synchronize (void *closure)</div>
<div>+{</div>
<div>+    nsgl_target_closure_t *gltc = closure;</div>
<div>+</div>
<div>+    if (cairo_device_acquire (gltc->device))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return;</div>
<div>+</div>
<div>+    glFinish ();</div>
<div>+</div>
<div>+    cairo_device_release (gltc->device);</div>
<div>+}</div>
<div>+</div>
<div>+static const cairo_boilerplate_target_t targets[] = {</div>
<div>+    {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>"nsgl", "gl", NULL, NULL,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>CAIRO_SURFACE_TYPE_GL, CAIRO_CONTENT_COLOR_ALPHA, 1,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>"cairo_nsgl_device_create",</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_create_surface,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_surface_create_similar,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>NULL, NULL,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_get_image_surface,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>cairo_surface_write_to_png,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_cleanup,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_boilerplate_nsgl_synchronize,</div>
<div>+        NULL,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>TRUE, FALSE, FALSE</div>
<div>+    }</div>
<div>+};</div>
<div>+CAIRO_BOILERPLATE (nsgl, targets)</div>
<div>diff --git a/build/Makefile.win32.features b/build/Makefile.win32.features</div>
<div>index 8cb155d..b45d65f 100644</div>
<div>--- a/build/Makefile.win32.features</div>
<div>+++ b/build/Makefile.win32.features</div>
<div>@@ -25,6 +25,7 @@ CAIRO_HAS_VG_SURFACE=0</div>
<div> CAIRO_HAS_EGL_FUNCTIONS=0</div>
<div> CAIRO_HAS_GLX_FUNCTIONS=0</div>
<div> CAIRO_HAS_WGL_FUNCTIONS=0</div>
<div>+CAIRO_HAS_NSGL_FUNCTIONS=0</div>
<div> CAIRO_HAS_SCRIPT_SURFACE=1</div>
<div> CAIRO_HAS_FT_FONT=0</div>
<div> CAIRO_HAS_FC_FONT=0</div>
<div>diff --git a/build/Makefile.win32.features-h b/build/Makefile.win32.features-h</div>
<div>index 13904cf..ef4ae47 100644</div>
<div>--- a/build/Makefile.win32.features-h</div>
<div>+++ b/build/Makefile.win32.features-h</div>
<div>@@ -80,6 +80,9 @@ endif</div>
<div> ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1)</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>@echo "#define CAIRO_HAS_WGL_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h</div>
<div> endif</div>
<div>+ifeq ($(CAIRO_HAS_NSGL_FUNCTIONS),1)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>@echo "#define CAIRO_HAS_NSGL_FUNCTIONS 1" >> $(top_srcdir)/src/cairo-features.h</div>
<div>+endif</div>
<div> ifeq ($(CAIRO_HAS_SCRIPT_SURFACE),1)</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>@echo "#define CAIRO_HAS_SCRIPT_SURFACE 1" >> $(top_srcdir)/src/cairo-features.h</div>
<div> endif</div>
<div>diff --git a/build/configure.ac.features b/build/configure.ac.features</div>
<div>index e4a2aaf..91737b0 100644</div>
<div>--- a/build/configure.ac.features</div>
<div>+++ b/build/configure.ac.features</div>
<div>@@ -402,6 +402,7 @@ AC_DEFUN([CAIRO_REPORT],</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>echo "  GLX functions:   $use_glx"</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>echo "  WGL functions:   $use_wgl"</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>echo "  EGL functions:   $use_egl"</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>echo "  NSOpenGL functions: $use_nsgl"</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>echo "  X11-xcb functions: $use_xlib_xcb"</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>echo "  XCB-shm functions: $use_xcb_shm"</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>echo ""</div>
<div>diff --git a/configure.ac b/configure.ac</div>
<div>index fc8d3b1..e456249 100644</div>
<div>--- a/configure.ac</div>
<div>+++ b/configure.ac</div>
<div>@@ -331,19 +331,20 @@ CAIRO_ENABLE_SURFACE_BACKEND(gl, OpenGL, no, [</div>
<div>   gl_REQUIRES="gl"</div>
<div>   PKG_CHECK_MODULES(gl, $gl_REQUIRES,, [</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span> dnl Fallback to searching for headers</div>
<div>-<span class="Apple-tab-span" style="white-space:pre"> </span> AC_CHECK_HEADER(GL/gl.h,, [use_gl="no (gl.pc nor OpenGL headers not found)"])</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> AC_CHECK_HEADER([GL/gl.h, OpenGL/gl.h],, [use_gl="no (gl.pc nor OpenGL headers not found)"])</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span> if test "x$use_gl" = "xyes"; then</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>     gl_NONPKGCONFIG_CFLAGS=</div>
<div>-<span class="Apple-tab-span" style="white-space:pre"> </span>     gl_NONPKGCONFIG_LIBS="-lGL"</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>     gl_NONPKGCONFIG_LIBS=</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span> fi])</div>
<div> </div>
<div>   if test "x$have_dl" = "xyes" -a "x$have_dlsym" = "xyes"; then</div>
<div>-    gl_LIBS="$gl_LIBS -ldl"</div>
<div>+    gl_LIBS="-ldl"</div>
<div>   fi</div>
<div> </div>
<div>   need_glx_functions=yes</div>
<div>   need_wgl_functions=yes</div>
<div>   need_egl_functions=yes</div>
<div>+  need_nsgl_functions=yes</div>
<div> ])</div>
<div> </div>
<div> dnl ===========================================================================</div>
<div>@@ -431,6 +432,7 @@ CAIRO_ENABLE_FUNCTIONS(glx, GLX, auto, [</div>
<div>     glx_NONPKGCONFIG_CFLAGS=</div>
<div>     glx_NONPKGCONFIG_LIBS="-lGL"</div>
<div>     CFLAGS="$save_CFLAGS"</div>
<div>+    need_nsgl_functions="no"</div>
<div>   else</div>
<div>       use_glx="no (not required by any backend)"</div>
<div>   fi</div>
<div>@@ -446,6 +448,22 @@ CAIRO_ENABLE_FUNCTIONS(wgl, WGL, auto, [</div>
<div> </div>
<div> dnl ===========================================================================</div>
<div> </div>
<div>+CAIRO_ENABLE_FUNCTIONS(nsgl, NSOpenGL, auto, [</div>
<div>+  if test "x$need_nsgl_functions" = "xyes"; then</div>
<div>+    AC_LANG_PUSH([Objective C])</div>
<div>+    dnl There is no pkgconfig for NSOpenGL; lets do a header check</div>
<div>+    AC_CHECK_HEADERS([OpenGL/gl.h], [], [use_nsgl="no (requires AppKit and OpenGL framework)"], [])</div>
<div>+    nsgl_LIBS="-Xlinker -framework -Xlinker OpenGL -Xlinker -framework -Xlinker AppKit"</div>
<div>+      gl_NONPKGCONFIG_CFLAGS=</div>
<div>+      gl_NONPKGCONFIG_LIBS=</div>
<div>+    AC_LANG_POP([Objective C])</div>
<div>+  else</div>
<div>+      use_nsgl="no (use enable-nsgl=yes to enable)"</div>
<div>+  fi</div>
<div>+])</div>
<div>+</div>
<div>+dnl ===========================================================================</div>
<div>+</div>
<div> any2ppm_cs=no</div>
<div> CAIRO_ENABLE_SURFACE_BACKEND(script, script, yes, [</div>
<div>   any2ppm_cs=yes</div>
<div>diff --git a/perf/Makefile.am b/perf/Makefile.am</div>
<div>index 92f0dfc..7929387 100644</div>
<div>--- a/perf/Makefile.am</div>
<div>+++ b/perf/Makefile.am</div>
<div>@@ -34,11 +34,21 @@ EXTRA_PROGRAMS += \</div>
<div> EXTRA_DIST += cairo-perf-diff COPYING</div>
<div> EXTRA_LTLIBRARIES += libcairoperf.la</div>
<div> </div>
<div>+if CAIRO_HAS_NSGL_FUNCTIONS</div>
<div>+cairo_nsgl_LIBS = \</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>-Xlinker -framework -Xlinker OpenGL \</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>-Xlinker -framework -Xlinker AppKit \</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>-Xlinker -framework -Xlinker Foundation</div>
<div>+else</div>
<div>+cairo_nsgl_LIBS =</div>
<div>+endif</div>
<div>+</div>
<div> LDADD = libcairoperf.la \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/boilerplate/libcairoboilerplate.la \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/src/libcairo.la</div>
<div> </div>
<div> cairo_perf_micro_SOURCES = $(cairo_perf_micro_sources)</div>
<div>+cairo_perf_micro_LDFLAGS = $(cairo_nsgl_LIBS)</div>
<div> cairo_perf_micro_LDADD = \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/perf/micro/libcairo-perf-micro.la \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(LDADD)</div>
<div>@@ -55,6 +65,7 @@ libcairoperf_la_SOURCES = \</div>
<div> cairo_analyse_trace_SOURCES = \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(cairo_analyse_trace_sources)<span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(cairo_analyse_trace_external_sources)</div>
<div>+cairo_analyse_trace_LDFLAGS = $(cairo_nsgl_LIBS)</div>
<div> cairo_analyse_trace_LDADD =<span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/util/cairo-missing/libcairo-missing.la \</div>
<div>@@ -67,6 +78,7 @@ cairo_analyse_trace_DEPENDENCIES = \</div>
<div> cairo_perf_trace_SOURCES = \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(cairo_perf_trace_sources)<span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(cairo_perf_trace_external_sources)</div>
<div>+cairo_perf_trace_LDFLAGS = $(cairo_nsgl_LIBS)</div>
<div> cairo_perf_trace_LDADD =<span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/util/cairo-script/libcairo-script-interpreter.la \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/util/cairo-missing/libcairo-missing.la \</div>
<div>diff --git a/src/Makefile.sources b/src/Makefile.sources</div>
<div>index d6793b0..85b43da 100644</div>
<div>--- a/src/Makefile.sources</div>
<div>+++ b/src/Makefile.sources</div>
<div>@@ -258,6 +258,7 @@ cairo_sources += $(_cairo_font_subset_sources)</div>
<div> cairo_egl_sources =</div>
<div> cairo_glx_sources =</div>
<div> cairo_wgl_sources =</div>
<div>+cairo_nsgl_sources =</div>
<div> </div>
<div> _cairo_pdf_operators_private = cairo-pdf-operators-private.h cairo-pdf-shading-private.h</div>
<div> _cairo_pdf_operators_sources = cairo-pdf-operators.c cairo-pdf-shading.c</div>
<div>@@ -404,6 +405,7 @@ cairo_glesv2_sources = $(cairo_gl_sources)</div>
<div> cairo_egl_sources += cairo-egl-context.c</div>
<div> cairo_glx_sources += cairo-glx-context.c</div>
<div> cairo_wgl_sources += cairo-wgl-context.c</div>
<div>+cairo_nsgl_sources += cairo-nsgl-context.m</div>
<div> </div>
<div> cairo_directfb_headers = cairo-directfb.h</div>
<div> cairo_directfb_sources = cairo-directfb-surface.c</div>
<div>diff --git a/src/Makefile.win32.features b/src/Makefile.win32.features</div>
<div>index 2274f4a..c885908 100644</div>
<div>--- a/src/Makefile.win32.features</div>
<div>+++ b/src/Makefile.win32.features</div>
<div>@@ -421,6 +421,22 @@ ifeq ($(CAIRO_HAS_WGL_FUNCTIONS),1)</div>
<div> enabled_cairo_pkgconf += cairo-wgl.pc</div>
<div> endif</div>
<div> </div>
<div>+supported_cairo_headers += $(cairo_nsgl_headers)</div>
<div>+all_cairo_headers += $(cairo_nsgl_headers)</div>
<div>+all_cairo_private += $(cairo_nsgl_private)</div>
<div>+all_cairo_cxx_sources += $(cairo_nsgl_cxx_sources)</div>
<div>+all_cairo_sources += $(cairo_nsgl_sources)</div>
<div>+ifeq ($(CAIRO_HAS_NSGL_FUNCTIONS),1)</div>
<div>+enabled_cairo_headers += $(cairo_nsgl_headers)</div>
<div>+enabled_cairo_private += $(cairo_nsgl_private)</div>
<div>+enabled_cairo_cxx_sources += $(cairo_nsgl_cxx_sources)</div>
<div>+enabled_cairo_sources += $(cairo_nsgl_sources)</div>
<div>+endif</div>
<div>+all_cairo_pkgconf += cairo-nsgl.pc</div>
<div>+ifeq ($(CAIRO_HAS_NSGL_FUNCTIONS),1)</div>
<div>+enabled_cairo_pkgconf += cairo-nsgl.pc</div>
<div>+endif</div>
<div>+</div>
<div> supported_cairo_headers += $(cairo_script_headers)</div>
<div> all_cairo_headers += $(cairo_script_headers)</div>
<div> all_cairo_private += $(cairo_script_private)</div>
<div>diff --git a/src/cairo-gl.h b/src/cairo-gl.h</div>
<div>index cec3173..dec2216 100644</div>
<div>--- a/src/cairo-gl.h</div>
<div>+++ b/src/cairo-gl.h</div>
<div>@@ -126,6 +126,22 @@ cairo_gl_surface_create_for_dc (cairo_device_t<span class="Apple-tab-span" style="white-space:pre">
</span>*device,</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>int<span class="Apple-tab-span" style="white-space:pre">
</span>height);</div>
<div> #endif</div>
<div> </div>
<div>+#if CAIRO_HAS_NSGL_FUNCTIONS</div>
<div>+#include <OpenGL/gl.h></div>
<div>+</div>
<div>+cairo_public cairo_device_t *</div>
<div>+cairo_nsgl_device_create (void *abstract_ctx);</div>
<div>+</div>
<div>+cairo_public void *</div>
<div>+cairo_nsgl_device_get_context (cairo_device_t *device);</div>
<div>+</div>
<div>+cairo_public cairo_surface_t *</div>
<div>+cairo_gl_surface_create_for_view (cairo_device_t *device,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> void<span class="Apple-tab-span" style="white-space:pre">
</span><span class="Apple-tab-span" style="white-space:pre"></span>*abstract_view,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> int<span class="Apple-tab-span" style="white-space:pre">
</span>width,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> int<span class="Apple-tab-span" style="white-space:pre">
</span>height);</div>
<div>+#endif</div>
<div>+</div>
<div> #if CAIRO_HAS_EGL_FUNCTIONS</div>
<div> #include <EGL/egl.h></div>
<div> </div>
<div>diff --git a/src/cairo-nsgl-context.m b/src/cairo-nsgl-context.m</div>
<div>new file mode 100644</div>
<div>index 0000000..b3e893c</div>
<div>--- /dev/null</div>
<div>+++ b/src/cairo-nsgl-context.m</div>
<div>@@ -0,0 +1,193 @@</div>
<div>+/* cairo - a vector graphics library with display and print output</div>
<div>+ *</div>
<div>+ * Copyright © 2012 Henry Song</div>
<div>+ * Copyright © 2009 Eric Anholt</div>
<div>+ * Copyright © 2009 Chris Wilson</div>
<div>+ * Copyright © 2005 Red Hat, Inc</div>
<div>+ *</div>
<div>+ * This library is free software; you can redistribute it and/or</div>
<div>+ * modify it either under the terms of the GNU Lesser General Public</div>
<div>+ * License version 2.1 as published by the Free Software Foundation</div>
<div>+ * (the "LGPL") or, at your option, under the terms of the Mozilla</div>
<div>+ * Public License Version 1.1 (the "MPL"). If you do not alter this</div>
<div>+ * notice, a recipient may use your version of this file under either</div>
<div>+ * the MPL or the LGPL.</div>
<div>+ *</div>
<div>+ * You should have received a copy of the LGPL along with this library</div>
<div>+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software</div>
<div>+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA</div>
<div>+ * You should have received a copy of the MPL along with this library</div>
<div>+ * in the file COPYING-MPL-1.1</div>
<div>+ *</div>
<div>+ * The contents of this file are subject to the Mozilla Public License</div>
<div>+ * Version 1.1 (the "License"); you may not use this file except in</div>
<div>+ * compliance with the License. You may obtain a copy of the License at</div>
<div>+ * http://www.mozilla.org/MPL/</div>
<div>+ *</div>
<div>+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY</div>
<div>+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for</div>
<div>+ * the specific language governing rights and limitations.</div>
<div>+ *</div>
<div>+ * The Original Code is the cairo graphics library.</div>
<div>+ *</div>
<div>+ * The Initial Developer of the Original Code is Red Hat, Inc.</div>
<div>+ *</div>
<div>+ * Contributor(s):</div>
<div>+ *<span class="Apple-tab-span" style="white-space:pre"> </span>Carl Worth <cworth@cworth.org></div>
<div>+ *<span class="Apple-tab-span" style="white-space:pre"> </span>Chris Wilson <chris@chris-wilson.co.uk></div>
<div>+ *<span class="Apple-tab-span" style="white-space:pre"> </span>Henry Song <henry.song@samsung.com></div>
<div>+ */</div>
<div>+</div>
<div>+#import "cairoint.h"</div>
<div>+</div>
<div>+#import "cairo-gl-private.h"</div>
<div>+</div>
<div>+#import "cairo-error-private.h"</div>
<div>+</div>
<div>+#import <dlfcn.h></div>
<div>+#import <stdlib.h></div>
<div>+#import <string.h></div>
<div>+#import <AppKit/NSOpenGL.h></div>
<div>+#import <AppKit/NSOpenGLView.h></div>
<div>+</div>
<div>+/* XXX needs hooking into XCloseDisplay() */</div>
<div>+</div>
<div>+typedef struct _cairo_nsgl_context {</div>
<div>+    cairo_gl_context_t base;</div>
<div>+</div>
<div>+    NSOpenGLContext *context;</div>
<div>+</div>
<div>+} cairo_nsgl_context_t;</div>
<div>+</div>
<div>+typedef struct _cairo_nsgl_surface {</div>
<div>+    cairo_gl_surface_t base;</div>
<div>+    NSView *view;</div>
<div>+} cairo_nsgl_surface_t;</div>
<div>+</div>
<div>+static void *</div>
<div>+nsglGetProcAddress (const char *name)</div>
<div>+{</div>
<div>+    return dlsym (RTLD_DEFAULT, name);</div>
<div>+}</div>
<div>+</div>
<div>+static void</div>
<div>+_nsgl_acquire (void *abstract_ctx)</div>
<div>+{</div>
<div>+    cairo_nsgl_context_t *ctx = abstract_ctx;</div>
<div>+    </div>
<div>+    [ctx->context makeCurrentContext];</div>
<div>+}</div>
<div>+</div>
<div>+static void</div>
<div>+_nsgl_release (void *abstract_ctx)</div>
<div>+{</div>
<div>+    /* no-op */</div>
<div>+}</div>
<div>+</div>
<div>+static void</div>
<div>+_nsgl_make_current (void *abstract_ctx, cairo_gl_surface_t *abstract_surface)</div>
<div>+{</div>
<div>+    cairo_nsgl_context_t *ctx = abstract_ctx;</div>
<div>+    cairo_nsgl_surface_t *surface = (cairo_nsgl_surface_t *) abstract_surface;</div>
<div>+</div>
<div>+    /* Set the window as the target of our context. */</div>
<div>+    [ctx->context setView: surface->view];</div>
<div>+}</div>
<div>+</div>
<div>+static void</div>
<div>+_nsgl_swap_buffers (void *abstract_ctx,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>   cairo_gl_surface_t *abstract_surface)</div>
<div>+{</div>
<div>+    cairo_nsgl_context_t *ctx = abstract_ctx;</div>
<div>+    [ctx->context flushBuffer];</div>
<div>+}</div>
<div>+</div>
<div>+static void</div>
<div>+_nsgl_destroy (void *abstract_ctx)</div>
<div>+{</div>
<div>+    cairo_nsgl_context_t *ctx = abstract_ctx;</div>
<div>+</div>
<div>+    [ctx->context release];</div>
<div>+}</div>
<div>+</div>
<div>+cairo_device_t *</div>
<div>+cairo_nsgl_device_create (void *abstract_ctx)</div>
<div>+{</div>
<div>+    cairo_nsgl_context_t *ctx;</div>
<div>+    cairo_status_t status;</div>
<div>+    NSOpenGLContext *nsgl_ctx = (NSOpenGLContext *)abstract_ctx;</div>
<div>+</div>
<div>+    ctx = calloc (1, sizeof (cairo_nsgl_context_t));</div>
<div>+    if (unlikely (ctx == NULL))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);</div>
<div>+</div>
<div>+    [ctx->context makeCurrentContext];</div>
<div>+</div>
<div>+    ctx->context = [nsgl_ctx retain];</div>
<div>+</div>
<div>+    ctx->base.acquire = _nsgl_acquire;</div>
<div>+    ctx->base.release = _nsgl_release;</div>
<div>+    ctx->base.make_current = _nsgl_make_current;</div>
<div>+    ctx->base.swap_buffers = _nsgl_swap_buffers;</div>
<div>+    ctx->base.destroy = _nsgl_destroy;</div>
<div>+</div>
<div>+    status = _cairo_gl_dispatch_init (&ctx->base.dispatch,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>     (cairo_gl_get_proc_addr_func_t) nsglGetProcAddress);</div>
<div>+    if (unlikely (status)) {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>free (ctx);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return _cairo_gl_context_create_in_error (status);</div>
<div>+    }</div>
<div>+</div>
<div>+    status = _cairo_gl_context_init (&ctx->base);</div>
<div>+    if (unlikely (status)) {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>free (ctx);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return _cairo_gl_context_create_in_error (status);</div>
<div>+    }</div>
<div>+</div>
<div>+    ctx->base.release (ctx);</div>
<div>+</div>
<div>+    return &ctx->base.base;</div>
<div>+}</div>
<div>+</div>
<div>+void *</div>
<div>+cairo_nsgl_device_get_context (cairo_device_t *device)</div>
<div>+{</div>
<div>+    cairo_nsgl_context_t *ctx;</div>
<div>+</div>
<div>+    if (device->backend->type != CAIRO_DEVICE_TYPE_GL) {</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>_cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH);</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return NULL;</div>
<div>+    }</div>
<div>+</div>
<div>+    ctx = (cairo_nsgl_context_t *) device;</div>
<div>+</div>
<div>+    return ctx->context;</div>
<div>+}</div>
<div>+</div>
<div>+cairo_surface_t *</div>
<div>+cairo_gl_surface_create_for_view (cairo_device_t<span class="Apple-tab-span" style="white-space:pre">
</span>*device,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> void<span class="Apple-tab-span" style="white-space:pre">
</span>*abstract_view,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> int<span class="Apple-tab-span" style="white-space:pre">
</span>width,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span> int<span class="Apple-tab-span" style="white-space:pre">
</span>height)</div>
<div>+{</div>
<div>+    cairo_nsgl_surface_t *surface;</div>
<div>+</div>
<div>+    if (unlikely (device->status))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return _cairo_surface_create_in_error (device->status);</div>
<div>+</div>
<div>+    if (device->backend->type != CAIRO_DEVICE_TYPE_GL)</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));</div>
<div>+</div>
<div>+    if (width <= 0 || height <= 0)</div>
<div>+        return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_INVALID_SIZE));</div>
<div>+</div>
<div>+    surface = calloc (1, sizeof (cairo_nsgl_surface_t));</div>
<div>+    if (unlikely (surface == NULL))</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));</div>
<div>+</div>
<div>+    _cairo_gl_surface_init (device, &surface->base,</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>   CAIRO_CONTENT_COLOR_ALPHA, width, height);</div>
<div>+    surface->view = (NSView *)abstract_view;</div>
<div>+</div>
<div>+    return &surface->base.base;</div>
<div>+}</div>
<div>diff --git a/test/Makefile.am b/test/Makefile.am</div>
<div>index 07826ff..1e148d7 100644</div>
<div>--- a/test/Makefile.am</div>
<div>+++ b/test/Makefile.am</div>
<div>@@ -71,6 +71,15 @@ endif</div>
<div> endif</div>
<div> test_sources += $(test)</div>
<div> </div>
<div>+if CAIRO_HAS_NSGL_FUNCTIONS</div>
<div>+cairo_nsgl_LIBS = \</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>-Xlinker -framework -Xlinker OpenGL \</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>-Xlinker -framework -Xlinker Appkit \</div>
<div>+<span class="Apple-tab-span" style="white-space:pre"> </span>-Xlinker -framework -Xlinker Foundation</div>
<div>+else</div>
<div>+cairo_nsgl_LIBS =</div>
<div>+endif</div>
<div>+</div>
<div> noinst_PROGRAMS = cairo-test-suite$(EXEEXT) # always build</div>
<div> </div>
<div> TESTS += cairo-test-suite$(EXEEXT)</div>
<div>@@ -84,6 +93,7 @@ cairo_test_suite_SOURCES = <span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(test_sources)<span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>cairo-test-constructors.c</div>
<div> cairo_test_suite_CFLAGS = $(AM_CFLAGS) $(real_pthread_CFLAGS) </div>
<div>+cairo_test_suite_LDFLAGS = $(cairo_nsgl_LIBS)</div>
<div> cairo_test_suite_LDADD = <span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(real_pthread_LIBS)<span class="Apple-tab-span" style="white-space:pre">
</span>\</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>$(top_builddir)/test/pdiff/libpdiff.la
<span class="Apple-tab-span" style="white-space:pre"></span>\</div>
<div>diff --git a/test/Makefile.sources b/test/Makefile.sources</div>
<div>index 1bf93e5..74a3623 100644</div>
<div>--- a/test/Makefile.sources</div>
<div>+++ b/test/Makefile.sources</div>
<div>@@ -390,7 +390,7 @@ ft_font_test_sources = \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>ft-text-vertical-layout-type3.c \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>ft-text-antialias-none.c</div>
<div> </div>
<div>-gl_surface_test_sources = \</div>
<div>+#gl_surface_test_sources = \</div>
<div> <span class="Apple-tab-span" style="white-space:pre"> </span>gl-surface-source.c</div>
<div> </div>
<div> quartz_surface_test_sources = quartz-surface-source.c</div>
<div>-- </div>
<div>1.8.0.1</div>
<div><br>
</div>
</div>
</body>
</html>