2002-08-20 16:36:09 +00:00
|
|
|
/*
|
2005-01-11 19:23:54 +00:00
|
|
|
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
2002-08-27 10:11:20 +00:00
|
|
|
|
|
|
|
Author: Alexander Malmberg <alexander@malmberg.org>
|
2002-08-20 16:36:09 +00:00
|
|
|
|
|
|
|
This file is part of GNUstep.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 23:25:10 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
2002-08-20 16:36:09 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:12:46 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 23:25:10 +00:00
|
|
|
|
2002-08-20 16:36:09 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-10-29 23:25:10 +00:00
|
|
|
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.
|
2002-08-20 16:36:09 +00:00
|
|
|
*/
|
|
|
|
|
2007-11-29 20:34:25 +00:00
|
|
|
|
2007-03-22 16:54:47 +00:00
|
|
|
#include <Foundation/NSDebug.h>
|
2007-11-29 20:34:25 +00:00
|
|
|
#include <Foundation/NSDictionary.h>
|
2008-08-19 17:25:10 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
2013-08-09 14:21:15 +00:00
|
|
|
#include <AppKit/NSBitmapImageRep.h>
|
|
|
|
#include <AppKit/NSGraphics.h>
|
2002-08-20 16:36:09 +00:00
|
|
|
|
2002-08-26 14:03:04 +00:00
|
|
|
#include "ARTGState.h"
|
2002-08-20 16:36:09 +00:00
|
|
|
#include "blit.h"
|
|
|
|
#include "ftfont.h"
|
|
|
|
|
2003-01-26 19:07:53 +00:00
|
|
|
#ifndef RDS
|
2007-03-22 16:54:47 +00:00
|
|
|
#include "x11/XWindowBuffer.h"
|
2003-01-26 19:07:53 +00:00
|
|
|
#endif
|
2002-08-20 16:36:09 +00:00
|
|
|
|
2007-03-22 16:54:47 +00:00
|
|
|
@implementation ARTContext
|
|
|
|
|
|
|
|
+ (void)initializeBackend
|
|
|
|
{
|
2008-08-19 17:25:10 +00:00
|
|
|
float gamma;
|
|
|
|
|
2007-03-22 16:54:47 +00:00
|
|
|
NSDebugLLog(@"back-art",@"Initializing libart/freetype backend");
|
|
|
|
|
|
|
|
[NSGraphicsContext setDefaultContextClass: [ARTContext class]];
|
|
|
|
[FTFontInfo initializeBackend];
|
2008-08-19 17:25:10 +00:00
|
|
|
|
|
|
|
gamma = [[NSUserDefaults standardUserDefaults]
|
|
|
|
floatForKey: @"back-art-text-gamma"];
|
|
|
|
artcontext_setup_gamma(gamma);
|
2007-03-22 16:54:47 +00:00
|
|
|
}
|
2002-08-20 16:36:09 +00:00
|
|
|
|
2008-01-19 13:12:03 +00:00
|
|
|
+ (Class) GStateClass
|
2002-08-20 16:36:09 +00:00
|
|
|
{
|
2008-01-19 13:12:03 +00:00
|
|
|
return [ARTGState class];
|
|
|
|
}
|
2002-08-20 16:36:09 +00:00
|
|
|
|
2008-09-14 21:22:54 +00:00
|
|
|
- (void) setupDrawInfo: (void*)device
|
2008-01-19 13:12:03 +00:00
|
|
|
{
|
2008-09-14 21:22:54 +00:00
|
|
|
int bpp;
|
|
|
|
int red_mask, green_mask, blue_mask;
|
2003-01-26 19:07:53 +00:00
|
|
|
#ifdef RDS
|
2008-09-14 21:22:54 +00:00
|
|
|
RDSServer *s = (RDSServer *)server;
|
|
|
|
|
|
|
|
[s getPixelFormat: &bpp masks: &red_mask : &green_mask : &blue_mask];
|
2003-01-26 19:07:53 +00:00
|
|
|
#else
|
2008-09-14 21:22:54 +00:00
|
|
|
gswindow_device_t *gs_win;
|
2005-11-19 20:15:53 +00:00
|
|
|
|
2008-09-14 21:22:54 +00:00
|
|
|
gs_win = device;
|
|
|
|
[(XGServer *)server getForScreen: gs_win->screen pixelFormat: &bpp
|
|
|
|
masks: &red_mask : &green_mask : &blue_mask];
|
2003-01-26 19:07:53 +00:00
|
|
|
#endif
|
2008-09-14 21:22:54 +00:00
|
|
|
artcontext_setup_draw_info(&DI, red_mask, green_mask, blue_mask, bpp);
|
2002-08-20 16:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) flushGraphics
|
2007-03-22 16:54:47 +00:00
|
|
|
{
|
|
|
|
/* TODO: _really_ flush? (ie. force updates and wait for shm completion?) */
|
2003-01-26 19:07:53 +00:00
|
|
|
#ifndef RDS
|
2007-03-22 16:54:47 +00:00
|
|
|
XFlush([(XGServer *)server xDisplay]);
|
2003-01-26 19:07:53 +00:00
|
|
|
#endif
|
2002-08-20 16:36:09 +00:00
|
|
|
}
|
|
|
|
|
2003-01-26 19:07:53 +00:00
|
|
|
#ifndef RDS
|
2007-03-22 16:54:47 +00:00
|
|
|
+ (void) _gotShmCompletion: (Drawable)d
|
2002-08-20 16:36:09 +00:00
|
|
|
{
|
2007-03-22 16:54:47 +00:00
|
|
|
[XWindowBuffer _gotShmCompletion: d];
|
2002-08-20 16:36:09 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 16:54:47 +00:00
|
|
|
- (void) gotShmCompletion: (Drawable)d
|
2002-08-20 16:36:09 +00:00
|
|
|
{
|
2007-03-22 16:54:47 +00:00
|
|
|
[XWindowBuffer _gotShmCompletion: d];
|
2002-08-20 16:36:09 +00:00
|
|
|
}
|
2003-01-26 19:07:53 +00:00
|
|
|
#endif
|
2002-08-20 16:36:09 +00:00
|
|
|
|
|
|
|
/* Private backend methods */
|
2007-03-22 16:54:47 +00:00
|
|
|
+ (void) handleExposeRect: (NSRect)rect forDriver: (void *)driver
|
2002-08-20 16:36:09 +00:00
|
|
|
{
|
2005-11-19 20:15:53 +00:00
|
|
|
[(XWindowBuffer *)driver _exposeRect: rect];
|
2002-08-20 16:36:09 +00:00
|
|
|
}
|
|
|
|
|
2013-08-09 14:21:15 +00:00
|
|
|
- (BOOL) isCompatibleBitmap: (NSBitmapImageRep*)bitmap
|
|
|
|
{
|
|
|
|
NSString *colorSpaceName;
|
|
|
|
int numColors;
|
|
|
|
|
|
|
|
if ([bitmap bitmapFormat] != 0)
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (([bitmap bitsPerSample] > 8) &&
|
|
|
|
([bitmap bitsPerSample] != 16))
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
numColors = [bitmap samplesPerPixel] - ([bitmap hasAlpha] ? 1 : 0);
|
|
|
|
colorSpaceName = [bitmap colorSpaceName];
|
|
|
|
if ([colorSpaceName isEqualToString: NSDeviceRGBColorSpace] ||
|
|
|
|
[colorSpaceName isEqualToString: NSCalibratedRGBColorSpace])
|
|
|
|
{
|
|
|
|
return (numColors == 3);
|
|
|
|
}
|
|
|
|
else if ([colorSpaceName isEqualToString: NSDeviceCMYKColorSpace])
|
|
|
|
{
|
|
|
|
return (numColors == 4);
|
|
|
|
}
|
|
|
|
else if ([colorSpaceName isEqualToString: NSDeviceWhiteColorSpace] ||
|
|
|
|
[colorSpaceName isEqualToString: NSCalibratedWhiteColorSpace])
|
|
|
|
{
|
|
|
|
return (numColors == 1);
|
|
|
|
}
|
|
|
|
else if ([colorSpaceName isEqualToString: NSDeviceBlackColorSpace] ||
|
|
|
|
[colorSpaceName isEqualToString: NSCalibratedBlackColorSpace])
|
|
|
|
{
|
|
|
|
return (numColors == 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-20 16:36:09 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation ARTContext (ops)
|
2008-08-19 17:25:10 +00:00
|
|
|
|
2002-08-20 16:36:09 +00:00
|
|
|
- (void) GSSetDevice: (void*)device : (int)x : (int)y
|
|
|
|
{
|
2008-08-19 17:25:10 +00:00
|
|
|
// Currently all windows share the same drawing info.
|
|
|
|
// It is enough to initialize it once.
|
2008-09-14 21:22:54 +00:00
|
|
|
// This will fail when different screen use different visuals.
|
2008-08-19 17:25:10 +00:00
|
|
|
static BOOL serverInitialized = NO;
|
|
|
|
|
|
|
|
if (!serverInitialized)
|
|
|
|
{
|
2008-09-14 21:22:54 +00:00
|
|
|
[self setupDrawInfo: device];
|
2008-08-19 17:25:10 +00:00
|
|
|
serverInitialized = YES;
|
|
|
|
}
|
2007-03-22 16:54:47 +00:00
|
|
|
[(ARTGState *)gstate GSSetDevice: device : x : y];
|
2002-08-20 16:36:09 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 16:54:47 +00:00
|
|
|
- (void) GSCurrentDevice: (void **)device : (int *)x : (int *)y
|
2002-08-28 16:58:28 +00:00
|
|
|
{
|
2007-03-22 16:54:47 +00:00
|
|
|
[(ARTGState *)gstate GSCurrentDevice: device : x : y];
|
2002-08-20 16:36:09 +00:00
|
|
|
}
|
2002-08-28 16:58:28 +00:00
|
|
|
@end
|