mirror of
https://github.com/gnustep/libs-back.git
synced 2025-04-22 07:21:02 +00:00
* Source/cairo/GNUmakefile:
* Source/cairo/CairoContext.m: * Source/cairo/CairoSurface.m: * Source/cairo/XGCairoModernSurface.m: * Headers/cairo/XGCairoModernSurface.h: * Headers/cairo/CairoSurface.h: New cairo surface which uses cairo_surface_create_similar to create a back buffer which has an alpha channel, even if the X server doesn't support surfaces with alpha. This new surface is also made the default since this seems to be the recommended way to double buffer with cairo. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@33978 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
30b2c2f88f
commit
85cc4d778c
7 changed files with 222 additions and 4 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2011-10-13 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/cairo/GNUmakefile:
|
||||
* Source/cairo/CairoContext.m:
|
||||
* Source/cairo/CairoSurface.m:
|
||||
* Source/cairo/XGCairoModernSurface.m:
|
||||
* Headers/cairo/XGCairoModernSurface.h:
|
||||
* Headers/cairo/CairoSurface.h: New cairo surface which uses
|
||||
cairo_surface_create_similar to create a back buffer which
|
||||
has an alpha channel, even if the X server doesn't support
|
||||
surfaces with alpha. This new surface is also made the default
|
||||
since this seems to be the recommended way to double buffer
|
||||
with cairo.
|
||||
|
||||
2011-09-18 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/cairo/CairoContext.m: revert the last change for now
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
|
||||
- (cairo_surface_t *) surface;
|
||||
|
||||
- (void) handleExposeRect: (NSRect)rect;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
38
Headers/cairo/XGCairoModernSurface.h
Normal file
38
Headers/cairo/XGCairoModernSurface.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
|
||||
Author: Eric Wasylishen <ewasylishen@gmail.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 2 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 XGCairoXModernSurface_h
|
||||
#define XGCairoXModernSurface_h
|
||||
|
||||
#include "cairo/CairoSurface.h"
|
||||
|
||||
@interface XGCairoModernSurface : CairoSurface
|
||||
{
|
||||
@private
|
||||
cairo_surface_t *_windowSurface;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
|
@ -47,8 +47,10 @@
|
|||
# else
|
||||
//# define _CAIRO_SURFACE_CLASSNAME XGCairoSurface
|
||||
//# include "cairo/XGCairoSurface.h"
|
||||
# define _CAIRO_SURFACE_CLASSNAME XGCairoXImageSurface
|
||||
# include "cairo/XGCairoXImageSurface.h"
|
||||
//# define _CAIRO_SURFACE_CLASSNAME XGCairoXImageSurface
|
||||
//# include "cairo/XGCairoXImageSurface.h"
|
||||
# define _CAIRO_SURFACE_CLASSNAME XGCairoModernSurface
|
||||
# include "cairo/XGCairoModernSurface.h"
|
||||
# endif /* USE_GLITZ */
|
||||
# include "x11/XGServerWindow.h"
|
||||
# include "x11/XWindowBuffer.h"
|
||||
|
@ -103,6 +105,7 @@
|
|||
|
||||
- (void) flushGraphics
|
||||
{
|
||||
// FIXME: Why is this here? When is it called?
|
||||
#if BUILD_SERVER == SERVER_x11
|
||||
XFlush([(XGServer *)server xDisplay]);
|
||||
#endif // BUILD_SERVER = SERVER_x11
|
||||
|
@ -113,7 +116,16 @@
|
|||
/* Private backend methods */
|
||||
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
|
||||
{
|
||||
[(XWindowBuffer *)driver _exposeRect: rect];
|
||||
if ([(id)driver isKindOfClass: [XWindowBuffer class]])
|
||||
{
|
||||
// For XGCairoXImageSurface
|
||||
[(XWindowBuffer *)driver _exposeRect: rect];
|
||||
}
|
||||
else if ([(id)driver isKindOfClass: [CairoSurface class]])
|
||||
{
|
||||
// For XGCairoModernSurface
|
||||
[(CairoSurface *)driver handleExposeRect: rect];
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef XSHM
|
||||
|
|
|
@ -65,4 +65,8 @@
|
|||
return _surface;
|
||||
}
|
||||
|
||||
- (void) handleExposeRect: (NSRect)rect
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -42,7 +42,7 @@ ifeq ($(BUILD_SERVER),x11)
|
|||
ifeq ($(WITH_GLITZ),yes)
|
||||
cairo_OBJC_FILES += XGCairoGlitzSurface.m
|
||||
else
|
||||
cairo_OBJC_FILES += XGCairoSurface.m XGCairoXImageSurface.m
|
||||
cairo_OBJC_FILES += XGCairoSurface.m XGCairoXImageSurface.m XGCairoModernSurface.m
|
||||
endif
|
||||
else
|
||||
ifeq ($(BUILD_GRAPHICS),cairo)
|
||||
|
|
148
Source/cairo/XGCairoModernSurface.m
Normal file
148
Source/cairo/XGCairoModernSurface.m
Normal file
|
@ -0,0 +1,148 @@
|
|||
/*
|
||||
Copyright (C) 2011 Free Software Foundation, Inc.
|
||||
|
||||
Author: Eric Wasylishen <ewasylishen@gmail.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 2 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 "config.h"
|
||||
#include "x11/XGServer.h"
|
||||
#include "x11/XGServerWindow.h"
|
||||
#include "cairo/XGCairoModernSurface.h"
|
||||
#include <cairo-xlib.h>
|
||||
|
||||
#define GSWINDEVICE ((gswindow_device_t *)gsDevice)
|
||||
|
||||
@implementation XGCairoModernSurface
|
||||
|
||||
- (id) initWithDevice: (void *)device
|
||||
{
|
||||
cairo_surface_t *windowsurface;
|
||||
|
||||
gsDevice = device;
|
||||
|
||||
// Create a cairo xlib surface for the window
|
||||
{
|
||||
Display *dpy = GSWINDEVICE->display;
|
||||
Visual *visual;
|
||||
XWindowAttributes attributes;
|
||||
|
||||
if (!XGetWindowAttributes(dpy, GSWINDEVICE->ident, &attributes))
|
||||
{
|
||||
visual = DefaultVisual(dpy, DefaultScreen(dpy));
|
||||
}
|
||||
else
|
||||
{
|
||||
visual = attributes.visual;
|
||||
}
|
||||
|
||||
windowsurface = cairo_xlib_surface_create(GSWINDEVICE->display,
|
||||
GSWINDEVICE->ident,
|
||||
visual,
|
||||
GSWINDEVICE->xframe.size.width,
|
||||
GSWINDEVICE->xframe.size.height);
|
||||
}
|
||||
|
||||
|
||||
if (GSWINDEVICE->type == NSBackingStoreNonretained)
|
||||
{
|
||||
// Don't double-buffer:
|
||||
// use the window surface as the drawing destination.
|
||||
|
||||
_surface = windowsurface;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do double-buffer:
|
||||
// Create a similar surface to the window which supports alpha
|
||||
|
||||
// Ask XGServerWindow to call +[CairoContext handleExposeRect:forDriver:]
|
||||
// to let us handle the back buffer -> front buffer copy using cairo.
|
||||
GSWINDEVICE->gdriverProtocol |= GDriverHandlesExpose | GDriverHandlesBacking;
|
||||
GSWINDEVICE->gdriver = self;
|
||||
|
||||
_windowSurface = windowsurface;
|
||||
_surface = cairo_surface_create_similar(windowsurface,
|
||||
CAIRO_CONTENT_COLOR_ALPHA,
|
||||
GSWINDEVICE->xframe.size.width,
|
||||
GSWINDEVICE->xframe.size.height);
|
||||
|
||||
/*NSLog(@"Window surface type %d, back buffer type %d, w %d h %d",
|
||||
(int) cairo_surface_get_type(_windowSurface),
|
||||
(int) cairo_surface_get_type(_surface),
|
||||
(int) GSWINDEVICE->xframe.size.width,
|
||||
(int) GSWINDEVICE->xframe.size.height);
|
||||
*/
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
if (_windowSurface != NULL)
|
||||
{
|
||||
cairo_surface_destroy(_windowSurface);
|
||||
}
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSSize) size
|
||||
{
|
||||
return GSWINDEVICE->xframe.size;
|
||||
}
|
||||
|
||||
- (void) handleExposeRect: (NSRect)rect
|
||||
{
|
||||
cairo_t *windowCtx = cairo_create(_windowSurface);
|
||||
|
||||
double backupOffsetX, backupOffsetY;
|
||||
|
||||
// Temporairly cancel the device offset on the back buffer since
|
||||
// we want to work with raw X11 pixel coordinates
|
||||
|
||||
cairo_surface_get_device_offset(_surface, &backupOffsetX, &backupOffsetY);
|
||||
cairo_surface_set_device_offset(_surface, 0, 0);
|
||||
|
||||
// Copy the desired rectangle from the back buffer to the
|
||||
// front buffer
|
||||
|
||||
// FIXME: should round
|
||||
cairo_rectangle(windowCtx, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||
cairo_clip(windowCtx);
|
||||
cairo_set_source_surface(windowCtx, _surface, 0, 0);
|
||||
cairo_set_operator(windowCtx, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_paint(windowCtx);
|
||||
|
||||
// Debugging
|
||||
// cairo_reset_clip(windowCtx);
|
||||
// cairo_set_source_rgba(windowCtx, 1.0, 0.0, 0.0, 0.5);
|
||||
// cairo_rectangle(windowCtx, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
|
||||
// cairo_stroke(windowCtx);
|
||||
// NSLog(@"Exposing rect %@ with cairo. Status: '%s'", NSStringFromRect(rect), cairo_status_to_string(cairo_status(windowCtx)));
|
||||
|
||||
cairo_destroy(windowCtx);
|
||||
|
||||
// Restore device offset
|
||||
cairo_surface_set_device_offset(_surface, backupOffsetX, backupOffsetY);
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in a new issue