1 #import <CoreFoundation/CFData.h>
2 #import <CoreGraphics/CGBitmapContext.h>
8 extern "C" UIImage *UIGetScreenImage();
10 static const size_t Width = 320;
11 static const size_t Height = 480;
12 static const size_t BytesPerPixel = 4;
13 static const size_t BitsPerComponent = 8;
15 static const size_t Stride = Width * BytesPerPixel;
16 static const size_t Size32 = Width * Height;
17 static const size_t Size8 = Size32 * BytesPerPixel;
19 CGContextRef CreateContext() {
20 uint8_t *buffer = (uint8_t *) malloc(Size8);
24 CGColorSpaceRef space = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
26 CGContextRef context = CGBitmapContextCreate(buffer, Width, Height, BitsPerComponent, Stride, space, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
30 CGColorSpaceRelease(space);
34 int main(int argc, char *argv[]) {
35 CGContextRef context0 = CreateContext();
36 CGContextRef context1 = CreateContext();
38 CGRect rect = CGRectMake(0, 0, Width, Height);
40 rfbScreenInfoPtr screen = rfbGetScreen(&argc, argv, Width, Height, BitsPerComponent, 3, BytesPerPixel);
42 screen->desktopName = "iPhone";
43 screen->alwaysShared = TRUE;
45 rfbInitServer(screen);
48 CGContextRef context = context1;
52 uint8_t *buffer0 = (uint8_t *) CGBitmapContextGetData(context0);
53 uint8_t *buffer1 = (uint8_t *) CGBitmapContextGetData(context1);
54 screen->frameBuffer = (char *) buffer0;
56 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
58 UIImageRef *image = UIGetScreenImage();
59 CGImageRef ref = [image CGImage];
60 CGContextDrawImage(context0, rect, ref);
64 if (memcmp(buffer0, buffer1, Size8) != 0)
65 rfbMarkRectAsModified(screen, 0, 0, Width, Height);
66 rfbProcessEvents(screen, 100000);
70 rfbScreenCleanup(screen);