OLD | NEW |
1 #include <math.h> | 1 #include <math.h> |
2 #include <jni.h> | 2 #include <jni.h> |
3 #include <android/bitmap.h> | 3 #include <android/bitmap.h> |
4 | 4 |
5 #include "SkCanvas.h" | 5 #include "SkCanvas.h" |
6 #include "SkGraphics.h" | 6 #include "SkGraphics.h" |
7 #include "SkSurface.h" | 7 #include "SkSurface.h" |
8 #include "SkString.h" | 8 #include "SkString.h" |
9 #include "SkTime.h" | 9 #include "SkTime.h" |
10 | 10 |
11 | 11 |
12 /** | 12 /** |
13 * Draws something into the given bitmap | 13 * Draws something into the given bitmap |
14 * @param env | 14 * @param env |
15 * @param thiz | 15 * @param thiz |
16 * @param dstBitmap The bitmap to place the results of skia into | 16 * @param dstBitmap The bitmap to place the results of skia into |
17 * @param elapsedTime The number of milliseconds since the app was started | 17 * @param elapsedTime The number of milliseconds since the app was started |
18 */ | 18 */ |
19 extern "C" | 19 extern "C" |
20 JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv*
env, | 20 JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv*
env, |
21 jobject thiz, jobject dstBitmap, jlong elapsedTime) | 21 jobject thiz, jobject dstBitmap, jlong elapsedTime) |
22 { | 22 { |
23 // Grab the dst bitmap info and pixels | 23 // Grab the dst bitmap info and pixels |
24 AndroidBitmapInfo dstInfo; | 24 AndroidBitmapInfo dstInfo; |
25 void* dstPixels; | 25 void* dstPixels; |
26 AndroidBitmap_getInfo(env, dstBitmap, &dstInfo); | 26 AndroidBitmap_getInfo(env, dstBitmap, &dstInfo); |
27 AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels); | 27 AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels); |
28 | 28 |
29 SkImage::Info info = { | 29 SkImageInfo info = { |
30 dstInfo.width, dstInfo.height, SkImage::kPMColor_ColorType,kPremul_SkAlp
haType | 30 dstInfo.width, dstInfo.height, kPMColor_SkColorType, kPremul_SkAlphaType |
31 }; | 31 }; |
32 | 32 |
33 // Create a surface from the given bitmap | 33 // Create a surface from the given bitmap |
34 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels,
dstInfo.stride)); | 34 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels,
dstInfo.stride)); |
35 SkCanvas* canvas = surface->getCanvas(); | 35 SkCanvas* canvas = surface->getCanvas(); |
36 | 36 |
37 // Draw something "interesting" | 37 // Draw something "interesting" |
38 | 38 |
39 // Clear the canvas with a white color | 39 // Clear the canvas with a white color |
40 canvas->drawColor(SK_ColorWHITE); | 40 canvas->drawColor(SK_ColorWHITE); |
(...skipping 22 matching lines...) Expand all Loading... |
63 float x = (float)i / 99.0f; | 63 float x = (float)i / 99.0f; |
64 float offset = elapsedTime / 1000.0f; | 64 float offset = elapsedTime / 1000.0f; |
65 canvas->drawLine(sin(x * M_PI + offset) * 800.0f, 0, // first endpoint | 65 canvas->drawLine(sin(x * M_PI + offset) * 800.0f, 0, // first endpoint |
66 cos(x * M_PI + offset) * 800.0f, 800, // second endpoin
t | 66 cos(x * M_PI + offset) * 800.0f, 800, // second endpoin
t |
67 paint); // SkPapint to te
ll how to draw the line | 67 paint); // SkPapint to te
ll how to draw the line |
68 } | 68 } |
69 | 69 |
70 // Unlock the dst's pixels | 70 // Unlock the dst's pixels |
71 AndroidBitmap_unlockPixels(env, dstBitmap); | 71 AndroidBitmap_unlockPixels(env, dstBitmap); |
72 } | 72 } |
OLD | NEW |