diff options
author | June McEnroe <june@causal.agency> | 2018-02-04 22:30:59 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-02-04 22:30:59 -0500 |
commit | 8142ec7904c1bd5bae590194c75550c25b9a14d3 (patch) | |
tree | c327683af23ea52604fe0cd4487114bacdd85b9a | |
parent | Mark mac target phony (diff) | |
download | src-8142ec7904c1bd5bae590194c75550c25b9a14d3.tar.gz src-8142ec7904c1bd5bae590194c75550c25b9a14d3.zip |
Reuse CGColorSpace and CGDataProvider in gfcocoa
Diffstat (limited to '')
-rw-r--r-- | bin/gfcocoa.m | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/bin/gfcocoa.m b/bin/gfcocoa.m index e6d633c4..def8d960 100644 --- a/bin/gfcocoa.m +++ b/bin/gfcocoa.m @@ -29,10 +29,17 @@ extern void input(char in); @interface BufferView : NSView { size_t bufSize; uint32_t *buf; + CGColorSpaceRef colorSpace; + CGDataProviderRef dataProvider; } @end @implementation BufferView +- (instancetype) initWithFrame: (NSRect) frameRect { + colorSpace = CGColorSpaceCreateDeviceRGB(); + return [super initWithFrame: frameRect]; +} + - (void) draw { draw(buf, [self frame].size.width, [self frame].size.height); [self setNeedsDisplay: YES]; @@ -45,6 +52,8 @@ extern void input(char in); bufSize = newBufSize; buf = malloc(bufSize); if (!buf) err(EX_OSERR, "malloc(%zu)", bufSize); + CGDataProviderRelease(dataProvider); + dataProvider = CGDataProviderCreateWithData(NULL, buf, bufSize, NULL); } [self draw]; } @@ -52,25 +61,15 @@ extern void input(char in); - (void) drawRect: (NSRect) UNUSED dirtyRect { NSSize size = [self frame].size; CGContextRef ctx = [[NSGraphicsContext currentContext] CGContext]; - CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); - CGDataProviderRef data = CGDataProviderCreateWithData(NULL, buf, bufSize, NULL); CGImageRef image = CGImageCreate( - size.width, - size.height, - 8, - 32, - 4 * size.width, - rgb, - kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, - data, - NULL, - false, - kCGRenderingIntentDefault + size.width, size.height, + 8, 32, 4 * size.width, + colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst, + dataProvider, + NULL, false, kCGRenderingIntentDefault ); CGContextDrawImage(ctx, [self frame], image); CGImageRelease(image); - CGDataProviderRelease(data); - CGColorSpaceRelease(rgb); } - (BOOL) acceptsFirstResponder { |