From: Jay Freeman (saurik) Date: Thu, 26 Jun 2008 01:57:06 +0000 (+0000) Subject: Intial VNC server for the iPhone. X-Git-Tag: v0.9.2591~6 X-Git-Url: https://git.saurik.com/veency.git/commitdiff_plain/57ad730ceeefc9b0fdb8b446d2a47c36399b10b3 Intial VNC server for the iPhone. --- 57ad730ceeefc9b0fdb8b446d2a47c36399b10b3 diff --git a/iphonevnc/LayerKit/LKPurpleServer.h b/iphonevnc/LayerKit/LKPurpleServer.h new file mode 100644 index 0000000..0a24f93 --- /dev/null +++ b/iphonevnc/LayerKit/LKPurpleServer.h @@ -0,0 +1,19 @@ +#ifndef LAYERKIT_LKPURPLESERVER_H_ +#define LAYERKIT_LKPURPLESERVER_H_ + +#include +#include + +#import + +#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 index 0000000..94ae09c --- /dev/null +++ b/iphonevnc/iPhoneVNC.mm @@ -0,0 +1,68 @@ +#import +#import +#import + +#include +#include +#include + +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 index 0000000..71d5a76 --- /dev/null +++ b/iphonevnc/makefile @@ -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