mirror of
https://github.com/gnustep/libs-back.git
synced 2025-02-23 20:01:22 +00:00
Experimental Cairo and Cairo/Glitz backends on win32
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@26189 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5a575c4b39
commit
201d3bf367
6 changed files with 371 additions and 22 deletions
43
Headers/cairo/Win32CairoGlitzSurface.h
Normal file
43
Headers/cairo/Win32CairoGlitzSurface.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
Win32CairoGlitzSurface.h
|
||||||
|
|
||||||
|
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
March 2nd, 2008
|
||||||
|
Author: Xavier Glattard <xavier.glattard@free.fr>
|
||||||
|
|
||||||
|
This file is part of GNUstep.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; see the file COPYING.LIB.
|
||||||
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||||
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Win32CairoGlitzSurface_h
|
||||||
|
#define Win32CairoGlitzSurface_h
|
||||||
|
|
||||||
|
#include "win32/WIN32Server.h"
|
||||||
|
|
||||||
|
#include "cairo/CairoSurface.h"
|
||||||
|
|
||||||
|
@interface Win32CairoGlitzSurface : CairoSurface
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
43
Headers/cairo/Win32CairoSurface.h
Normal file
43
Headers/cairo/Win32CairoSurface.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
Win32CairoSurface.h
|
||||||
|
|
||||||
|
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
March 2nd, 2008
|
||||||
|
Author: Xavier Glattard <xavier.glattard@free.fr>
|
||||||
|
|
||||||
|
This file is part of GNUstep.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; see the file COPYING.LIB.
|
||||||
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||||
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef Win32CairoSurface_h
|
||||||
|
#define Win32CairoSurface_h
|
||||||
|
|
||||||
|
#include "win32/WIN32Server.h"
|
||||||
|
|
||||||
|
#include "cairo/CairoSurface.h"
|
||||||
|
|
||||||
|
@interface Win32CairoSurface : CairoSurface
|
||||||
|
{
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -32,21 +32,36 @@
|
||||||
#include "cairo/CairoPDFSurface.h"
|
#include "cairo/CairoPDFSurface.h"
|
||||||
#include "cairo/CairoFontInfo.h"
|
#include "cairo/CairoFontInfo.h"
|
||||||
#include "cairo/CairoFontEnumerator.h"
|
#include "cairo/CairoFontEnumerator.h"
|
||||||
#include "x11/XGServer.h"
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef USE_GLITZ
|
|
||||||
#include "cairo/XGCairoGlitzSurface.h"
|
|
||||||
#else
|
|
||||||
#include "cairo/XGCairoSurface.h"
|
|
||||||
#include "cairo/XGCairoXImageSurface.h"
|
|
||||||
#include "x11/XGServerWindow.h"
|
|
||||||
#include "x11/XWindowBuffer.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CGSTATE ((CairoGState *)gstate)
|
#define CGSTATE ((CairoGState *)gstate)
|
||||||
|
|
||||||
@class XWindowBuffer;
|
#if BUILD_SERVER == SERVER_x11
|
||||||
|
# include "x11/XGServer.h"
|
||||||
|
# ifdef USE_GLITZ
|
||||||
|
# define _CAIRO_SURFACE_CLASSNAME XGCairoGlitzSurface
|
||||||
|
# include "cairo/XGCairoGlitzSurface.h"
|
||||||
|
# else
|
||||||
|
//# define _CAIRO_SURFACE_CLASSNAME XGCairoSurface
|
||||||
|
//# include "cairo/XGCairoSurface.h"
|
||||||
|
# define _CAIRO_SURFACE_CLASSNAME XGCairoXImageSurface
|
||||||
|
# include "cairo/XGCairoXImageSurface.h"
|
||||||
|
# endif /* USE_GLITZ */
|
||||||
|
# include "x11/XGServerWindow.h"
|
||||||
|
# include "x11/XWindowBuffer.h"
|
||||||
|
#elif BUILD_SERVER == SERVER_win32
|
||||||
|
# include <windows.h>
|
||||||
|
# ifdef USE_GLITZ
|
||||||
|
# define _CAIRO_SURFACE_CLASSNAME Win32CairoGlitzSurface
|
||||||
|
# include "cairo/Win32CairoGlitzSurface.h"
|
||||||
|
# else
|
||||||
|
# define _CAIRO_SURFACE_CLASSNAME Win32CairoSurface
|
||||||
|
# include "cairo/Win32CairoSurface.h"
|
||||||
|
# endif /* USE_GLITZ */
|
||||||
|
#else
|
||||||
|
# error Invalid server for Cairo backend : non implemented
|
||||||
|
#endif /* BUILD_SERVER */
|
||||||
|
|
||||||
|
|
||||||
@implementation CairoContext
|
@implementation CairoContext
|
||||||
|
|
||||||
|
@ -70,9 +85,13 @@
|
||||||
|
|
||||||
- (void) flushGraphics
|
- (void) flushGraphics
|
||||||
{
|
{
|
||||||
|
#if BUILD_SERVER == SERVER_x11
|
||||||
XFlush([(XGServer *)server xDisplay]);
|
XFlush([(XGServer *)server xDisplay]);
|
||||||
|
#endif // BUILD_SERVER = SERVER_x11
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILD_SERVER == SERVER_x11
|
||||||
|
|
||||||
/* Private backend methods */
|
/* Private backend methods */
|
||||||
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
|
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
|
||||||
{
|
{
|
||||||
|
@ -91,7 +110,9 @@
|
||||||
[XWindowBuffer _gotShmCompletion: d];
|
[XWindowBuffer _gotShmCompletion: d];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // XSHM
|
||||||
|
|
||||||
|
#endif // BUILD_SERVER = SERVER_x11
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -112,12 +133,7 @@
|
||||||
{
|
{
|
||||||
CairoSurface *surface;
|
CairoSurface *surface;
|
||||||
|
|
||||||
#ifdef USE_GLITZ
|
surface = [[_CAIRO_SURFACE_CLASSNAME alloc] initWithDevice: device];
|
||||||
surface = [[XGCairoGlitzSurface alloc] initWithDevice: device];
|
|
||||||
#else
|
|
||||||
//surface = [[XGCairoSurface alloc] initWithDevice: device];
|
|
||||||
surface = [[XGCairoXImageSurface alloc] initWithDevice: device];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[CGSTATE GSSetSurface: surface : x : y];
|
[CGSTATE GSSetSurface: surface : x : y];
|
||||||
}
|
}
|
||||||
|
@ -166,3 +182,5 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
#undef _CAIRO_SURFACE_CLASSNAME
|
||||||
|
|
|
@ -38,13 +38,25 @@ cairo_OBJC_FILES = CairoSurface.m \
|
||||||
CairoFaceInfo.m \
|
CairoFaceInfo.m \
|
||||||
CairoPSSurface.m \
|
CairoPSSurface.m \
|
||||||
CairoPDFSurface.m \
|
CairoPDFSurface.m \
|
||||||
XGCairoSurface.m \
|
|
||||||
XGCairoXImageSurface.m
|
|
||||||
|
|
||||||
ifeq ($(WITH_GLITZ),yes)
|
ifeq ($(BUILD_SERVER),x11)
|
||||||
cairo_OBJC_FILES += XGCairoGlitzSurface.m
|
ifeq ($(WITH_GLITZ),yes)
|
||||||
|
cairo_OBJC_FILES += XGCairoGlitzSurface.m
|
||||||
|
else
|
||||||
|
cairo_OBJC_FILES += XGCairoSurface.m XGCairoXImageSurface.m
|
||||||
|
endif
|
||||||
|
else
|
||||||
|
ifeq ($(BUILD_GRAPHICS),cairo)
|
||||||
|
ifeq ($(WITH_GLITZ),yes)
|
||||||
|
cairo_OBJC_FILES += Win32CairoGlitzSurface.m
|
||||||
|
else
|
||||||
|
cairo_OBJC_FILES += Win32CairoSurface.m
|
||||||
|
# Win32CairoXImageSurface.m
|
||||||
|
endif
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
cairo_OBJC_FILES +=
|
||||||
|
|
||||||
-include GNUmakefile.preamble
|
-include GNUmakefile.preamble
|
||||||
|
|
||||||
|
|
166
Source/cairo/Win32CairoGlitzSurface.m
Normal file
166
Source/cairo/Win32CairoGlitzSurface.m
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
/*
|
||||||
|
Win32CairoGlitzSurface.m
|
||||||
|
|
||||||
|
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Author: Xavier Glattard <xavier.glattard@online.fr>
|
||||||
|
Based on the work of:
|
||||||
|
Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
Banlu Kemiyatorn <object at gmail dot com>
|
||||||
|
|
||||||
|
This file is part of GNUstep.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; see the file COPYING.LIB.
|
||||||
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||||
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cairo/Win32CairoGlitzSurface.h"
|
||||||
|
#include <cairo-glitz.h>
|
||||||
|
#include <glitz-wgl.h>
|
||||||
|
|
||||||
|
#define GSWINDEVICE ((HWND)gsDevice)
|
||||||
|
|
||||||
|
@implementation Win32CairoGlitzSurface
|
||||||
|
|
||||||
|
- (id) initWithDevice: (void *)device
|
||||||
|
{
|
||||||
|
WIN_INTERN *win;
|
||||||
|
|
||||||
|
static BOOL first_time = YES;
|
||||||
|
|
||||||
|
unsigned long mask = 0;
|
||||||
|
glitz_drawable_format_t dtempl;
|
||||||
|
|
||||||
|
//static
|
||||||
|
glitz_drawable_format_t *dformat = NULL;
|
||||||
|
static unsigned count = 0;
|
||||||
|
glitz_drawable_t *drawable = NULL;
|
||||||
|
glitz_format_t *format = NULL;
|
||||||
|
glitz_surface_t *surface = NULL;
|
||||||
|
RECT sz;
|
||||||
|
|
||||||
|
count++;
|
||||||
|
|
||||||
|
gsDevice = device;
|
||||||
|
GetClientRect(GSWINDEVICE,&sz);
|
||||||
|
win = (WIN_INTERN *)GetWindowLong(GSWINDEVICE, GWL_USERDATA);
|
||||||
|
|
||||||
|
if(first_time)
|
||||||
|
{
|
||||||
|
NSLog(@"Win32CairoGlitzSurface : %d (%d) : glitz_wgl_init",__LINE__,count);
|
||||||
|
glitz_wgl_init(NULL);
|
||||||
|
first_time=NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
//NSLog(@"Win32CairoGlitzSurface : init window %d (%d,%d-%d,%d)",GSWINDEVICE,sz.left,sz.top,sz.right,sz.bottom);
|
||||||
|
|
||||||
|
//if(!dformat)
|
||||||
|
{
|
||||||
|
dtempl.samples = 1;
|
||||||
|
mask |= GLITZ_FORMAT_SAMPLES_MASK;
|
||||||
|
dtempl.color.red_size = 8;
|
||||||
|
dtempl.color.green_size = 8;
|
||||||
|
dtempl.color.blue_size = 8;
|
||||||
|
dtempl.color.alpha_size = 8;
|
||||||
|
dtempl.color.fourcc = GLITZ_FOURCC_RGB;
|
||||||
|
mask |= GLITZ_FORMAT_FOURCC_MASK
|
||||||
|
| GLITZ_FORMAT_RED_SIZE_MASK
|
||||||
|
| GLITZ_FORMAT_GREEN_SIZE_MASK
|
||||||
|
| GLITZ_FORMAT_BLUE_SIZE_MASK
|
||||||
|
| GLITZ_FORMAT_ALPHA_SIZE_MASK;
|
||||||
|
|
||||||
|
dtempl.doublebuffer = 0;
|
||||||
|
mask |= GLITZ_FORMAT_DOUBLEBUFFER_MASK;
|
||||||
|
|
||||||
|
if(win && win->useHDC)
|
||||||
|
{
|
||||||
|
HGDIOBJ old;
|
||||||
|
|
||||||
|
old = SelectObject(win->hdc, win->old);
|
||||||
|
DeleteObject(old);
|
||||||
|
DeleteDC(win->hdc);
|
||||||
|
win->hdc = NULL;
|
||||||
|
win->old = NULL;
|
||||||
|
win->useHDC = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
dformat = glitz_wgl_find_window_format(mask,&dtempl,0);
|
||||||
|
|
||||||
|
if (!dformat)
|
||||||
|
{
|
||||||
|
NSLog(@"Win32CairoGlitzSurface : %d (%d) : no format for drawable",__LINE__,count);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* NSLog (@"ID:%d RGBA:%d/%d/%d/%d D:%d St:%d DB:%d S:%d",
|
||||||
|
(int) dformat->id,
|
||||||
|
dformat->color.red_size,
|
||||||
|
dformat->color.green_size,
|
||||||
|
dformat->color.blue_size,
|
||||||
|
dformat->color.alpha_size,
|
||||||
|
dformat->depth_size,
|
||||||
|
dformat->stencil_size,
|
||||||
|
dformat->doublebuffer,
|
||||||
|
dformat->samples
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
drawable = glitz_wgl_create_drawable_for_window(
|
||||||
|
dformat,
|
||||||
|
GSWINDEVICE,
|
||||||
|
sz.right-sz.left,
|
||||||
|
sz.bottom-sz.top);
|
||||||
|
|
||||||
|
if (!drawable)
|
||||||
|
{
|
||||||
|
NSLog(@"Win32CairoGlitzSurface : %d (%d) : no glitz drawable",__LINE__,count);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
format = glitz_find_standard_format(drawable, GLITZ_STANDARD_ARGB32);
|
||||||
|
if (!format)
|
||||||
|
{
|
||||||
|
NSLog(@"Win32CairoGlitzSurface : %d (%d) : couldn't find ARGB32 surface format",__LINE__,GSWINDEVICE);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
surface = glitz_surface_create(
|
||||||
|
drawable, format,
|
||||||
|
sz.right-sz.left,
|
||||||
|
sz.bottom-sz.top,
|
||||||
|
0, NULL);
|
||||||
|
|
||||||
|
if (!surface)
|
||||||
|
{
|
||||||
|
NSLog(@"Win32CairoGlitzSurface : %d (%d) : couldn't create glitz surface",__LINE__,count);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
glitz_surface_attach(surface, drawable, GLITZ_DRAWABLE_BUFFER_FRONT_COLOR);
|
||||||
|
_surface = cairo_glitz_surface_create(surface);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSSize) size
|
||||||
|
{
|
||||||
|
RECT sz;
|
||||||
|
GetClientRect(GSWINDEVICE,&sz);
|
||||||
|
return NSMakeSize(sz.right-sz.left, sz.bottom-sz.top);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
67
Source/cairo/Win32CairoSurface.m
Normal file
67
Source/cairo/Win32CairoSurface.m
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
/*
|
||||||
|
Win32CairoSurface.m
|
||||||
|
|
||||||
|
Copyright (C) 2008 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
Author: Xavier Glattard <xavier.glattard@online.fr>
|
||||||
|
Based on the work of:
|
||||||
|
Banlu Kemiyatorn <object at gmail dot com>
|
||||||
|
|
||||||
|
This file is part of GNUstep.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; see the file COPYING.LIB.
|
||||||
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
||||||
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
|
Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "cairo/Win32CairoSurface.h"
|
||||||
|
#include <cairo-win32.h>
|
||||||
|
|
||||||
|
#define GSWINDEVICE ((HWND)gsDevice)
|
||||||
|
|
||||||
|
@implementation Win32CairoSurface
|
||||||
|
|
||||||
|
- (id) initWithDevice: (void *)device
|
||||||
|
{
|
||||||
|
HDC hDC;
|
||||||
|
WIN_INTERN *win;
|
||||||
|
gsDevice = device;
|
||||||
|
|
||||||
|
win = (WIN_INTERN *)GetWindowLong(GSWINDEVICE, GWL_USERDATA);
|
||||||
|
if(win && win->useHDC)
|
||||||
|
hDC = win->hdc;
|
||||||
|
else
|
||||||
|
hDC = GetDC(GSWINDEVICE);
|
||||||
|
|
||||||
|
if( !hDC )
|
||||||
|
{
|
||||||
|
NSLog(@"Win32CairoSurface : %d : no device context",__LINE__);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
_surface = cairo_win32_surface_create(hDC);
|
||||||
|
if(!(win && win->useHDC))
|
||||||
|
ReleaseDC(GSWINDEVICE,hDC);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSSize) size
|
||||||
|
{
|
||||||
|
RECT sz;
|
||||||
|
GetClientRect(GSWINDEVICE,&sz);
|
||||||
|
return NSMakeSize(sz.right-sz.left, sz.top-sz.bottom);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
Loading…
Reference in a new issue