Try to keep the visual of art consistent with the one used by X.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@26849 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2008-09-14 21:22:54 +00:00
parent 9540ccd8a3
commit d6fc8b8e74
4 changed files with 130 additions and 99 deletions

View file

@ -1,3 +1,12 @@
2008-09-14 Fred Kiefer <FredKiefer@gmx.de>
* Source/art/ARTContext.m (-setupDrawInfo): Moved code from here
to...
* Source/x11/XGServer.m (-getForScreen:pixelFormat:masks:::):
... here, including helper functions. Commented out this code and
replaced it by a different approach.
* Headers/x11/XGServer.h: Declare this new method.
2008-09-14 13:17-EDT Gregory John Casamento <greg_casamento@yahoo.com>
* install.sh: Adding install script for use by compile-all.

View file

@ -64,6 +64,8 @@ typedef enum {
- (void *) xrContextForScreen: (int)screen_number;
- (XGDrawMechanism) drawMechanismForScreen: (int)screen_number;
- (void) getForScreen: (int)screen_number pixelFormat: (int *)bpp_number
masks: (int *)red_mask : (int *)green_mask : (int *)blue_mask;
- (Window) xDisplayRootWindowForScreen: (int)screen_number;
- (XColor) xColorFromColor: (XColor)color forScreen: (int)screen_number;

View file

@ -35,32 +35,6 @@
#include "x11/XWindowBuffer.h"
#endif
// Could use NSSwapInt() instead
static unsigned int flip_bytes32(unsigned int i)
{
return ((i >> 24) & 0xff)
|((i >> 8) & 0xff00)
|((i << 8) & 0xff0000)
|((i << 24) & 0xff000000);
}
static unsigned int flip_bytes16(unsigned int i)
{
return ((i >> 8) & 0xff)
|((i << 8) & 0xff00);
}
static int byte_order(void)
{
union
{
unsigned int i;
char c;
} foo;
foo.i = 1;
return foo.c != 1;
}
@implementation ARTContext
+ (void)initializeBackend
@ -82,83 +56,22 @@ static int byte_order(void)
return [ARTGState class];
}
- (void) setupDrawInfo
- (void) setupDrawInfo: (void*)device
{
#ifdef RDS
{
RDSServer *s = (RDSServer *)server;
int bpp;
int red_mask, green_mask, blue_mask;
#ifdef RDS
RDSServer *s = (RDSServer *)server;
[s getPixelFormat: &bpp masks: &red_mask : &green_mask : &blue_mask];
artcontext_setup_draw_info(&DI, red_mask, green_mask, blue_mask, bpp);
}
#else
{
Display *d = [(XGServer *)server xDisplay];
int bpp;
Visual *visual;
XVisualInfo template;
XVisualInfo *visualInfo;
int numMatches;
XImage *i;
gswindow_device_t *gs_win;
/*
We need a visual that we can generate pixel values for by ourselves.
Thus, we try to find a DirectColor or TrueColor visual. If that fails,
we use the default visual and hope that it's usable.
*/
template.class = DirectColor;
visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches);
if (!visualInfo)
{
template.class = TrueColor;
visualInfo = XGetVisualInfo(d, VisualClassMask, &template, &numMatches);
}
if (visualInfo)
{
visual = visualInfo->visual;
bpp = visualInfo->depth;
XFree(visualInfo);
}
else
{
visual = DefaultVisual(d, DefaultScreen(d));
bpp = DefaultDepth(d, DefaultScreen(d));
}
i = XCreateImage(d, visual, bpp, ZPixmap, 0, NULL, 8, 8, 8, 0);
bpp = i->bits_per_pixel;
XDestroyImage(i);
/* If the server doesn't have the same endianness as we do, we need
to flip the masks around (well, at least sometimes; not sure
what'll really happen for 15/16bpp modes). */
{
int us = byte_order(); /* True iff we're big-endian. */
int them = ImageByteOrder(d); /* True iff the server is big-endian. */
if (us != them)
{
if ((bpp == 32) || (bpp == 24))
{
visual->red_mask = flip_bytes32(visual->red_mask);
visual->green_mask = flip_bytes32(visual->green_mask);
visual->blue_mask = flip_bytes32(visual->blue_mask);
}
else if (bpp == 16)
{
visual->red_mask = flip_bytes16(visual->red_mask);
visual->green_mask = flip_bytes16(visual->green_mask);
visual->blue_mask = flip_bytes16(visual->blue_mask);
}
}
}
/* Only returns if the visual was usable. */
artcontext_setup_draw_info(&DI, visual->red_mask, visual->green_mask,
visual->blue_mask, bpp);
}
gs_win = device;
[(XGServer *)server getForScreen: gs_win->screen pixelFormat: &bpp
masks: &red_mask : &green_mask : &blue_mask];
#endif
artcontext_setup_draw_info(&DI, red_mask, green_mask, blue_mask, bpp);
}
- (void) flushGraphics
@ -195,11 +108,12 @@ static int byte_order(void)
{
// Currently all windows share the same drawing info.
// It is enough to initialize it once.
// This will fail when different screen use different visuals.
static BOOL serverInitialized = NO;
if (!serverInitialized)
{
[self setupDrawInfo];
[self setupDrawInfo: device];
serverInitialized = YES;
}
[(ARTGState *)gstate GSSetDevice: device : x : y];

View file

@ -528,6 +528,112 @@ _parse_display_name(NSString *name, int *dn, int *sn)
return [[self _screenContextForScreen: screen_number] drawMechanism];
}
// Could use NSSwapInt() instead
static unsigned int flip_bytes32(unsigned int i)
{
return ((i >> 24) & 0xff)
|((i >> 8) & 0xff00)
|((i << 8) & 0xff0000)
|((i << 24) & 0xff000000);
}
static unsigned int flip_bytes16(unsigned int i)
{
return ((i >> 8) & 0xff)
|((i << 8) & 0xff00);
}
static int byte_order(void)
{
union
{
unsigned int i;
char c;
} foo;
foo.i = 1;
return foo.c != 1;
}
/**
* Used by the art backend to determine the drawing mechanism.
*/
- (void) getForScreen: (int)screen_number pixelFormat: (int *)bpp_number
masks: (int *)red_mask : (int *)green_mask : (int *)blue_mask
{
Visual *visual;
XImage *i;
int bpp;
#if 0
XVisualInfo template;
XVisualInfo *visualInfo;
int numMatches;
/*
We need a visual that we can generate pixel values for by ourselves.
Thus, we try to find a DirectColor or TrueColor visual. If that fails,
we use the default visual and hope that it's usable.
*/
template.class = DirectColor;
visualInfo = XGetVisualInfo(dpy, VisualClassMask, &template, &numMatches);
if (!visualInfo)
{
template.class = TrueColor;
visualInfo = XGetVisualInfo(dpy, VisualClassMask, &template, &numMatches);
}
if (visualInfo)
{
visual = visualInfo->visual;
bpp = visualInfo->depth;
XFree(visualInfo);
}
else
{
visual = DefaultVisual(dpy, DefaultScreen(dpy));
bpp = DefaultDepth(dpy, DefaultScreen(dpy));
}
#else
RContext *context;
// Better to get the used visual from the context.
context = [self xrContextForScreen: screen_number];
visual = context->visual;
bpp = context->depth;
#endif
i = XCreateImage(dpy, visual, bpp, ZPixmap, 0, NULL, 8, 8, 8, 0);
bpp = i->bits_per_pixel;
XDestroyImage(i);
*red_mask = visual->red_mask;
*green_mask = visual->green_mask;
*blue_mask = visual->blue_mask;
*bpp_number = bpp;
/* If the server doesn't have the same endianness as we do, we need
to flip the masks around (well, at least sometimes; not sure
what'll really happen for 15/16bpp modes). */
{
int us = byte_order(); /* True iff we're big-endian. */
int them = ImageByteOrder(dpy); /* True iff the server is big-endian. */
if (us != them)
{
if ((bpp == 32) || (bpp == 24))
{
*red_mask = flip_bytes32(*red_mask);
*green_mask = flip_bytes32(*green_mask);
*blue_mask = flip_bytes32(*blue_mask);
}
else if (bpp == 16)
{
*red_mask = flip_bytes16(*red_mask);
*green_mask = flip_bytes16(*green_mask);
*blue_mask = flip_bytes16(*blue_mask);
}
}
}
}
/**
Returns the root window of the display
*/