[cairo-commit] 2 commits - build/configure.ac.features configure.ac src/cairo-gl.h src/cairo-wgl-context.c src/cairo-win32-printing-surface.c src/cairo-win32-surface.c
Chris Wilson
ickle at kemper.freedesktop.org
Mon Jun 14 04:46:53 PDT 2010
build/configure.ac.features | 1
configure.ac | 9 +
src/cairo-gl.h | 16 ++
src/cairo-wgl-context.c | 253 +++++++++++++++++++++++++++++++++++++
src/cairo-win32-printing-surface.c | 9 -
src/cairo-win32-surface.c | 4
6 files changed, 285 insertions(+), 7 deletions(-)
New commits:
commit 505a0456d2498112155db7e7f275a14dc98f643e
Author: Zoxc <zoxc32 at gmail.com>
Date: Mon Jun 14 01:20:54 2010 +0200
gl: Added WGL context and surface.
diff --git a/build/configure.ac.features b/build/configure.ac.features
index 1e40de8..1473bd7 100644
--- a/build/configure.ac.features
+++ b/build/configure.ac.features
@@ -390,6 +390,7 @@ AC_DEFUN([CAIRO_REPORT],
echo " PNG functions: $use_png"
echo " GLEW functions: $use_glew"
echo " GLX functions: $use_glx"
+ echo " WGL functions: $use_wgl"
echo " EGL functions: $use_egl"
echo " X11-xcb functions: $use_xlib_xcb"
echo " XCB-drm functions: $use_xcb_drm"
diff --git a/configure.ac b/configure.ac
index dc54b58..fe262b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -348,6 +348,7 @@ CAIRO_ENABLE_SURFACE_BACKEND(gl, OpenGL, no, [
CAIRO_CFLAGS="$CAIRO_CFLAGS -I\$(top_srcdir)/src/glew"
fi
need_glx_functions=yes
+ need_wgl_functions=yes
need_egl_functions=yes
])
@@ -417,6 +418,14 @@ CAIRO_ENABLE_FUNCTIONS(glx, GLX, auto, [
fi
])
+CAIRO_ENABLE_FUNCTIONS(wgl, WGL, auto, [
+ if test "x$need_wgl_functions" = "xyes"; then
+ AC_CHECK_HEADER(windows.h,, [use_wgl="no (WGL headers not found)"])
+ else
+ use_wgl="no (not required by any backend)"
+ fi
+])
+
dnl ===========================================================================
any2ppm_cs=no
diff --git a/src/cairo-gl.h b/src/cairo-gl.h
index 7dc1fbd..7657a93 100644
--- a/src/cairo-gl.h
+++ b/src/cairo-gl.h
@@ -75,6 +75,22 @@ cairo_gl_surface_create_for_window (cairo_device_t *device,
int width, int height);
#endif
+#if CAIRO_HAS_WGL_FUNCTIONS
+#include <windows.h>
+
+cairo_public cairo_device_t *
+cairo_wgl_device_create (HGLRC rc);
+
+cairo_public HGLRC
+cairo_wgl_device_get_context (cairo_device_t *device);
+
+cairo_public cairo_surface_t *
+cairo_gl_surface_create_for_dc (cairo_device_t *device,
+ HDC dc,
+ int width,
+ int height);
+#endif
+
#if CAIRO_HAS_EGL_FUNCTIONS
#include <EGL/egl.h>
diff --git a/src/cairo-wgl-context.c b/src/cairo-wgl-context.c
new file mode 100644
index 0000000..e8b8ec6
--- /dev/null
+++ b/src/cairo-wgl-context.c
@@ -0,0 +1,253 @@
+/* cairo - a vector graphics library with display and print output
+ *
+ * Copyright © 2009 Eric Anholt
+ * Copyright © 2009 Chris Wilson
+ * Copyright © 2005 Red Hat, Inc
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it either under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation
+ * (the "LGPL") or, at your option, under the terms of the Mozilla
+ * Public License Version 1.1 (the "MPL"). If you do not alter this
+ * notice, a recipient may use your version of this file under either
+ * the MPL or the LGPL.
+ *
+ * You should have received a copy of the LGPL along with this library
+ * in the file COPYING-LGPL-2.1; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
+ * You should have received a copy of the MPL along with this library
+ * in the file COPYING-MPL-1.1
+ *
+ * The contents of this file are subject to the Mozilla Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
+ * OF ANY KIND, either express or implied. See the LGPL or the MPL for
+ * the specific language governing rights and limitations.
+ *
+ * The Original Code is the cairo graphics library.
+ *
+ * The Initial Developer of the Original Code is Red Hat, Inc.
+ *
+ * Contributor(s):
+ * Carl Worth <cworth at cworth.org>
+ * Chris Wilson <chris at chris-wilson.co.uk>
+ * Zoxc <zoxc32 at gmail.com>
+ */
+
+#include "cairoint.h"
+
+#include "cairo-gl-private.h"
+
+#include "cairo-error-private.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+typedef struct _cairo_wgl_context {
+ cairo_gl_context_t base;
+
+ HDC dummy_dc;
+ HWND dummy_hwnd;
+ HGLRC rc;
+
+ HDC prev_dc;
+ HGLRC prev_rc;
+} cairo_wgl_context_t;
+
+typedef struct _cairo_wgl_surface {
+ cairo_gl_surface_t base;
+
+ HDC dc;
+} cairo_wgl_surface_t;
+
+static void
+_wgl_acquire (void *abstract_ctx)
+{
+ cairo_wgl_context_t *ctx = abstract_ctx;
+
+ HDC current_dc;
+
+ ctx->prev_dc = wglGetCurrentDC ();
+ ctx->prev_rc = wglGetCurrentContext ();
+
+ if (ctx->base.current_target == NULL ||
+ _cairo_gl_surface_is_texture (ctx->base.current_target))
+ {
+ current_dc = ctx->dummy_dc;
+ }
+ else
+ {
+ cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) ctx->base.current_target;
+ current_dc = surface->dc;
+ }
+
+ if (ctx->prev_dc != current_dc ||
+ (ctx->prev_rc != ctx->rc &&
+ current_dc != ctx->dummy_dc))
+ {
+ wglMakeCurrent (current_dc, ctx->rc);
+ }
+}
+
+static void
+_wgl_make_current (void *abstract_ctx, cairo_gl_surface_t *abstract_surface)
+{
+ cairo_wgl_context_t *ctx = abstract_ctx;
+ cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) abstract_surface;
+
+ /* Set the window as the target of our context. */
+ wglMakeCurrent (surface->dc, ctx->rc);
+}
+
+static void
+_wgl_release (void *abstract_ctx)
+{
+ cairo_wgl_context_t *ctx = abstract_ctx;
+
+ if (ctx->prev_dc != wglGetCurrentDC () ||
+ ctx->prev_rc != wglGetCurrentContext ())
+ {
+ wglMakeCurrent (ctx->prev_dc,
+ ctx->prev_rc);
+ }
+}
+
+static void
+_wgl_swap_buffers (void *abstract_ctx,
+ cairo_gl_surface_t *abstract_surface)
+{
+ cairo_wgl_surface_t *surface = (cairo_wgl_surface_t *) abstract_surface;
+
+ SwapBuffers (surface->dc);
+}
+
+static void
+_wgl_destroy (void *abstract_ctx)
+{
+ cairo_wgl_context_t *ctx = abstract_ctx;
+
+ if (ctx->dummy_dc != 0) {
+ ReleaseDC (ctx->dummy_hwnd, ctx->dummy_dc);
+ DestroyWindow (ctx->dummy_hwnd);
+ CloseHandle (ctx->dummy_hwnd);
+ }
+
+ wglMakeCurrent (0, 0);
+}
+
+static cairo_status_t
+_wgl_dummy_ctx (cairo_wgl_context_t *ctx)
+{
+ WNDCLASSEXA wincl;
+ PIXELFORMATDESCRIPTOR pfd;
+ int format;
+ HDC dc;
+
+ ZeroMemory (&wincl, sizeof (WNDCLASSEXA));
+ wincl.cbSize = sizeof (WNDCLASSEXA);
+ wincl.hInstance = GetModuleHandle (0);
+ wincl.lpszClassName = "cairo_wgl_context_dummy";
+ wincl.lpfnWndProc = DefWindowProcA;
+ wincl.style = CS_OWNDC;
+
+ RegisterClassExA (&wincl);
+
+ ctx->dummy_hwnd = CreateWindow ("cairo_wgl_context_dummy", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
+ ctx->dummy_dc = GetDC (ctx->dummy_hwnd);
+
+ ZeroMemory (&pfd, sizeof (PIXELFORMATDESCRIPTOR));
+ pfd.nSize = sizeof (PIXELFORMATDESCRIPTOR);
+ pfd.nVersion = 1;
+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
+ pfd.iPixelType = PFD_TYPE_RGBA;
+ pfd.cColorBits = 24;
+ pfd.cDepthBits = 16;
+ pfd.iLayerType = PFD_MAIN_PLANE;
+
+ format = ChoosePixelFormat (ctx->dummy_dc, &pfd);
+ SetPixelFormat (ctx->dummy_dc, format, &pfd);
+
+ wglMakeCurrent(ctx->dummy_dc, ctx->rc);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+cairo_device_t *
+cairo_wgl_device_create (HGLRC rc)
+{
+ cairo_wgl_context_t *ctx;
+ cairo_status_t status;
+
+ ctx = calloc (1, sizeof (cairo_wgl_context_t));
+ if (unlikely (ctx == NULL))
+ return _cairo_gl_context_create_in_error (CAIRO_STATUS_NO_MEMORY);
+
+ ctx->rc = rc;
+ ctx->prev_dc = 0;
+ ctx->prev_rc = 0;
+
+ status = _wgl_dummy_ctx (ctx);
+ if (unlikely (status)) {
+ free (ctx);
+ return _cairo_gl_context_create_in_error (status);
+ }
+
+ ctx->base.acquire = _wgl_acquire;
+ ctx->base.release = _wgl_release;
+ ctx->base.make_current = _wgl_make_current;
+ ctx->base.swap_buffers = _wgl_swap_buffers;
+ ctx->base.destroy = _wgl_destroy;
+
+ status = _cairo_gl_context_init (&ctx->base);
+ if (unlikely (status)) {
+ free (ctx);
+ return _cairo_gl_context_create_in_error (status);
+ }
+
+ ctx->base.release (ctx);
+
+ return &ctx->base.base;
+}
+
+HGLRC
+cairo_wgl_device_get_context (cairo_device_t *device)
+{
+ cairo_wgl_context_t *ctx;
+
+ if (device->backend->type != CAIRO_DEVICE_TYPE_GL) {
+ _cairo_error_throw (CAIRO_STATUS_DEVICE_TYPE_MISMATCH);
+ return NULL;
+ }
+
+ ctx = (cairo_wgl_context_t *) device;
+
+ return ctx->rc;
+}
+
+cairo_surface_t *
+cairo_gl_surface_create_for_dc (cairo_device_t *device,
+ HDC dc,
+ int width,
+ int height)
+{
+ cairo_wgl_surface_t *surface;
+
+ if (unlikely (device->status))
+ return _cairo_surface_create_in_error (device->status);
+
+ if (device->backend->type != CAIRO_DEVICE_TYPE_GL)
+ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_SURFACE_TYPE_MISMATCH));
+
+ surface = calloc (1, sizeof (cairo_wgl_surface_t));
+ if (unlikely (surface == NULL))
+ return _cairo_surface_create_in_error (_cairo_error (CAIRO_STATUS_NO_MEMORY));
+
+ _cairo_gl_surface_init (device, &surface->base,
+ CAIRO_CONTENT_COLOR_ALPHA, width, height);
+ surface->dc = dc;
+
+ return &surface->base.base;
+}
commit fd6c38b9e006feefa20ce4f54d3108dad51c828d
Author: Zoxc <zoxc32 at gmail.com>
Date: Mon Jun 14 01:04:10 2010 +0200
win32: Fixed compile errors in Windows backend.
diff --git a/src/cairo-win32-printing-surface.c b/src/cairo-win32-printing-surface.c
index d6868b2..9f9f568 100644
--- a/src/cairo-win32-printing-surface.c
+++ b/src/cairo-win32-printing-surface.c
@@ -285,9 +285,9 @@ _cairo_win32_printing_surface_init_clear_color (cairo_win32_surface_t *surface,
cairo_solid_pattern_t *color)
{
if (surface->content == CAIRO_CONTENT_COLOR_ALPHA)
- _cairo_pattern_init_solid (color, CAIRO_COLOR_WHITE, CAIRO_CONTENT_COLOR);
+ _cairo_pattern_init_solid (color, CAIRO_COLOR_WHITE);
else
- _cairo_pattern_init_solid (color, CAIRO_COLOR_BLACK, CAIRO_CONTENT_COLOR);
+ _cairo_pattern_init_solid (color, CAIRO_COLOR_BLACK);
}
static COLORREF
@@ -677,8 +677,7 @@ _cairo_win32_printing_surface_paint_image_pattern (cairo_win32_surface_t *surf
}
_cairo_pattern_init_solid (&background_pattern,
- background_color,
- CAIRO_CONTENT_COLOR);
+ background_color);
status = _cairo_surface_paint (opaque_surface,
CAIRO_OPERATOR_SOURCE,
&background_pattern.base,
@@ -788,7 +787,7 @@ _cairo_win32_printing_surface_paint_surface_pattern (cairo_win32_surface_t *su
}
static void
-vertex_set_color (TRIVERTEX *vert, cairo_color_t *color)
+vertex_set_color (TRIVERTEX *vert, cairo_color_stop_t *color)
{
/* MSDN says that the range here is 0x0000 .. 0xff00;
* that may well be a typo, but just chop the low bits
diff --git a/src/cairo-win32-surface.c b/src/cairo-win32-surface.c
index ba4d24e..cebf83f 100644
--- a/src/cairo-win32-surface.c
+++ b/src/cairo-win32-surface.c
@@ -96,11 +96,11 @@ _cairo_win32_print_gdi_error (const char *context)
NULL,
last_error,
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPSTR) &lpMsgBuf,
+ (LPWSTR) &lpMsgBuf,
0, NULL)) {
fprintf (stderr, "%s: Unknown GDI error", context);
} else {
- fwprintf (stderr, "%S: %s", context, (char *)lpMsgBuf);
+ fwprintf (stderr, L"%s: %S", context, (wchar_t *)lpMsgBuf);
LocalFree (lpMsgBuf);
}
More information about the cairo-commit
mailing list