CanvasProperty.cpp revision 52244fff29042926e21fa897ef5ab11148e35299
1/* 2 * Copyright (C) 20014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "jni.h" 18#include "GraphicsJNI.h" 19#include <android_runtime/AndroidRuntime.h> 20 21#include <utils/VirtualLightRefBase.h> 22#include <CanvasProperty.h> 23 24namespace android { 25 26using namespace uirenderer; 27 28#ifdef USE_OPENGL_RENDERER 29 30static jlong incRef(VirtualLightRefBase* ptr) { 31 ptr->incStrong(0); 32 return reinterpret_cast<jlong>(ptr); 33} 34 35static jlong createFloat(JNIEnv* env, jobject clazz, jfloat initialValue) { 36 return incRef(new CanvasPropertyPrimitive(initialValue)); 37} 38 39static jlong createPaint(JNIEnv* env, jobject clazz, jlong paintPtr) { 40 const SkPaint* paint = reinterpret_cast<const SkPaint*>(paintPtr); 41 return incRef(new CanvasPropertyPaint(*paint)); 42} 43 44static void unref(JNIEnv* env, jobject clazz, jlong containerPtr) { 45 reinterpret_cast<VirtualLightRefBase*>(containerPtr)->decStrong(0); 46} 47 48#endif 49 50// ---------------------------------------------------------------------------- 51// JNI Glue 52// ---------------------------------------------------------------------------- 53 54const char* const kClassPathName = "android/graphics/CanvasProperty"; 55 56static JNINativeMethod gMethods[] = { 57#ifdef USE_OPENGL_RENDERER 58 { "nCreateFloat", "(F)J", (void*) createFloat }, 59 { "nCreatePaint", "(J)J", (void*) createPaint }, 60 { "nUnref", "(J)V", (void*) unref }, 61#endif 62}; 63 64int register_android_graphics_CanvasProperty(JNIEnv* env) { 65 return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods)); 66} 67 68}; // namespace android 69