Re: Taking screen shots
Re: Taking screen shots
- Subject: Re: Taking screen shots
- From: Kevin Meaney <email@hidden>
- Date: Wed, 18 Jun 2014 18:26:15 +0100
> This is NOT OK:
>
> - (void)handleIncomingDrawCommand:(id)drawCommand {
> CGContextRef cgContext = [[NSGraphicsContext currentContext]
> graphicsPort];
> ImmediatelyPerformDrawCommand(drawCommand, cgContext); // NO!
> }
Bugger, that is exactly what I'm doing.
Basically the tool is intended for drawing to an offscreen bitmap. But I got feedback that while testing out scripts people wanted to see what was going on, so I tried having a window associated with the offscreen bitmap that could be shown in a debug mode and blit the offscreen context into the window in the draw rect of the window's content view after setting set needs display. This slowed things down a lot for large bitmaps as I'm not keeping track of what region changed.
So I tried this approach, with a fixed size window and the performance is only slightly slower than working with an offscreen bitmap without a window. I've got a large collection of test scripts producing images and comparing the output to previously produced images and the generated images from the window context are within acceptable tolerances the same images.
The window is fixed size, but the problem occurred when the window was dragged offscreen and if drawing occurred whilst the window was offscreen. SonOfGrab gets the window content correctly.
Thanks for the feedback.
I'll have to think about another approach.
Kevin
> Depending on your application, your listener may need to maintain a
> partial or complete history of draw commands it has received so that it
> can draw them all anew in -drawRect:. If it's too expensive to redraw
> all your commands every time you get sent -drawRect:, you can maintain
> _your own_ offscreen buffer and just blit it to the screen in
> -drawRect:.
>
> // xpc listener
> NSBitmapImageRep *_offscreenBuffer;
> - (void)handleIncomingDrawCommand:(id)drawCommand {
> AppendDrawCommandToQueue(drawCommand); // in case we need to resize
> and redraw the _offscreenBuffer
> PerformQueuedDrawCommands(_offscreenBuffer);
> [_myView setNeedsDisplay:YES];
> }
>
> // view
> - (void)setFrameSize:(NSSize)newSize {
> ResizeBuffer(_offscreenBuffer, newSize);
> PerformQueuedDrawCommands(_offscreenBuffer);
> [super setFrameSize:newSize];
> }
>
> - (void)drawRect:(NSRect)dirtyRect {
> [_offscreenBuffer drawAtPoint:self.bounds.origin];
> }
>
> You can build a CGContextRef around an NSBitmapImageRep by using
> +[NSGraphicsContext graphicsContextWithBitmapImageRep:] and getting the
> result's graphicsPort.
>
> --Kyle Sluder
>
> * not really the only way, but the only supported way that works in all
> cases.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden