discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cairo drawing problem


From: Fred Kiefer
Subject: Re: cairo drawing problem
Date: Thu, 11 Jun 2020 23:56:39 +0200

Hi Andreas,

I did not get your original mail and it isn’t even in my spam folder where your 
previous mails.

> Am 11.06.2020 um 00:05 schrieb Josh Freeman <gnustep_lists@twilightedge.com>:
> 
>   Try initializing your window as NSBackingStoreBuffered? 
> (NSBackingStoreNonretained tells the window to draw directly to the screen 
> without buffering, so the pixel data is probably unavailable for reading 
> back).

This might help but I really would like to understand where the issue comes 
from in the first place.

Looking at the code and the output below the first thing I notice is that the X 
error happens after the extraction of the view data into the bitmap image was 
finished. The most likely scenario is that the data we extracted is somehow 
invalid. That would fit in wit your suggested work around.

But all of this is just blind guessing, what we need here is example code that 
allows to reproduce this issue with GNUstep classes only.

Andreas, could you please strip down your application to pure GNUstep and if 
that still displays the error send out that code?

Cheers,
Fred

> On Jun 8, 2020, at 1:52 PM, Andreas Höschler via Discussion list for the 
> GNUstep programming environment wrote:
> 
>> 
>> Hi all,
>> 
>> I have just found some time to continue testing my app(s) on GNUstep and 
>> realised that drawing OSM maps fails under GNUstep when using the cairo 
>> backend while it works if using libart.
>> 
>> My code draws something in a NSView subclass and then uses
>> 
>>         [mapView display];
>>         [mapView lockFocus];
>>         NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] 
>> initWithFocusedViewRect:[mapView bounds]];
>>         data = [[[rep representationUsingType:NSPNGFileType 
>> properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] 
>> forKey:@"NSImageInterlaced"]] retain] autorelease];
>>         if ([data length] == 0) // try TIFF instead
>>           {
>>            data = [[[rep representationUsingType:NSTIFFFileType 
>> properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] 
>> forKey:@"NSImageInterlaced"]] retain] autorelease];
>>            if ([data length] == 0) NSLog(@"Damn! TIFF failed as well!");
>>           }
>>         [mapView unlockFocus];
>> 
>> to produce a PNG from the view content. This works great with libart
>> 
>> art:
>> ============================================================================
>> 
>> 2020-06-08 19:37:18.526 ESMMapServer[10165:10165] draw way inlays... 359 
>> _drawPrimaryInLays 1 _drawOtherInLays 1
>> 2020-06-08 19:37:18.527 ESMMapServer[10165:10165] BUMM
>> 2020-06-08 19:37:18.545 ESMMapServer[10165:10165] Draw 7 mapShields ...
>> 2020-06-08 19:37:18.548 ESMMapServer[10165:10165] Draw 1 mapLocs ...
>> 2020-06-08 19:37:18.549 ESMMapServer[10165:10165] Draw 2 mapLines ...
>> 2020-06-08 19:37:18.549 ESMMapServer[10165:10165] <ESMMapLine: 0x2ed0550> 
>> drawLine _colorName (null) _color 0 0 1
>> 2020-06-08 19:37:18.549 ESMMapServer[10165:10165] <ESMMapLine: 0x2ed4610> 
>> drawLine _colorName (null) _color 0 1 0
>> 2020-06-08 19:37:18.557 ESMMapServer[10165:10165]  h=--- v=--- <ESMMapView: 
>> 0x2302ca0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; 
>> width = 542; height = 620} locking Focus ...
>> 2020-06-08 19:37:18.557 ESMMapServer[10165:10165] getting rep ...
>> 2020-06-08 19:37:18.563 ESMMapServer[10165:10165] rep <NSBitmapImageRep: 
>> 0x2f15450 size: {width = 542; height = 620} pixelsWide: 542 pixelsHigh: 620 
>> colorSpaceName: NSDeviceRGBColorSpace bps: 8>
>> 2020-06-08 19:37:18.665 ESMMapServer[10165:10165]  h=--- v=--- <ESMMapView: 
>> 0x2302ca0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; 
>> width = 542; height = 620} unocked Focus!
>> 2020-06-08 19:37:18.665 ESMMapServer[10165:10165] data 248529
>> 
>> but fails with cairo
>> 
>> cairo:
>> =======================================================================================
>> 2020-06-08 19:31:52.783 ESMMapServer[9982:9982] draw way inlays... 359 
>> _drawPrimaryInLays 1 _drawOtherInLays 1
>> 2020-06-08 19:31:52.783 ESMMapServer[9982:9982] BUMM
>> 2020-06-08 19:31:52.798 ESMMapServer[9982:9982] Draw 8 mapShields ...
>> 2020-06-08 19:31:52.801 ESMMapServer[9982:9982] Draw 1 mapLocs ...
>> 2020-06-08 19:31:52.802 ESMMapServer[9982:9982] Draw 2 mapLines ...
>> 2020-06-08 19:31:52.802 ESMMapServer[9982:9982] <ESMMapLine: 0x33b52c0> 
>> drawLine _colorName (null) _color 0 0 1
>> 2020-06-08 19:31:52.802 ESMMapServer[9982:9982] <ESMMapLine: 0x33c3d30> 
>> drawLine _colorName (null) _color 0 1 0
>> 2020-06-08 19:31:52.811 ESMMapServer[9982:9982]  h=--- v=--- <ESMMapView: 
>> 0x28e0fe0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; 
>> width = 542; height = 620} locking Focus ...
>> 2020-06-08 19:31:52.812 ESMMapServer[9982:9982] getting rep ...
>> 2020-06-08 19:31:52.815 ESMMapServer[9982:9982] rep <NSBitmapImageRep: 
>> 0x3698ef0 size: {width = 542; height = 620} pixelsWide: 542 pixelsHigh: 620 
>> colorSpaceName: NSDeviceRGBColorSpace bps: 8>
>> 2020-06-08 19:31:52.882 ESMMapServer[9982:9982]  h=--- v=--- <ESMMapView: 
>> 0x28e0fe0> f={x = 0; y = 0; width = 542; height = 620} b={x = 0; y = 0; 
>> width = 542; height = 620} unocked Focus!
>> 2020-06-08 19:31:52.883 ESMMapServer[9982:9982] data 1383
>> 2020-06-08 19:31:52.921 ESMMapServer[9982:9982] X-Windows error - 
>> RenderBadPicture (invalid Picture parameter)
>>          on display: :0
>>                type: 0
>>       serial number: 1169
>>        request code: 139
>> 
>> 
>> data contains nothing reasonable after this X-WIndows error. I have attached 
>> the complete implementation of
>> 
>> - (NSDictionary *)PNGForMapRequestDic:(NSDictionary *)dic;
>> 
>> for reference below (contains the lockFocus ... unlockFocus magic). Any idea 
>> what might be causing this X-Windows error with cairo? I am stuck when it 
>> gets to backend issues. I might have to add that this error occurs in a tool 
>> (no gui app) named ESMMapServer which is supposed to produce maps (PNGs) 
>> from OSM data in the background.
>> 
>> Thanks a lot,
>> 
>> Andreas
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> - (NSDictionary *)PNGForMapRequestDic:(NSDictionary *)dic
>> {
>>   NSNumber *pixelWidth = [dic objectForKey:@"pixelWidth"];
>>   NSNumber *pixelHeight = [dic objectForKey:@"pixelHeight"];
>>   NSNumber *x = [dic objectForKey:@"x"];
>>   NSNumber *y = [dic objectForKey:@"y"];
>>   NSNumber *width = [dic objectForKey:@"width"];
>>   NSNumber *height = [dic objectForKey:@"height"];
>>   NSArray *locations = [dic objectForKey:@"locations"];
>>   NSArray *hintPaths = [dic objectForKey:@"hintPaths"];
>>   BOOL drawTextMarks = [[dic objectForKey:@"drawTextMarks"] intValue];
>>   NSLog(@"PNGForMapRequestDic hintPaths %d %@ %@ %@ %@ pixelWidth %@ 
>> pixelHeight %@", [hintPaths count], x, y, width, height, pixelWidth, 
>> pixelHeight);
>>   NSLog(@"locations %@", [locations description]);
>> 
>>   [_shields removeAllObjects];
>> 
>>   if ((pixelWidth) && (pixelHeight) && (x) && (y) && (width) && (height))
>>     {
>>      _visibleMapSection = NSMakeRect ([x floatValue], [y floatValue], [width 
>> floatValue], [height floatValue]);
>>      if (_visibleMapSection.size.height > MAXESMMAPHEIGHT) // reducing map 
>> size to avoid OSMMapServer break down <-----------
>>        {
>>         NSLog(@"reducing map size to avoid OSMMapServer break down %f -> 
>> %f", _visibleMapSection.size.height, MAXESMMAPHEIGHT);
>>         float margin = (_visibleMapSection.size.height - MAXESMMAPHEIGHT) / 
>> 2;
>>         _visibleMapSection.origin.y += margin;
>>         _visibleMapSection.size.height = MAXESMMAPHEIGHT;
>>        }
>>      _imageSize = NSMakeSize([pixelWidth floatValue], [pixelHeight 
>> floatValue]);
>>      NSLog(@"_imageSize %@", NSStringFromSize(_imageSize));
>>      if (_imageSize.width / _imageSize.height > 
>> (_visibleMapSection.size.width * cos ((_visibleMapSection.origin.y + 
>> _visibleMapSection.size.height / 2.0) / 180.0 * 3.14)) / 
>> _visibleMapSection.size.height)
>>        {
>>         float correctedWidth = _visibleMapSection.size.height * 
>> _imageSize.width / (_imageSize.height * cos ((_visibleMapSection.origin.y + 
>> _visibleMapSection.size.height / 2.0) / 180.0 * 3.14));
>>         //         NSLog(@"requested width %f correctedWidth %f", 
>> _visibleMapSection.size.width, correctedWidth);
>>         _visibleMapSection.origin.x -= (correctedWidth - 
>> _visibleMapSection.size.width) / 2.0;
>>         _visibleMapSection.size.width = correctedWidth;
>>        }
>>      else
>>        {
>>         float correctedHeight = (_visibleMapSection.size.width * 
>> _imageSize.height * cos ((_visibleMapSection.origin.y + 
>> _visibleMapSection.size.height / 2.0) / 180.0 * 3.14) / _imageSize.width);
>>         //         NSLog(@"requested height %f correctedHeight %f", 
>> _visibleMapSection.size.height, correctedHeight);
>>         _visibleMapSection.origin.y -= (correctedHeight - 
>> _visibleMapSection.size.height) / 2.0;
>>         _visibleMapSection.size.height = correctedHeight;
>>        }
>>      NSLog(@"_visibleMapSection %@", NSStringFromRect(_visibleMapSection));
>> 
>>      NSArray *presentations = [self 
>> suitablePresentationsForRect:_visibleMapSection];
>>      //      NSLog(@"presentations %@", [presentations description]);
>>      NSEnumerator *enumerator = [presentations objectEnumerator];
>>      ESMMapPresentation *presentation;
>>      NSArray *highways = nil;
>>      NSArray *ways = nil;
>>      NSArray *namedNodes = nil;
>>      ESMMapView *mapView = nil;
>>      NSWindow *window = nil;
>> 
>>      NSLog(@"_sharedMapView %@", _sharedMapView);
>>      if (_sharedMapView)
>>        {
>>         mapView = (ESMMapView *)[_sharedMapView retain];
>>         [mapView removeAllPathsAndMapLabels];
>>        }
>>      else
>>        {
>>         window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0, 
>> _imageSize.width, _imageSize.height) styleMask:NSBorderlessWindowMask 
>> backing:NSBackingStoreNonretained defer:NO];
>>         mapView = [[ESMMapView alloc] initWithFrame:NSMakeRect(0, 0, 
>> _imageSize.width, _imageSize.height)];

