mirror of
https://github.com/gnustep/libs-back.git
synced 2025-05-31 01:11:00 +00:00
opal: Correct DPSgsave/restore. Disabled doublebuffering. Work on fixing doublebuffering. Implemented various DPS methods.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@36927 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b35ef8791a
commit
2a8c5f64b3
5 changed files with 200 additions and 20 deletions
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,27 @@
|
||||||
|
2013-07-25 Ivan Vucica <ivan@vucica.net>
|
||||||
|
|
||||||
|
* Source/opal/OpalContext.m:
|
||||||
|
Pushing -DPSgsave: and -DPSgrestore: to OpalGState.
|
||||||
|
|
||||||
|
* Source/opal/OpalSurface.m:
|
||||||
|
-Disabled doublebuffering temporarily.
|
||||||
|
-Work on fixing doublebuffering, including creating subimage
|
||||||
|
properly.
|
||||||
|
-Richer debug image output code, plus saving as PNGs.
|
||||||
|
|
||||||
|
* Source/opal/OpalGState.m:
|
||||||
|
-DPSfill
|
||||||
|
-Setting color now also sets stroke color.
|
||||||
|
-Corrected name for -DPSgsave and -DPSgrestore.
|
||||||
|
-Implemented -saveClip, -restoreClip.
|
||||||
|
-Implemented -DPSeoclip and -DPSeofill.
|
||||||
|
-Added dummy DPSshow:, GSShowText:: etc.
|
||||||
|
-Implemented -DPScurrentpoint:: so that superclass's
|
||||||
|
DPSrlineto:: works.
|
||||||
|
|
||||||
|
* Headers/opal/OpalSurface.h:
|
||||||
|
Added -createCGContexts to header to fix a warning.
|
||||||
|
|
||||||
2013-07-24 Fred Kiefer <FredKiefer@gmx.de>
|
2013-07-24 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/win32/w32_movesize.m (-decodeWM_EXITSIZEMOVEParams:::):
|
* Source/win32/w32_movesize.m (-decodeWM_EXITSIZEMOVEParams:::):
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
- (id) initWithDevice: (void *)device;
|
- (id) initWithDevice: (void *)device;
|
||||||
- (struct _gswindow_device_t *) device;
|
- (struct _gswindow_device_t *) device;
|
||||||
- (CGContextRef) cgContext;
|
- (CGContextRef) cgContext;
|
||||||
|
- (void) createCGContexts;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface OpalSurface (DebugExtensions)
|
@interface OpalSurface (DebugExtensions)
|
||||||
|
|
|
@ -70,6 +70,17 @@
|
||||||
return [surface isDrawingToScreen];
|
return [surface isDrawingToScreen];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) DPSgsave
|
||||||
|
{
|
||||||
|
[super DPSgsave];
|
||||||
|
[OGSTATE DPSgsave];
|
||||||
|
}
|
||||||
|
- (void) DPSgrestore
|
||||||
|
{
|
||||||
|
[super DPSgrestore];
|
||||||
|
[OGSTATE DPSgrestore];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This handles 'expose' event notifications that arrive from
|
This handles 'expose' event notifications that arrive from
|
||||||
X11.
|
X11.
|
||||||
|
@ -82,7 +93,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if BUILD_SERVER == SERVER_x11
|
#if BUILD_SERVER == SERVER_x11
|
||||||
#ifdef XSHM
|
#ifdef XSHM
|
||||||
+ (void) _gotShmCompletion: (Drawable)d
|
+ (void) _gotShmCompletion: (Drawable)d
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
{
|
{
|
||||||
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
//CGContextFillPath(CGCTX);
|
CGContextFillPath(CGCTX);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) DPSimage: (NSAffineTransform *)matrix
|
- (void) DPSimage: (NSAffineTransform *)matrix
|
||||||
|
@ -203,7 +203,13 @@
|
||||||
[super DPSinitgraphics];
|
[super DPSinitgraphics];
|
||||||
|
|
||||||
[_opalSurface createCGContexts];
|
[_opalSurface createCGContexts];
|
||||||
|
/*
|
||||||
|
if ([_opalSurface device])
|
||||||
|
{
|
||||||
|
CGContextTranslateCTM(CGCTX, 0, [_opalSurface device]->buffer_height);
|
||||||
|
CGContextScaleCTM(CGCTX, 1, -1);
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -236,6 +242,7 @@ static CGFloat theAlpha = 1.; // TODO: removeme
|
||||||
const CGFloat alpha = 1; // TODO: is this correct?
|
const CGFloat alpha = 1; // TODO: is this correct?
|
||||||
if(!CGCTX)
|
if(!CGCTX)
|
||||||
return;
|
return;
|
||||||
|
CGContextSetRGBStrokeColor(CGCTX, r, g, b, alpha);
|
||||||
CGContextSetRGBFillColor(CGCTX, r, g, b, alpha);
|
CGContextSetRGBFillColor(CGCTX, r, g, b, alpha);
|
||||||
}
|
}
|
||||||
- (void) DPSrectfill: (CGFloat)x : (CGFloat)y : (CGFloat)w : (CGFloat)h
|
- (void) DPSrectfill: (CGFloat)x : (CGFloat)y : (CGFloat)w : (CGFloat)h
|
||||||
|
@ -388,18 +395,97 @@ static CGFloat theAlpha = 1.; // TODO: removeme
|
||||||
CGContextFlush(CGCTX);
|
CGContextFlush(CGCTX);
|
||||||
[_opalSurface handleExpose:CGRectMake(0, 0, 1024, 1024)];
|
[_opalSurface handleExpose:CGRectMake(0, 0, 1024, 1024)];
|
||||||
}
|
}
|
||||||
- (void) DPSsavegstate
|
- (void) DPSgsave
|
||||||
{
|
{
|
||||||
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
[super DPSsavegstate];
|
#warning Opal bug: nil ctx should 'only' print a warning instead of crashing
|
||||||
CGContextSaveGState(CGCTX);
|
if (CGCTX)
|
||||||
|
CGContextSaveGState(CGCTX);
|
||||||
}
|
}
|
||||||
- (void) DPSrestoregstate
|
- (void) DPSgrestore
|
||||||
{
|
{
|
||||||
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
[super DPSrestoregstate];
|
#warning Opal bug: nil ctx should 'only' print a warning instead of crashing
|
||||||
|
if (CGCTX)
|
||||||
|
CGContextRestoreGState(CGCTX);
|
||||||
|
}
|
||||||
|
- (void *) saveClip
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
CGRect * r = calloc(sizeof(CGRect), 1);
|
||||||
|
*r = CGContextGetClipBoundingBox(CGCTX);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
- (void) restoreClip: (void *)savedClip
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
OPContextResetClip(CGCTX);
|
||||||
|
CGContextClipToRect(CGCTX, *(CGRect *)savedClip);
|
||||||
|
free(savedClip);
|
||||||
|
}
|
||||||
|
- (void) DPSeoclip
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
CGContextEOClip(CGCTX);
|
||||||
|
}
|
||||||
|
- (void) DPSeofill
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
CGContextEOFillPath(CGCTX);
|
||||||
|
}
|
||||||
|
- (void) DPSshow: (const char *)s
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
|
||||||
|
CGContextSaveGState(CGCTX);
|
||||||
|
CGContextSetRGBFillColor(CGCTX, 0, 1, 0, 1);
|
||||||
|
CGContextFillRect(CGCTX, CGRectMake(0, 0, 12, strlen(s) * 12));
|
||||||
CGContextRestoreGState(CGCTX);
|
CGContextRestoreGState(CGCTX);
|
||||||
}
|
}
|
||||||
|
- (void) GSShowText: (const char *)s : (size_t) length
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
/*
|
||||||
|
const char * s2 = calloc(s, length+1);
|
||||||
|
strcpy(s2, s);
|
||||||
|
*/
|
||||||
|
CGContextSaveGState(CGCTX);
|
||||||
|
CGContextSetRGBFillColor(CGCTX, 0, 1, 0, 1);
|
||||||
|
CGContextFillRect(CGCTX, CGRectMake(0, 0, 12, length * 12));
|
||||||
|
CGContextRestoreGState(CGCTX);
|
||||||
|
// free(s2);
|
||||||
|
}
|
||||||
|
- (void) GSShowGlyphsWithAdvances: (const NSGlyph *)glyphs : (const NSSize *)advances : (size_t) length
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
CGContextSaveGState(CGCTX);
|
||||||
|
CGContextSetRGBFillColor(CGCTX, 0, 1, 0, 1);
|
||||||
|
CGContextFillRect(CGCTX, CGRectMake(0, 0, 12, length * 12));
|
||||||
|
CGContextRestoreGState(CGCTX);
|
||||||
|
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
- (void) DPSrlineto: (CGFloat) x
|
||||||
|
: (CGFloat) y
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
|
||||||
|
|
||||||
|
CGContextAddRelativeLine(CGCTX, x, y);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#warning -DPSrlineto:: not implemented directly
|
||||||
|
#endif
|
||||||
|
- (void) DPScurrentpoint: (CGFloat *)x
|
||||||
|
: (CGFloat *)y
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s - %g %g", self, [self class], __PRETTY_FUNCTION__, x, y);
|
||||||
|
|
||||||
|
CGPoint currentPoint = CGContextGetPathCurrentPoint(CGCTX);
|
||||||
|
*x = currentPoint.x;
|
||||||
|
*y = currentPoint.y;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// MARK: Non-required unimplemented methods
|
// MARK: Non-required unimplemented methods
|
||||||
|
@ -421,6 +507,11 @@ static CGFloat theAlpha = 1.; // TODO: removeme
|
||||||
{
|
{
|
||||||
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
}
|
}
|
||||||
|
- (void) DPSsetgstate: (NSInteger) gst
|
||||||
|
{
|
||||||
|
NSDebugLLog(@"OpalGState", @"%p (%@): %s", self, [self class], __PRETTY_FUNCTION__);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ static CGContextRef createCGBitmapContext (int pixelsWide,
|
||||||
|
|
||||||
- (void) createCGContexts
|
- (void) createCGContexts
|
||||||
{
|
{
|
||||||
|
|
||||||
// FIXME: this method and class presumes we are being passed
|
// FIXME: this method and class presumes we are being passed
|
||||||
// a window device.
|
// a window device.
|
||||||
|
|
||||||
|
@ -134,9 +135,13 @@ static CGContextRef createCGBitmapContext (int pixelsWide,
|
||||||
_gsWindowDevice->gdriverProtocol |= GDriverHandlesExpose | GDriverHandlesBacking;
|
_gsWindowDevice->gdriverProtocol |= GDriverHandlesExpose | GDriverHandlesBacking;
|
||||||
_gsWindowDevice->gdriver = self;
|
_gsWindowDevice->gdriver = self;
|
||||||
|
|
||||||
|
#if 0
|
||||||
_backingCGContext = createCGBitmapContext(
|
_backingCGContext = createCGBitmapContext(
|
||||||
_gsWindowDevice->buffer_width,
|
_gsWindowDevice->buffer_width,
|
||||||
_gsWindowDevice->buffer_height);
|
_gsWindowDevice->buffer_height);
|
||||||
|
#else
|
||||||
|
#warning NOTE! Doublebuffering disabled.
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,32 +162,82 @@ static CGContextRef createCGBitmapContext (int pixelsWide,
|
||||||
{
|
{
|
||||||
NSDebugLLog(@"OpalSurface", @"handleExposeRect %@", NSStringFromRect(rect));
|
NSDebugLLog(@"OpalSurface", @"handleExposeRect %@", NSStringFromRect(rect));
|
||||||
|
|
||||||
CGRect cgRect = CGRectMake(rect.origin.x, rect.origin.y,
|
|
||||||
rect.size.width, rect.size.height);
|
|
||||||
|
|
||||||
CGImageRef backingImage = CGBitmapContextCreateImage(_backingCGContext);
|
CGImageRef backingImage = CGBitmapContextCreateImage(_backingCGContext);
|
||||||
if (!backingImage) // FIXME: writing a nil image fails with Opal
|
if (!backingImage) // FIXME: writing a nil image fails with Opal
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
CGRect cgRect = CGRectMake(rect.origin.x, rect.origin.y,
|
||||||
|
rect.size.width, rect.size.height);
|
||||||
|
|
||||||
|
CGRect subimageCGRect = cgRect;
|
||||||
|
//subimageCGRect.origin.y = CGImageGetHeight(backingImage) - cgRect.origin.y - cgRect.size.height;
|
||||||
|
|
||||||
|
// TODO: opal might be able to provide a variant of DrawImage that does
|
||||||
|
// not require creating a subimage
|
||||||
|
CGImageRef subImage = CGImageCreateWithImageInRect(backingImage, subimageCGRect);
|
||||||
|
|
||||||
CGContextSaveGState(_x11CGContext);
|
CGContextSaveGState(_x11CGContext);
|
||||||
OPContextResetClip(_x11CGContext);
|
OPContextResetClip(_x11CGContext);
|
||||||
OPContextSetIdentityCTM(_x11CGContext);
|
OPContextSetIdentityCTM(_x11CGContext);
|
||||||
|
|
||||||
CGContextDrawImage(_x11CGContext, cgRect, backingImage);
|
|
||||||
|
|
||||||
|
cgRect.origin.y = [self device]->buffer_height - cgRect.origin.y - cgRect.size.height;
|
||||||
|
NSDebugLLog(@"OpalSurface, "@"Painting from %@ to %@", NSStringFromRect(*(NSRect *)&subimageCGRect), NSStringFromRect(*(NSRect *)&cgRect));
|
||||||
|
|
||||||
|
CGContextDrawImage(_x11CGContext, cgRect, subImage);
|
||||||
|
|
||||||
|
CGContextSetRGBFillColor(_x11CGContext, 0, (rand() % 255) / 255., 1, 0.7);
|
||||||
|
CGContextSetRGBStrokeColor(_x11CGContext, 1, 0, 0, 1);
|
||||||
|
CGContextSetLineWidth(_x11CGContext, 2);
|
||||||
|
//CGContextFillRect(_x11CGContext, cgRect);
|
||||||
|
// CGContextStrokeRect(_x11CGContext, cgRect);i
|
||||||
|
#else
|
||||||
|
CGContextSaveGState(_x11CGContext);
|
||||||
|
OPContextResetClip(_x11CGContext);
|
||||||
|
OPContextSetIdentityCTM(_x11CGContext);
|
||||||
|
|
||||||
|
CGContextDrawImage(_x11CGContext, CGRectMake(0, 0, [self device]->buffer_width, [self device]->buffer_height), backingImage);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
[self _saveImage: backingImage withPrefix:@"/tmp/opalback-backing-" size: CGSizeZero];
|
||||||
|
[self _saveImage: subImage withPrefix:@"/tmp/opalback-subimage-" size: subimageCGRect.size ];
|
||||||
|
|
||||||
|
CGImageRelease(backingImage);
|
||||||
|
CGImageRelease(subImage);
|
||||||
|
|
||||||
|
CGContextRestoreGState(_x11CGContext);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _saveImage: (CGImageRef) img withPrefix: (NSString *) prefix size: (CGSize) size
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
#warning Saving debug images
|
||||||
|
#if 1
|
||||||
|
#warning Opal bug: cannot properly save subimage created with CGImageCreateWithImageInRect()
|
||||||
|
if (size.width != 0 || size.height != 0)
|
||||||
|
{
|
||||||
|
CGContextRef tmp = createCGBitmapContext(size.width, size.height);
|
||||||
|
CGContextDrawImage(tmp, CGRectMake(0, 0, size.width, size.height), img);
|
||||||
|
img = CGBitmapContextCreateImage(tmp);
|
||||||
|
[(id)img autorelease];
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// FIXME: Opal tries to access -path from CFURLRef
|
// FIXME: Opal tries to access -path from CFURLRef
|
||||||
//CFURLRef fileUrl = CFURLCreateWithFileSystemPath(NULL, @"/tmp/opalback.jpg", kCFURLPOSIXPathStyle, NO);
|
//CFURLRef fileUrl = CFURLCreateWithFileSystemPath(NULL, @"/tmp/opalback.jpg", kCFURLPOSIXPathStyle, NO);
|
||||||
CFURLRef fileUrl = (CFURLRef)[[NSURL fileURLWithPath: @"/tmp/opalback.jpg"] retain];
|
NSString * path = [NSString stringWithFormat: @"%@%dx%d.png", prefix, CGImageGetWidth(img), CGImageGetHeight(img)];
|
||||||
|
CFURLRef fileUrl = (CFURLRef)[[NSURL fileURLWithPath: path] retain];
|
||||||
NSLog(@"FileURL %@", fileUrl);
|
NSLog(@"FileURL %@", fileUrl);
|
||||||
CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, @"public.jpeg"/*kUTTypeJPEG*/, 1, NULL);
|
//CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, @"public.jpeg"/*kUTTypeJPEG*/, 1, NULL);
|
||||||
CGImageDestinationAddImage(outfile, backingImage, NULL);
|
CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, @"public.png"/*kUTTypePNG*/, 1, NULL);
|
||||||
|
CGImageDestinationAddImage(outfile, img, NULL);
|
||||||
CGImageDestinationFinalize(outfile);
|
CGImageDestinationFinalize(outfile);
|
||||||
CFRelease(fileUrl);
|
CFRelease(fileUrl);
|
||||||
CFRelease(outfile);
|
CFRelease(outfile);
|
||||||
|
|
||||||
CGImageRelease(backingImage);
|
#endif
|
||||||
|
|
||||||
CGContextRestoreGState(_x11CGContext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isDrawingToScreen
|
- (BOOL) isDrawingToScreen
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue