draft test app to show skia in a window
git-svn-id: http://skia.googlecode.com/svn/trunk@32 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/xcode/hostapp/test.cpp b/xcode/hostapp/test.cpp
new file mode 100644
index 0000000..aae344d
--- /dev/null
+++ b/xcode/hostapp/test.cpp
@@ -0,0 +1,48 @@
+#include <Carbon/Carbon.h>
+#include "SkCanvas.h"
+#include "SkPaint.h"
+
+extern CGImageRef SkCreateCGImageRef(const SkBitmap&);
+extern "C" void SkiaDraw(CGContextRef cg, CGRect bounds);
+
+static void sampleDraw(SkCanvas* canvas) {
+ canvas->drawColor(0xFF0000FF);
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+
+ canvas->drawCircle(SkIntToScalar(100), SkIntToScalar(100),
+ SkIntToScalar(90), paint);
+}
+
+static CGImageRef gImage;
+
+void SkiaDraw(CGContextRef cg, CGRect bounds) {
+ if (NULL == gImage) {
+ SkBitmap bitmap;
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, 640, 480);
+ bitmap.allocPixels();
+
+ SkCanvas canvas(bitmap);
+ sampleDraw(&canvas);
+
+ gImage = SkCreateCGImageRef(bitmap);
+ }
+
+ CGColorRef color = CGColorCreateGenericRGB(1, 1, 1, 1);
+ CGContextSetFillColorWithColor(cg, color);
+ CGColorRelease(color);
+ CGContextFillRect(cg, bounds);
+
+ CGRect r = CGRectMake(0, 0, 640, 480);
+
+ CGContextSaveGState(cg);
+ CGContextTranslateCTM(cg, 0, r.size.height);
+ CGContextScaleCTM(cg, 1, -1);
+
+ CGContextDrawImage(cg, r, gImage);
+
+ CGContextRestoreGState(cg);
+}
+
+