reed@android.com | 758b129 | 2008-12-18 17:54:12 +0000 | [diff] [blame] | 1 | #include <Carbon/Carbon.h> |
reed@android.com | 0d55f1e | 2008-12-18 19:26:11 +0000 | [diff] [blame^] | 2 | #include "SkCGUtils.h" |
reed@android.com | 758b129 | 2008-12-18 17:54:12 +0000 | [diff] [blame] | 3 | #include "SkCanvas.h" |
| 4 | #include "SkPaint.h" |
| 5 | |
reed@android.com | 758b129 | 2008-12-18 17:54:12 +0000 | [diff] [blame] | 6 | extern "C" void SkiaDraw(CGContextRef cg, CGRect bounds); |
| 7 | |
| 8 | static void sampleDraw(SkCanvas* canvas) { |
| 9 | canvas->drawColor(0xFF0000FF); |
| 10 | |
| 11 | SkPaint paint; |
| 12 | paint.setAntiAlias(true); |
| 13 | |
| 14 | canvas->drawCircle(SkIntToScalar(100), SkIntToScalar(100), |
| 15 | SkIntToScalar(90), paint); |
| 16 | } |
| 17 | |
| 18 | static CGImageRef gImage; |
| 19 | |
| 20 | void SkiaDraw(CGContextRef cg, CGRect bounds) { |
| 21 | if (NULL == gImage) { |
| 22 | SkBitmap bitmap; |
| 23 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, 640, 480); |
| 24 | bitmap.allocPixels(); |
| 25 | |
| 26 | SkCanvas canvas(bitmap); |
| 27 | sampleDraw(&canvas); |
| 28 | |
| 29 | gImage = SkCreateCGImageRef(bitmap); |
| 30 | } |
| 31 | |
| 32 | CGColorRef color = CGColorCreateGenericRGB(1, 1, 1, 1); |
| 33 | CGContextSetFillColorWithColor(cg, color); |
| 34 | CGColorRelease(color); |
| 35 | CGContextFillRect(cg, bounds); |
| 36 | |
| 37 | CGRect r = CGRectMake(0, 0, 640, 480); |
| 38 | |
| 39 | CGContextSaveGState(cg); |
| 40 | CGContextTranslateCTM(cg, 0, r.size.height); |
| 41 | CGContextScaleCTM(cg, 1, -1); |
| 42 | |
| 43 | CGContextDrawImage(cg, r, gImage); |
| 44 | |
| 45 | CGContextRestoreGState(cg); |
| 46 | } |
| 47 | |
| 48 | |