OLD | NEW |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include <math.h> | 1 #include <math.h> |
9 #include <jni.h> | 2 #include <jni.h> |
10 #include <android/bitmap.h> | 3 #include <android/bitmap.h> |
11 | 4 |
12 #include "SkCanvas.h" | 5 #include "SkCanvas.h" |
13 #include "SkGraphics.h" | 6 #include "SkGraphics.h" |
14 #include "SkSurface.h" | 7 #include "SkSurface.h" |
15 #include "SkString.h" | 8 #include "SkString.h" |
16 #include "SkTime.h" | 9 #include "SkTime.h" |
17 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
29 { | 22 { |
30 // Grab the dst bitmap info and pixels | 23 // Grab the dst bitmap info and pixels |
31 AndroidBitmapInfo dstInfo; | 24 AndroidBitmapInfo dstInfo; |
32 void* dstPixels; | 25 void* dstPixels; |
33 AndroidBitmap_getInfo(env, dstBitmap, &dstInfo); | 26 AndroidBitmap_getInfo(env, dstBitmap, &dstInfo); |
34 AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels); | 27 AndroidBitmap_lockPixels(env, dstBitmap, &dstPixels); |
35 | 28 |
36 SkImageInfo info = SkImageInfo::MakeN32Premul(dstInfo.width, dstInfo.height)
; | 29 SkImageInfo info = SkImageInfo::MakeN32Premul(dstInfo.width, dstInfo.height)
; |
37 | 30 |
38 // Create a surface from the given bitmap | 31 // Create a surface from the given bitmap |
39 sk_sp<SkSurface> surface(SkSurface::MakeRasterDirect(info, dstPixels, dstInf
o.stride)); | 32 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterDirect(info, dstPixels,
dstInfo.stride)); |
40 SkCanvas* canvas = surface->getCanvas(); | 33 SkCanvas* canvas = surface->getCanvas(); |
41 | 34 |
42 // Draw something "interesting" | 35 // Draw something "interesting" |
43 | 36 |
44 // Clear the canvas with a white color | 37 // Clear the canvas with a white color |
45 canvas->drawColor(SK_ColorWHITE); | 38 canvas->drawColor(SK_ColorWHITE); |
46 | 39 |
47 // Setup a SkPaint for drawing our text | 40 // Setup a SkPaint for drawing our text |
48 SkPaint paint; | 41 SkPaint paint; |
49 paint.setColor(SK_ColorBLACK); // This is a solid black color for our text | 42 paint.setColor(SK_ColorBLACK); // This is a solid black color for our text |
(...skipping 18 matching lines...) Expand all Loading... |
68 float x = (float)i / 99.0f; | 61 float x = (float)i / 99.0f; |
69 float offset = elapsedTime / 1000.0f; | 62 float offset = elapsedTime / 1000.0f; |
70 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 |
71 cos(x * M_PI + offset) * 800.0f, 800, // second endpoin
t | 64 cos(x * M_PI + offset) * 800.0f, 800, // second endpoin
t |
72 paint); // SkPapint to te
ll how to draw the line | 65 paint); // SkPapint to te
ll how to draw the line |
73 } | 66 } |
74 | 67 |
75 // Unlock the dst's pixels | 68 // Unlock the dst's pixels |
76 AndroidBitmap_unlockPixels(env, dstBitmap); | 69 AndroidBitmap_unlockPixels(env, dstBitmap); |
77 } | 70 } |
OLD | NEW |