• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* libs/android_runtime/android/graphics/Rasterizer.cpp
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 // This file was generated from the C++ include file: SkRasterizer.h
19 // Any changes made to this file will be discarded by the build.
20 // To change this file, either edit the include, or device/tools/gluemaker/main.cpp,
21 // or one of the auxilary file specifications in device/tools/gluemaker.
22 
23 #include "jni.h"
24 #include "GraphicsJNI.h"
25 #include "SkLayerRasterizer.h"
26 #include "core_jni_helpers.h"
27 
28 #include <hwui/Paint.h>
29 
30 // Rasterizer.java holds a pointer (jlong) to this guy
31 class NativeRasterizer {
32 public:
NativeRasterizer()33     NativeRasterizer() {}
~NativeRasterizer()34     virtual ~NativeRasterizer() {}
35 
36     // Can return NULL, or a ref to the skia rasterizer.
refRasterizer()37     virtual SkRasterizer* refRasterizer() { return NULL; }
38 };
39 
40 class NativeLayerRasterizer : public NativeRasterizer {
41 public:
42     SkLayerRasterizer::Builder fBuilder;
43 
refRasterizer()44     virtual SkRasterizer* refRasterizer() {
45         return fBuilder.snapshotRasterizer();
46     }
47 };
48 
refNativeRasterizer(jlong rasterizerHandle)49 SkRasterizer* GraphicsJNI::refNativeRasterizer(jlong rasterizerHandle) {
50     NativeRasterizer* nr = reinterpret_cast<NativeRasterizer*>(rasterizerHandle);
51     return nr ? nr->refRasterizer() : NULL;
52 }
53 
54 ///////////////////////////////////////////////////////////////////////////////
55 
56 namespace android {
57 
58 class SkRasterizerGlue {
59 public:
finalizer(JNIEnv * env,jobject clazz,jlong objHandle)60     static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) {
61         delete reinterpret_cast<NativeRasterizer *>(objHandle);
62     }
63 };
64 
65 static const JNINativeMethod gRasterizerMethods[] = {
66     {"finalizer", "(J)V", (void*) SkRasterizerGlue::finalizer}
67 };
68 
register_android_graphics_Rasterizer(JNIEnv * env)69 int register_android_graphics_Rasterizer(JNIEnv* env) {
70     return RegisterMethodsOrDie(env, "android/graphics/Rasterizer", gRasterizerMethods,
71                                 NELEM(gRasterizerMethods));
72 }
73 
74 class SkLayerRasterizerGlue {
75 public:
create(JNIEnv * env,jobject)76     static jlong create(JNIEnv* env, jobject) {
77         return reinterpret_cast<jlong>(new NativeLayerRasterizer);
78     }
79 
addLayer(JNIEnv * env,jobject,jlong layerHandle,jlong paintHandle,jfloat dx,jfloat dy)80     static void addLayer(JNIEnv* env, jobject, jlong layerHandle, jlong paintHandle, jfloat dx, jfloat dy) {
81         NativeLayerRasterizer* nr = reinterpret_cast<NativeLayerRasterizer *>(layerHandle);
82         const Paint* paint = reinterpret_cast<Paint *>(paintHandle);
83         SkASSERT(nr);
84         SkASSERT(paint);
85         nr->fBuilder.addLayer(*paint, dx, dy);
86     }
87 };
88 
89 static const JNINativeMethod gLayerRasterizerMethods[] = {
90     { "nativeConstructor",  "()J",      (void*)SkLayerRasterizerGlue::create    },
91     { "nativeAddLayer",     "(JJFF)V",  (void*)SkLayerRasterizerGlue::addLayer  }
92 };
93 
register_android_graphics_LayerRasterizer(JNIEnv * env)94 int register_android_graphics_LayerRasterizer(JNIEnv* env)
95 {
96     return RegisterMethodsOrDie(env, "android/graphics/LayerRasterizer",
97                                 gLayerRasterizerMethods, NELEM(gLayerRasterizerMethods));
98 }
99 
100 }
101 
102