<a lot of unrelated code removed>

>>      NSData *data = nil;
>> 
>>      if (_sharedMapView)
>>        {
>>         [mapView prepareOSMDrawing];
>>         NSLog(@"%@ calling display ..", mapView);
>>         [mapView display];
>>         NSLog(@"%@ display done", mapView);
>>        }
>>      else
>>        {
>>         [mapView display];
>>         NS_DURING
>>         NSLog(@"%@ locking Focus ...", mapView);
>>         [mapView lockFocus];
>>         NSLog(@"getting rep ...");
>>         //      NSLog(@"window frame %@", NSStringFromRect([[mapView window] 
>> frame]));
>>         //      NSLog(@"contentView frame %@", NSStringFromRect([[[mapView 
>> window] contentView] frame]));
>>         //      NSLog(@"frame %@", NSStringFromRect([mapView frame]));
>>         //      NSLog(@"bounds %@", NSStringFromRect([mapView bounds]));
>>         NSBitmapImageRep *rep = [[NSBitmapImageRep alloc] 
>> initWithFocusedViewRect:[mapView bounds]];
>>         NSLog(@"rep %@", rep);
>>         data = [[[rep representationUsingType:NSPNGFileType 
>> properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] 
>> forKey:@"NSImageInterlaced"]] retain] autorelease];
>> /*           {
>>            NSString *path = @"/home/ahoesch/A.tiff";
>>            NSData *data = [[[rep representationUsingType:NSTIFFFileType 
>> properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] 
>> forKey:@"NSImageInterlaced"]] retain] autorelease];
>>            [data writeToFile:path atomically:YES];
>>           }
>>  */
>>         if ([data length] == 0) // try TIFF instead
>>           {
>>            NSLog(@"Getting PNG data failed! We try TIFF instead ...");
>>            //      NSData *data = [[[rep TIFFRepresentation] retain] 
>> autorelease];
>>            data = [[[rep representationUsingType:NSTIFFFileType 
>> properties:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1] 
>> forKey:@"NSImageInterlaced"]] retain] autorelease];
>>            if ([data length] == 0) NSLog(@"Damn! TIFF failed as well!");
>>           }
>>         [mapView unlockFocus];
>>         NSLog(@"%@ unocked Focus!", mapView);
>>         [rep release];
>>         NS_HANDLER
>>         NSLog(@"Something went terribly wrong: %@", [localException 
>> description]);
>>         //      NSView *clipView = [mapView superview];
>>         //      NSLog(@"clipView %@ bounds %@", NSStringFromRect([clipView 
>> frame]), NSStringFromRect([clipView bounds]));
>>         NS_ENDHANDLER
>>        }
>> 
>>      NSLog(@"data %d", [data length]);
>>      [window release];
>>      [mapView release];
>>      return [NSDictionary dictionaryWithObjectsAndKeys:
>>      [NSNumber numberWithFloat:_visibleMapSection.origin.x], 
>> @"visibleMapSection.origin.x",
>>      [NSNumber numberWithFloat:_visibleMapSection.origin.y], 
>> @"visibleMapSection.origin.y",
>>      [NSNumber numberWithFloat:_visibleMapSection.size.width], 
>> @"visibleMapSection.size.width",
>>      [NSNumber numberWithFloat:_visibleMapSection.size.height], 
>> @"visibleMapSection.size.height",
>>      data, @"imageData",
>>      nil];
>>     }
>>   else return nil;
>> }
>> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]