summary refs log tree commit diff
path: root/bin/gfcocoa.m
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2018-02-04 22:30:59 -0500
committerJune McEnroe <programble@gmail.com>2018-02-04 22:30:59 -0500
commit2a0e262253f3849362f7ac4db6f5e8bb04d77491 (patch)
tree2bc435110d641775e1fa3263810b45e4ea73f022 /bin/gfcocoa.m
parentMark mac target phony (diff)
downloadsrc-2a0e262253f3849362f7ac4db6f5e8bb04d77491.tar.gz
src-2a0e262253f3849362f7ac4db6f5e8bb04d77491.zip
Reuse CGColorSpace and CGDataProvider in gfcocoa
Diffstat (limited to '')
-rw-r--r--bin/gfcocoa.m29
1 files changed, 14 insertions, 15 deletions
diff --git a/bin/gfcocoa.m b/bin/gfcocoa.m
index d91107b9..0e2fbe2c 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 {
-06-03 10:34:51 -0400'>2022-06-03Stop polling stdin after EOFJune McEnroe 2022-06-02Set TABSIZE=4June McEnroe 2022-06-02Do basic match highlightingJune McEnroe 2022-06-02Clean up parsing a littleJune McEnroe 2022-06-02Don't duplicate path stringJune McEnroe 2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe 2022-06-02Add initial working version of qfJune McEnroe 2022-05-29Set prompt for okshJune McEnroe