Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: platform_tools/android/examples/hello_skia_app/jni/helloskia.cpp

Issue 16336004: create simple skia app for android using jni (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: remove binary files Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 #include <math.h>
2 #include <jni.h>
3 #include <android/bitmap.h>
4
5 #include "SkCanvas.h"
6 #include "SkGraphics.h"
7 #include "SkSurface.h"
8 #include "SkString.h"
9 #include "SkTime.h"
10
11
12 /**
13 * Draws something into the given bitmap
14 * @param env
15 * @param thiz
16 * @param dstBitmap The bitmap to place the results of skia into
17 * @param elapsedTime The number of milliseconds since the app was started
18 */
19 extern "C"
20 JNIEXPORT void JNICALL Java_com_example_HelloSkiaActivity_drawIntoBitmap(JNIEnv* env,
21 jobject thiz, jobject dstBitmap, jlong elapsedTime)
22 {
23 // Grab the dst bitmap info and pixels
24 AndroidBitmapInfo dstInfo;
25 void* dstPixels;
26 AndroidBitmap_getInfo(env, dstBitmap, &dstInfo);
27 AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels);
28
29 SkImage::Info info = {
30 dstInfo.width, dstInfo.height, SkImage::kPMColor_ColorType, SkImage::kPr emul_AlphaType
31 };
32
33 // Create a surface from the given bitmap
34 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels, dstInfo.stride));
35 SkCanvas* canvas = surface->getCanvas();
36
37 // Draw something "interesting"
38
39 // Clear the canvas with a white color
40 canvas->drawColor(SK_ColorWHITE);
41
42 // Setup a SkPaint for drawing our text
43 SkPaint paint;
44 paint.setColor(SK_ColorBLACK); // This is a solid black color for our text
45 paint.setTextSize(SkIntToScalar(30)); // Sets the text size to 30 pixels
46 paint.setAntiAlias(true); // We turn on anti-aliasing so that the text to lo oks good.
47
48 // Draw some text
49 SkString text("Skia is Best!");
50 SkScalar fontHeight = paint.getFontSpacing();
51 canvas->drawText(text.c_str(), text.size(), // text's data and length
52 10, fontHeight, // X and Y coordinates to place the text
53 paint); // SkPaint to tell how to draw t he text
54
55 // Adapt the SkPaint for drawing blue lines
56 paint.setAntiAlias(false); // Turning off anti-aliasing speeds up the line d rawing
57 paint.setColor(0xFF0000FF); // This is a solid blue color for our lines
58 paint.setStrokeWidth(SkIntToScalar(2)); // This makes the lines have a thick ness of 2 pixels
59
60 // Draw some interesting lines using trig functions
61 for (int i = 0; i < 100; i++)
62 {
63 float x = (float)i / 99.0f;
64 float offset = elapsedTime / 1000.0f;
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
67 paint); // SkPapint to te ll how to draw the line
68 }
69
70 // Unlock the dst's pixels
71 AndroidBitmap_unlockPixels(env, dstBitmap);
72 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698