* Headers/AppKit/NSOpenGL.h,

* Source/NSOpenGLPixelFormat.m: NSOpenGLPixelFormat directly
        * implements
        initWithCoder so that it may marshall the pixel attributes prior
to
        initWithAttributes:. Change the getValues:... method to take an
        int argument instead of long. GLint is mapped to int on most
systems.
        * Source/NSOpenGLContext.m: Use the format decoding to decode an
        * OpenGL context.
        Patch by Clint Smullen <daemonae>.

        * Source/GSLayoutManager.m: Small cleanup in glyph code.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@35923 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2012-12-26 19:19:50 +00:00
parent e93fd24f0d
commit 60fcb3622e
5 changed files with 134 additions and 91 deletions

View file

@ -1,3 +1,15 @@
2012-12-26 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSOpenGL.h,
* Source/NSOpenGLPixelFormat.m: NSOpenGLPixelFormat directly implements
initWithCoder so that it may marshall the pixel attributes prior to
initWithAttributes:. Change the getValues:... method to take an
int argument instead of long. GLint is mapped to int on most systems.
* Source/NSOpenGLContext.m: Use the format decoding to decode an OpenGL context.
Patch by Clint Smullen <daemonae>.
* Source/GSLayoutManager.m: Small cleanup in glyph code.
2012-12-23 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSFont.m (-initWithName:...): Move replacement name into

View file

@ -86,10 +86,10 @@ typedef enum {
NSOpenGLGOResetLibrary = 504
} NSOpenGLGlobalOption;
@interface NSOpenGLPixelFormat : NSObject
@interface NSOpenGLPixelFormat : NSObject <NSCoding>
{
}
- (void)getValues:(long *)vals
- (void)getValues:(int *)vals
forAttribute:(NSOpenGLPixelFormatAttribute)attrib
forVirtualScreen:(int)screen;
- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs;

View file

