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

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

Issue 137993012: use some helper Make functions to initialize SkImageInfo (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 11 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
« no previous file with comments | « include/core/SkImageInfo.h ('k') | samplecode/SampleFatBits.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 SkImageInfo info = { 29 SkImageInfo info = SkImageInfo::MakeN32Premul(dstInfo.width, dstInfo.height) ;
30 dstInfo.width, dstInfo.height, kPMColor_SkColorType, kPremul_SkAlphaType
31 };
32 30
33 // Create a surface from the given bitmap 31 // Create a surface from the given bitmap
34 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels, dstInfo.stride)); 32 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels, dstInfo.stride));
35 SkCanvas* canvas = surface->getCanvas(); 33 SkCanvas* canvas = surface->getCanvas();
36 34
37 // Draw something "interesting" 35 // Draw something "interesting"
38 36
39 // Clear the canvas with a white color 37 // Clear the canvas with a white color
40 canvas->drawColor(SK_ColorWHITE); 38 canvas->drawColor(SK_ColorWHITE);
41 39
(...skipping 21 matching lines...) Expand all
63 float x = (float)i / 99.0f; 61 float x = (float)i / 99.0f;
64 float offset = elapsedTime / 1000.0f; 62 float offset = elapsedTime / 1000.0f;
65 canvas->drawLine(sin(x * M_PI + offset) * 800.0f, 0, // first endpoint 63 canvas->drawLine(sin(x * M_PI + offset) * 800.0f, 0, // first endpoint
66 cos(x * M_PI + offset) * 800.0f, 800, // second endpoin t 64 cos(x * M_PI + offset) * 800.0f, 800, // second endpoin t
67 paint); // SkPapint to te ll how to draw the line 65 paint); // SkPapint to te ll how to draw the line
68 } 66 }
69 67
70 // Unlock the dst's pixels 68 // Unlock the dst's pixels
71 AndroidBitmap_unlockPixels(env, dstBitmap); 69 AndroidBitmap_unlockPixels(env, dstBitmap);
72 } 70 }
OLDNEW
« no previous file with comments | « include/core/SkImageInfo.h ('k') | samplecode/SampleFatBits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698