Index: experimental/HelloSkia/jni/helloskia.cpp |
diff --git a/experimental/HelloSkia/jni/helloskia.cpp b/experimental/HelloSkia/jni/helloskia.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6efa78224a55057e758952a9641a087ff920bc71 |
--- /dev/null |
+++ b/experimental/HelloSkia/jni/helloskia.cpp |
@@ -0,0 +1,65 @@ |
+#include <math.h> |
+#include <time.h> |
+#include <jni.h> |
+#include <android/bitmap.h> |
+ |
+#include "SkCanvas.h" |
+#include "SkGraphics.h" |
+#include "SkSurface.h" |
+#include "SkString.h" |
+#include "SkTime.h" |
+ |
+ |
+static float get_seconds() |
djsollen
2013/06/04 00:26:35
doesn't look like you call this function
Zach Reizner
2013/06/04 14:35:45
Done.
|
+{ |
+ struct timespec currentTime; |
+ clock_gettime(CLOCK_REALTIME, ¤tTime); |
+ return currentTime.tv_sec + (float)currentTime.tv_nsec / 1e9; |
+} |
+ |
+/** |
+ * Draws something into the given bitmap |
+ * @param env |
+ * @param thiz |
+ * @param dstBitmap The bitmap to place the results of skia into |
+ * @param elapsedTime The number of milliseconds since the app was started |
+ */ |
+extern "C" |
+JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv* env, |
+ jobject thiz, jobject dstBitmap, jlong elapsedTime) |
+{ |
+ // Grab the dst bitmap info and pixels |
+ AndroidBitmapInfo dstInfo; |
+ void* dstPixels; |
+ AndroidBitmap_getInfo(env, dstBitmap, &dstInfo); |
+ AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels); |
+ |
+ SkImage::Info info = { |
+ dstInfo.width, dstInfo.height, SkImage::kPMColor_ColorType, SkImage::kPremul_AlphaType |
+ }; |
+ |
+ // Create a surface from the given bitmap |
+ SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels, dstInfo.stride)); |
+ SkCanvas* canvas = surface->getCanvas(); |
+ |
djsollen
2013/06/04 00:26:35
keep the basic text drawing as well, but I like yo
Zach Reizner
2013/06/04 14:35:45
Done.
|
+ // Draw something "interesting" |
+ |
+ // Clear the canvas with a white color |
+ canvas->drawColor(SK_ColorWHITE); |
+ |
+ // Draw some interesting lines using trig functions |
+ SkPaint paint; |
+ paint.setColor(0xFF0000FF); // This is a solid blue color for our lines |
+ paint.setStrokeWidth(SkIntToScalar(2)); // This makes the lines have a thickness of 2 pixels |
+ for (int i = 0; i < 100; i++) |
+ { |
+ float x = (float)i / 99.0f; |
+ float offset = elapsedTime / 1000.0f; |
+ canvas->drawLine(sin(x * M_PI + offset) * 800.0f, 0, // first endpoint |
+ cos(x * M_PI + offset) * 800.0f, 800, // second endpoint |
+ paint); |
+ } |
+ |
+ // Unlock the dst's pixels |
+ AndroidBitmap_unlockPixels(env, dstBitmap); |
+} |