ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/EmulatorView.mm
(Generate patch)

Comparing BasiliskII/src/MacOSX/EmulatorView.mm (file contents):
Revision 1.8 by nigel, 2003-03-11T11:27:20Z vs.
Revision 1.9 by nigel, 2003-03-21T06:41:04Z

# Line 1 | Line 1
1   /*
2 < *      EmulatorView.mm - Custom NSView for Basilisk II graphics output
2 > *      EmulatorView.mm - Custom NSView for Basilisk II windowed graphics output
3   *
4   *      $Id$
5   *
6 < *  Basilisk II (C) 1997-2002 Christian Bauer
6 > *  Basilisk II (C) 1997-2003 Christian Bauer
7   *
8   *  This program is free software; you can redistribute it and/or modify
9   *  it under the terms of the GNU General Public License as published by
# Line 157 | Line 157 | static int prevFlags;
157          int                     i;
158          float           seconds;
159          NSDate          *startDate;
160 +        char            *method;
161  
162          if ( ! drawView )
163 +        {
164 +                WarningSheet (@"The emulator has not been setup yet.",
165 +                                          @"Try to run, then pause the emulator, first.", nil, [self window]);
166                  return;
167 +        }
168  
169          drawView = NO;
170          [self lockFocus];
# Line 178 | Line 183 | static int prevFlags;
183          [self unlockFocus];
184          drawView = YES;
185  
186 <        InfoSheet(@"Benchmark run. 300 frames.",
186 > #ifdef NSBITMAP
187 >        method = "NSBITMAP";
188 > #endif
189 > #ifdef CGIMAGEREF
190 >        method = "CGIMAGEREF";
191 > #endif
192 > #ifdef CGDRAWBITMAP
193 >        method = "CGDRAWBITMAP";
194 > #endif
195 >
196 >        InfoSheet(@"Ran benchmark (300 screen redraws)",
197                            [NSString stringWithFormat:
198 <                                @"%.2f seconds, %.3f frames per second", seconds, i/seconds],
198 >                                @"%.2f seconds, %.3f frames per second (using %s implementation)",
199 >                                seconds, i/seconds, method],
200                            @"Thanks", [self window]);
201   }
202  
# Line 190 | Line 206 | static int prevFlags;
206   #ifdef NSBITMAP
207          return [bitmap TIFFRepresentation];
208   #else
209 <        WarningAlert("How do I get a TIFF from a CGImageRef?");
209 >        NSBitmapImageRep        *b = [NSBitmapImageRep alloc];
210 >
211 >        b = [b initWithBitmapDataPlanes: (unsigned char **) &bitmap
212 >                                                 pixelsWide: x
213 >                                                 pixelsHigh: y
214 >  #ifdef CGIMAGEREF
215 >                                          bitsPerSample: CGImageGetBitsPerComponent(cgImgRep)
216 >                                        samplesPerPixel: 3
217 >                                                   hasAlpha: NO
218 >                                                   isPlanar: NO
219 >                                         colorSpaceName: NSCalibratedRGBColorSpace
220 >                                                bytesPerRow: CGImageGetBytesPerRow(cgImgRep)
221 >                                           bitsPerPixel: CGImageGetBitsPerPixel(cgImgRep)];
222 >  #endif
223 >  #ifdef CGDRAWBITMAP
224 >                                          bitsPerSample: bps
225 >                                        samplesPerPixel: spp
226 >                                                   hasAlpha: hasAlpha
227 >                                                   isPlanar: isPlanar
228 >                                         colorSpaceName: NSCalibratedRGBColorSpace
229 >                                                bytesPerRow: bytesPerRow
230 >                                           bitsPerPixel: bpp];
231 >  #endif
232 >
233 >    if ( ! b )
234 >        {
235 >                ErrorAlert("Could not allocate an NSBitmapImageRep for the TIFF");
236 >                return nil;
237 >        }
238 >
239 >        return [b TIFFRepresentation];
240   #endif
195        return nil;
241   }
242  
243   // Enable display of, and drawing into, the view
# Line 201 | Line 246 | static int prevFlags;
246                    imageWidth: (short) width
247                   imageHeight: (short) height
248   {
204        D(NSLog(@"readyToDraw: theBitmap=%lx\n", theBitmap));
205
206        bitmap = theBitmap;
249          numBytes = [theBitmap bytesPerRow] * height;
250   #endif
251   #ifdef CGIMAGEREF
252   - (void) readyToDraw: (CGImageRef) image
253 +                          bitmap: (void *) theBitmap
254                    imageWidth: (short) width
255                   imageHeight: (short) height
256   {
214        D(NSLog(@"readyToDraw: theBitmap=%lx\n", [cgImgRef bitmap]));
215
257          cgImgRep = image;
258          numBytes = CGImageGetBytesPerRow(image) * height;
259   #endif
# Line 227 | Line 268 | static int prevFlags;
268                          isPlanar: (BOOL)  planar
269                          hasAlpha: (BOOL)  alpha
270   {
230        D(NSLog(@"readyToDraw: theBitmap=%lx\n", theBitmap));
231
232        bitmap = theBitmap;
271          bps = bitsPerSample;
272          spp = samplesPerPixel;
273          bpp = bitsPerPixel;
# Line 238 | Line 276 | static int prevFlags;
276          hasAlpha = alpha;
277          numBytes = bpr * height;
278   #endif
279 +        D(NSLog(@"readyToDraw: theBitmap=%lx\n", theBitmap));
280 +
281 +        bitmap = theBitmap;
282          x = width, y = height;
283          drawView = YES;
284          [[self window] setAcceptsMouseMovedEvents:      YES];
# Line 396 | Line 437 | static NSPoint mouse;                  // Previous/curr
437          ADBMouseUp(0);
438   }
439  
440 < #if DEBUG && ! defined(CGIMAGEREF)
440 > #if DEBUG
441   - (void) randomise              // Draw some coloured snow in the bitmap
442   {
443          unsigned char   *data,
444                                          *pixel;
445  
405  #ifdef CGDRAWBITMAP
406        data = bitmap;
407  #endif
446    #ifdef NSBITMAP
447          data = [bitmap bitmapData];
448 +  #else
449 +        data = bitmap;
450    #endif
451  
452          for ( int i = 0; i < 1000; ++i )
# Line 424 | Line 464 | static NSPoint mouse;                  // Previous/curr
464  
465   #if DEBUG
466          NSLog(@"In drawRect");
427 # ifndef CGIMAGEREF
467          [self randomise];
429 # endif
468   #endif
469  
470   #ifdef NSBITMAP

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines