]> git.saurik.com Git - veency.git/commitdiff
Intial VNC server for the iPhone.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 26 Jun 2008 01:57:06 +0000 (01:57 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 26 Jun 2008 01:57:06 +0000 (01:57 +0000)
iphonevnc/LayerKit/LKPurpleServer.h [new file with mode: 0644]
iphonevnc/iPhoneVNC.mm [new file with mode: 0644]
iphonevnc/makefile [new file with mode: 0644]

diff --git a/iphonevnc/LayerKit/LKPurpleServer.h b/iphonevnc/LayerKit/LKPurpleServer.h
new file mode 100644 (file)
index 0000000..0a24f93
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef LAYERKIT_LKPURPLESERVER_H_
+#define LAYERKIT_LKPURPLESERVER_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#import <CoreGraphics/CGImage.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+CGImageRef LKPurpleServerGetScreenImage(void *null);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif/*LAYERKIT_LKPURPLESERVER_H_*/
diff --git a/iphonevnc/iPhoneVNC.mm b/iphonevnc/iPhoneVNC.mm
new file mode 100644 (file)
index 0000000..94ae09c
--- /dev/null
@@ -0,0 +1,68 @@
+#import <LayerKit/LKPurpleServer.h>
+#import <CoreFoundation/CFData.h>
+#import <CoreGraphics/CGBitmapContext.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <rfb/rfb.h>
+
+static const size_t Width = 320;
+static const size_t Height = 480;
+static const size_t BytesPerPixel = 4;
+static const size_t BitsPerComponent = 8;
+
+static const size_t Stride = Width * BytesPerPixel;
+static const size_t Size32 = Width * Height;
+static const size_t Size8 = Size32 * BytesPerPixel;
+
+CGContextRef CreateContext() {
+    uint8_t *buffer = (uint8_t *) malloc(Size8);
+    if (buffer == NULL)
+        return NULL;
+
+    CGColorSpaceRef space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
+
+    CGContextRef context = CGBitmapContextCreate(buffer, Width, Height, BitsPerComponent, Stride, space, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
+    if (context == NULL)
+        free(buffer);
+
+    CGColorSpaceRelease(space);
+    return context;
+}
+
+int main(int argc, char *argv[]) {
+    CGContextRef context0 = CreateContext();
+    CGContextRef context1 = CreateContext();
+
+    CGRect rect = CGRectMake(0, 0, Width, Height);
+
+    rfbScreenInfoPtr screen = rfbGetScreen(&argc, argv, Width, Height, BitsPerComponent, 3, BytesPerPixel);
+
+    screen->desktopName = "iPhone";
+    screen->alwaysShared = TRUE;
+
+    rfbInitServer(screen);
+
+    for (;;) {
+        CGContextRef context = context1;
+        context1 = context0;
+        context0 = context;
+
+        uint8_t *buffer0 = (uint8_t *) CGBitmapContextGetData(context0);
+        uint8_t *buffer1 = (uint8_t *) CGBitmapContextGetData(context1);
+        screen->frameBuffer = (char *) buffer0;
+
+        CGImageRef image = LKPurpleServerGetScreenImage(NULL);
+        CGContextDrawImage(context0, rect, image);
+        CFRelease(image);
+
+        if (memcmp(buffer0, buffer1, Size8) != 0)
+            rfbMarkRectAsModified(screen, 0, 0, Width, Height);
+        rfbProcessEvents(screen, 100000);
+    }
+
+
+    rfbScreenCleanup(screen);
+
+    return 0;
+}
diff --git a/iphonevnc/makefile b/iphonevnc/makefile
new file mode 100644 (file)
index 0000000..71d5a76
--- /dev/null
@@ -0,0 +1,16 @@
+all: iPhoneVNC
+
+clean:
+       rm -f iPhoneVNC
+
+test: all
+       ./iPhoneVNC
+
+iPhoneVNC: iPhoneVNC.mm makefile
+       g++ -g0 -O3 -o $@ $< -I. \
+            -lvncserver -lz \
+           -framework CoreFoundation \
+           -framework CoreGraphics \
+           -framework LayerKit
+
+.PHONY: all clean test