@ -43,7 +43,7 @@
#import "GNUstepGUI/GSLayoutManager_internal.h"
/* TODO: is using rand() here ok? */
static int random_level(void)
static inline int random_level(void)
{
int i;
for (i = 0; i < SKIP_LIST_DEPTH - 2; i++)
@ -82,31 +82,6 @@ static glyph_run_t *run_insert(glyph_run_head_t **context, int level)
return r;
}
/*
* Remove the run r from the context of the skip list and free it.
* The context does not point at r, but to the run immediately before r.
* context[0]->next == r
*/
static void run_remove(glyph_run_head_t **context, glyph_run_t *r)
{
glyph_run_head_t *h;
int i;
// Free the glyphs
if (r->glyphs)
free(r->glyphs);
h = &r->head;
if (h->next)
((glyph_run_t *)h->next)->prev = r->prev;
for (i = 0; i <= r->level; i++)
context[i]->next = context[i]->next->next;
h -= r->level;
free(h);
}
/*
* Free the glphys of a run.
*/
@ -121,6 +96,30 @@ static inline void run_free_glyphs(glyph_run_t *r)
}
}
/*
* Remove the run r from the context of the skip list and free it.
* The context does not point at r, but to the run immediately before r.
* context[0]->next == r
*/
static inline void run_remove(glyph_run_head_t **context, glyph_run_t *r)
{
glyph_run_head_t *h;
int i;
// Free the glyphs
run_free_glyphs(r);
h = &r->head;
if (h->next)
((glyph_run_t *)h->next)->prev = r->prev;
for (i = 0; i <= r->level; i++)
context[i]->next = context[i]->next->next;
h -= r->level;
free(h);
}
/* Recalculates char_length, glyph_length, and complete for a
glyph_run_head_t. All "children" of this head must have valid values. */
static void run_fix_head(glyph_run_head_t *h)
@ -175,6 +174,7 @@ Private method used internally by GSLayoutManager for sanity checking.
{
/* set up attributes for this run */
NSNumber *n;
NSFont *font;
r->explicit_kern = !![attributes objectForKey: NSKernAttributeName];
@ -184,7 +184,7 @@ Private method used internally by GSLayoutManager for sanity checking.
else
r->ligature = 1;
r->font = [typesetter fontForCharactersWithAttributes: attributes];
font = [typesetter fontForCharactersWithAttributes: attributes];
/* TODO: it might be useful to change this slightly:
Returning a nil font from -fontForCharactersWithAttributes: causes those
characters to not be displayed (ie. no glyphs are generated).
@ -192,10 +192,10 @@ Private method used internally by GSLayoutManager for sanity checking.
How would glyph<->char mapping be handled? Map the entire run to one
NSNullGlyph?
*/
if (!r->font)
r->font = [NSFont userFontOfSize: 0];
r->font = [self substituteFontForFont: r->font];
r->font = [r->font retain];
if (font == nil)
font = [NSFont userFontOfSize: 0];
font = [self substituteFontForFont: font];
ASSIGN(r->font, font);
}
-(void) _run_free_attributes: (glyph_run_t *)r
@ -355,9 +355,9 @@ Private method used internally by GSLayoutManager for sanity checking.
{
if (glyph_pos)
*glyph_pos = cached_pos;
if (char_pos)
if (char_pos)
*char_pos = cached_cpos;
return cached_run;
return cached_run;
}
}
@ -418,8 +418,6 @@ Private method used internally by GSLayoutManager for sanity checking.
* glyph_pos and char_pos, when supplied, will contain the starting
* glyph/character index for this run.
*/
#define run_for_character_index(a,b,c,d) [self run_for_character_index: a : c : d]
- (glyph_run_t *)run_for_character_index: (unsigned int)charIndex
: (unsigned int *)glyph_pos
: (unsigned int *)char_pos
@ -771,7 +769,7 @@ Fills in all glyph holes up to last. only looking at levels below level
unsigned int pos, cpos;
int lo, hi, mid, i;
r = run_for_character_index(target, glyphs, &pos, &cpos);
r = [self run_for_character_index: target : &pos : &cpos];
if (!r)
{
[NSException raise: NSRangeException
@ -1718,32 +1716,40 @@ places where we switch.
- (void) deleteGlyphsInRange: (NSRange)aRange
{
/* See invalidateGlyphsForCharacterRange:changeInLength:actualCharacterRange:
glyph_run_t *r;
glyph_run_t *run;
unsigned int pos, cpos;
unsigned int glyphIndex;
unsigned int lastGlyphIndex;
glyph_run_head_t *context[SKIP_LIST_DEPTH];
glyphIndex = NSMinRange(aRange);
while (glyphIndex < NSMaxRange(aRange))
lastGlyphIndex = NSMaxRange(aRange) - 1;
while (glyphIndex <= lastGlyphIndex)
{
if (glyphs->glyph_length <= glyphIndex)
run = run_for_glyph_index(glyphIndex, glyphs, &pos, &cpos);
if (!run)
{
[NSException raise: NSRangeException
format: @"%s glyph index out of range", __PRETTY_FUNCTION__];
return;
}
r = run_for_glyph_index(glyphIndex, glyphs, &pos, &cpos);
if (!r)
{
[NSException raise: NSRangeException
format: @"%s glyph index out of range", __PRETTY_FUNCTION__];
return;
}
glyphIndex += r->head.glyph_length;
run_free_glyphs(r);
// FIXME: Need to invalidate the entries above this one.
// FIXME: remove all invalid glyphs from run
if ((pos == 0) && (lastGlyphIndex >= glyphIndex - pos + run->head.glyph_length))
{
run_free_glyphs(run);
}
else
{
if (lastGlyphIndex >= glyphIndex - pos + run->head.glyph_length)
{
}
r->head.glyph_length = len;
}
// FIXME: Need to invalidate the entries above this one.
// FIXME Cache this value
glyphIndex += r->head.glyph_length - pos;
}
*/
NSLog(@"Internal method %s called", __PRETTY_FUNCTION__);
@ -3184,7 +3190,7 @@ forStartingGlyphAtIndex: (NSUInteger)glyph
//NSLog(@"Insert %d glyphs at %d for index %d", length, glyph, index);
run = run_for_character_index(index, glyphs, &gpos, &cpos);
run = [self run_for_character_index: index : &gpos : &cpos];
if (!run)
{
[NSException raise: NSRangeException
@ -3193,6 +3199,15 @@ forStartingGlyphAtIndex: (NSUInteger)glyph
}
len = glyph - gpos + length;
if (len < 0)
{
NSLog(@"Insert %d glyphs at %d for index %d", length, glyph, index);
NSLog(@"Found gpos %d cpos %d len %d", gpos, cpos, len);
[NSException raise: NSRangeException
format: @"%s glyph index out of range", __PRETTY_FUNCTION__];
return;
}
if (!run->glyphs)
{
run->glyphs = malloc(sizeof(glyph_t) * len);
@ -3227,7 +3242,7 @@ forStartingGlyphAtIndex: (NSUInteger)glyph
unsigned int gpos, cpos;
NSSize advances[length];
run = run_for_character_index(index, glyphs, &gpos, &cpos);
run = [self run_for_character_index: index : &gpos : &cpos];
if (!run)
{
[NSException raise: NSRangeException

View file

@ -27,29 +27,14 @@
*/
#import <Foundation/NSString.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDebug.h>
#import "AppKit/NSOpenGL.h"
#import "GNUstepGUI/GSDisplayServer.h"
// @interface GSGLPixelFormat : NSOpenGLPixelFormat
// {}
// + _classContext;
// @end
// @implementation GSGLPixelFormat
// - (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs
// {
// self = [[GSGLPixelFormat _classContext] alloc];
// return [self initWithAttributes: attribs];
// }
// @end
//static GSGLPixelFormat *temp;
@implementation NSOpenGLPixelFormat
+ _classPixelFormat
+ (Class) _classPixelFormat
{
Class glPixelFormatClass = [GSCurrentServer() glPixelFormatClass];
@ -65,16 +50,7 @@
}
}
// + (void) initialize
// {
// if (self == [NSOpenGLPixelFormat class])
// {
// temp = (GSGLPixelFormat *) NSAllocateObject([GSGLPixelFormat class], 0,
// NSDefaultMallocZone());
// }
// }
+ allocWithZone: (NSZone *) z
+ (id) allocWithZone: (NSZone*) z
{
Class c = [self _classPixelFormat];
if (c)
@ -83,25 +59,56 @@
return nil;
}
- (void)getValues:(long *)vals
forAttribute:(NSOpenGLPixelFormatAttribute)attrib
forVirtualScreen:(int)screen
- (void) getValues: (int*)vals
forAttribute: (NSOpenGLPixelFormatAttribute)attrib
forVirtualScreen: (int)screen
{
[self subclassResponsibility: _cmd];
}
- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs
- (id) initWithAttributes: (NSOpenGLPixelFormatAttribute*)attribs
{
[self subclassResponsibility: _cmd];
return nil;
}
- (int)numberOfVirtualScreens
- (int) numberOfVirtualScreens
{
[self subclassResponsibility: _cmd];
return 0;
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
if ([aDecoder allowsKeyedCoding])
{
NSMutableData *attrs = [aDecoder decodeObjectForKey: @"NSPixelAttributes"];
if (attrs != nil)
{
NSOpenGLPixelFormatAttribute *glattrs;
unsigned char tmp = 0;
// Ensure that it is zero-terminated
[attrs appendBytes: &tmp length: sizeof(tmp)];
// FIXME: Deserialize an integer array
glattrs = (NSOpenGLPixelFormatAttribute *)[attrs mutableBytes];
return [self initWithAttributes: glattrs];
}
}
else
{
}
return self;
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[self subclassResponsibility: _cmd];
}
@end

View file

@ -252,12 +252,21 @@ static NSOpenGLPixelFormatAttribute attrs[] =
}
}
- (id) initWithCoder: (NSCoder *)aCoder
- (id) initWithCoder: (NSCoder *)aDecoder
{
self = [super initWithCoder: aCoder];
self = [super initWithCoder: aDecoder];
if (!self)
return nil;
// FIXME: Should set a pixel format like -init does
if ([aDecoder allowsKeyedCoding])
{
[self setPixelFormat: [aDecoder decodeObjectForKey: @"NSPixelFormat"]];
}
else
{
[self setPixelFormat: [[self class] defaultPixelFormat]];
}
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_frameChanged:)