Rasterizer.cpp revision 76f6a86de25e1bf74717e047e55fd44b089673f3
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 "Paint.h" 26#include "SkLayerRasterizer.h" 27#include "core_jni_helpers.h" 28 29// Rasterizer.java holds a pointer (jlong) to this guy 30class NativeRasterizer { 31public: 32 NativeRasterizer() {} 33 virtual ~NativeRasterizer() {} 34 35 // Can return NULL, or a ref to the skia rasterizer. 36 virtual SkRasterizer* refRasterizer() { return NULL; } 37}; 38 39class NativeLayerRasterizer : public NativeRasterizer { 40public: 41 SkLayerRasterizer::Builder fBuilder; 42 43 virtual SkRasterizer* refRasterizer() { 44 return fBuilder.snapshotRasterizer(); 45 } 46}; 47 48SkRasterizer* GraphicsJNI::refNativeRasterizer(jlong rasterizerHandle) { 49 NativeRasterizer* nr = reinterpret_cast<NativeRasterizer*>(rasterizerHandle); 50 return nr ? nr->refRasterizer() : NULL; 51} 52 53/////////////////////////////////////////////////////////////////////////////// 54 55namespace android { 56 57class SkRasterizerGlue { 58public: 59 static void finalizer(JNIEnv* env, jobject clazz, jlong objHandle) { 60 delete reinterpret_cast<NativeRasterizer *>(objHandle); 61 } 62}; 63 64static const JNINativeMethod gRasterizerMethods[] = { 65 {"finalizer", "(J)V", (void*) SkRasterizerGlue::finalizer} 66}; 67 68int register_android_graphics_Rasterizer(JNIEnv* env) { 69 return RegisterMethodsOrDie(env, "android/graphics/Rasterizer", gRasterizerMethods, 70 NELEM(gRasterizerMethods)); 71} 72 73class SkLayerRasterizerGlue { 74public: 75 static jlong create(JNIEnv* env, jobject) { 76 return reinterpret_cast<jlong>(new NativeLayerRasterizer); 77 } 78 79 static void addLayer(JNIEnv* env, jobject, jlong layerHandle, jlong paintHandle, jfloat dx, jfloat dy) { 80 NativeLayerRasterizer* nr = reinterpret_cast<NativeLayerRasterizer *>(layerHandle); 81 const Paint* paint = reinterpret_cast<Paint *>(paintHandle); 82 SkASSERT(nr); 83 SkASSERT(paint); 84 nr->fBuilder.addLayer(*paint, dx, dy); 85 } 86}; 87 88static const JNINativeMethod gLayerRasterizerMethods[] = { 89 { "nativeConstructor", "()J", (void*)SkLayerRasterizerGlue::create }, 90 { "nativeAddLayer", "(JJFF)V", (void*)SkLayerRasterizerGlue::addLayer } 91}; 92 93int register_android_graphics_LayerRasterizer(JNIEnv* env) 94{ 95 return RegisterMethodsOrDie(env, "android/graphics/LayerRasterizer", 96 gLayerRasterizerMethods, NELEM(gLayerRasterizerMethods)); 97} 98 99} 100 101