aboutsummaryrefslogtreecommitdiffhomepage
path: root/xcode/hostapp/test.cpp
diff options
context:
space:
mode:
authorGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2008-12-18 17:54:12 +0000
committerGravatar reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2008-12-18 17:54:12 +0000
commit758b129f11d8ce2d2235f73ea4523f21f3d8b079 (patch)
tree6460990d5903c0ae120359ff146f7ecd2aac0b19 /xcode/hostapp/test.cpp
parent9fb1731ef2b279da54d3d3e0fa04d1e0e5c3651a (diff)
draft test app to show skia in a window
git-svn-id: http://skia.googlecode.com/svn/trunk@32 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'xcode/hostapp/test.cpp')
-rw-r--r--xcode/hostapp/test.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/xcode/hostapp/test.cpp b/xcode/hostapp/test.cpp
new file mode 100644
index 0000000000..aae344d049
--- /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);
+}
+
+