Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #include <math.h> | |
| 2 #include <time.h> | |
| 3 #include <jni.h> | |
| 4 #include <android/bitmap.h> | |
| 5 | |
| 6 #include "SkCanvas.h" | |
| 7 #include "SkGraphics.h" | |
| 8 #include "SkSurface.h" | |
| 9 #include "SkString.h" | |
| 10 #include "SkTime.h" | |
| 11 | |
| 12 | |
| 13 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.
| |
| 14 { | |
| 15 struct timespec currentTime; | |
| 16 clock_gettime(CLOCK_REALTIME, ¤tTime); | |
| 17 return currentTime.tv_sec + (float)currentTime.tv_nsec / 1e9; | |
| 18 } | |
| 19 | |
| 20 /** | |
| 21 * Draws something into the given bitmap | |
| 22 * @param env | |
| 23 * @param thiz | |
| 24 * @param dstBitmap The bitmap to place the results of skia into | |
| 25 * @param elapsedTime The number of milliseconds since the app was started | |
| 26 */ | |
| 27 extern "C" | |
| 28 JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv* env, | |
| 29 jobject thiz, jobject dstBitmap, jlong elapsedTime) | |
| 30 { | |
| 31 // Grab the dst bitmap info and pixels | |
| 32 AndroidBitmapInfo dstInfo; | |
| 33 void* dstPixels; | |
| 34 AndroidBitmap_getInfo(env, dstBitmap, &dstInfo); | |
| 35 AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels); | |
| 36 | |
| 37 SkImage::Info info = { | |
| 38 dstInfo.width, dstInfo.height, SkImage::kPMColor_ColorType, SkImage::kPr emul_AlphaType | |
| 39 }; | |
| 40 | |
| 41 // Create a surface from the given bitmap | |
| 42 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels, dstInfo.stride)); | |
| 43 SkCanvas* canvas = surface->getCanvas(); | |
| 44 | |
|
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.
| |
| 45 // Draw something "interesting" | |
| 46 | |
| 47 // Clear the canvas with a white color | |
| 48 canvas->drawColor(SK_ColorWHITE); | |
| 49 | |
| 50 // Draw some interesting lines using trig functions | |
| 51 SkPaint paint; | |
| 52 paint.setColor(0xFF0000FF); // This is a solid blue color for our lines | |
| 53 paint.setStrokeWidth(SkIntToScalar(2)); // This makes the lines have a thick ness of 2 pixels | |
| 54 for (int i = 0; i < 100; i++) | |
| 55 { | |
| 56 float x = (float)i / 99.0f; | |
| 57 float offset = elapsedTime / 1000.0f; | |
| 58 canvas->drawLine(sin(x * M_PI + offset) * 800.0f, 0, // first endpoint | |
| 59 cos(x * M_PI + offset) * 800.0f, 800, // second endpoin t | |
| 60 paint); | |
| 61 } | |
| 62 | |
| 63 // Unlock the dst's pixels | |
| 64 AndroidBitmap_unlockPixels(env, dstBitmap); | |
| 65 } | |
| OLD | NEW |