CanvasProperty.cpp revision 52244fff29042926e21fa897ef5ab11148e35299
152244fff29042926e21fa897ef5ab11148e35299John Reck/*
252244fff29042926e21fa897ef5ab11148e35299John Reck * Copyright (C) 20014 The Android Open Source Project
352244fff29042926e21fa897ef5ab11148e35299John Reck *
452244fff29042926e21fa897ef5ab11148e35299John Reck * Licensed under the Apache License, Version 2.0 (the "License");
552244fff29042926e21fa897ef5ab11148e35299John Reck * you may not use this file except in compliance with the License.
652244fff29042926e21fa897ef5ab11148e35299John Reck * You may obtain a copy of the License at
752244fff29042926e21fa897ef5ab11148e35299John Reck *
852244fff29042926e21fa897ef5ab11148e35299John Reck *      http://www.apache.org/licenses/LICENSE-2.0
952244fff29042926e21fa897ef5ab11148e35299John Reck *
1052244fff29042926e21fa897ef5ab11148e35299John Reck * Unless required by applicable law or agreed to in writing, software
1152244fff29042926e21fa897ef5ab11148e35299John Reck * distributed under the License is distributed on an "AS IS" BASIS,
1252244fff29042926e21fa897ef5ab11148e35299John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1352244fff29042926e21fa897ef5ab11148e35299John Reck * See the License for the specific language governing permissions and
1452244fff29042926e21fa897ef5ab11148e35299John Reck * limitations under the License.
1552244fff29042926e21fa897ef5ab11148e35299John Reck */
1652244fff29042926e21fa897ef5ab11148e35299John Reck
1752244fff29042926e21fa897ef5ab11148e35299John Reck#include "jni.h"
1852244fff29042926e21fa897ef5ab11148e35299John Reck#include "GraphicsJNI.h"
1952244fff29042926e21fa897ef5ab11148e35299John Reck#include <android_runtime/AndroidRuntime.h>
2052244fff29042926e21fa897ef5ab11148e35299John Reck
2152244fff29042926e21fa897ef5ab11148e35299John Reck#include <utils/VirtualLightRefBase.h>
2252244fff29042926e21fa897ef5ab11148e35299John Reck#include <CanvasProperty.h>
2352244fff29042926e21fa897ef5ab11148e35299John Reck
2452244fff29042926e21fa897ef5ab11148e35299John Recknamespace android {
2552244fff29042926e21fa897ef5ab11148e35299John Reck
2652244fff29042926e21fa897ef5ab11148e35299John Reckusing namespace uirenderer;
2752244fff29042926e21fa897ef5ab11148e35299John Reck
2852244fff29042926e21fa897ef5ab11148e35299John Reck#ifdef USE_OPENGL_RENDERER
2952244fff29042926e21fa897ef5ab11148e35299John Reck
3052244fff29042926e21fa897ef5ab11148e35299John Reckstatic jlong incRef(VirtualLightRefBase* ptr) {
3152244fff29042926e21fa897ef5ab11148e35299John Reck    ptr->incStrong(0);
3252244fff29042926e21fa897ef5ab11148e35299John Reck    return reinterpret_cast<jlong>(ptr);
3352244fff29042926e21fa897ef5ab11148e35299John Reck}
3452244fff29042926e21fa897ef5ab11148e35299John Reck
3552244fff29042926e21fa897ef5ab11148e35299John Reckstatic jlong createFloat(JNIEnv* env, jobject clazz, jfloat initialValue) {
3652244fff29042926e21fa897ef5ab11148e35299John Reck    return incRef(new CanvasPropertyPrimitive(initialValue));
3752244fff29042926e21fa897ef5ab11148e35299John Reck}
3852244fff29042926e21fa897ef5ab11148e35299John Reck
3952244fff29042926e21fa897ef5ab11148e35299John Reckstatic jlong createPaint(JNIEnv* env, jobject clazz, jlong paintPtr) {
4052244fff29042926e21fa897ef5ab11148e35299John Reck    const SkPaint* paint = reinterpret_cast<const SkPaint*>(paintPtr);
4152244fff29042926e21fa897ef5ab11148e35299John Reck    return incRef(new CanvasPropertyPaint(*paint));
4252244fff29042926e21fa897ef5ab11148e35299John Reck}
4352244fff29042926e21fa897ef5ab11148e35299John Reck
4452244fff29042926e21fa897ef5ab11148e35299John Reckstatic void unref(JNIEnv* env, jobject clazz, jlong containerPtr) {
4552244fff29042926e21fa897ef5ab11148e35299John Reck    reinterpret_cast<VirtualLightRefBase*>(containerPtr)->decStrong(0);
4652244fff29042926e21fa897ef5ab11148e35299John Reck}
4752244fff29042926e21fa897ef5ab11148e35299John Reck
4852244fff29042926e21fa897ef5ab11148e35299John Reck#endif
4952244fff29042926e21fa897ef5ab11148e35299John Reck
5052244fff29042926e21fa897ef5ab11148e35299John Reck// ----------------------------------------------------------------------------
5152244fff29042926e21fa897ef5ab11148e35299John Reck// JNI Glue
5252244fff29042926e21fa897ef5ab11148e35299John Reck// ----------------------------------------------------------------------------
5352244fff29042926e21fa897ef5ab11148e35299John Reck
5452244fff29042926e21fa897ef5ab11148e35299John Reckconst char* const kClassPathName = "android/graphics/CanvasProperty";
5552244fff29042926e21fa897ef5ab11148e35299John Reck
5652244fff29042926e21fa897ef5ab11148e35299John Reckstatic JNINativeMethod gMethods[] = {
5752244fff29042926e21fa897ef5ab11148e35299John Reck#ifdef USE_OPENGL_RENDERER
5852244fff29042926e21fa897ef5ab11148e35299John Reck    { "nCreateFloat", "(F)J", (void*) createFloat },
5952244fff29042926e21fa897ef5ab11148e35299John Reck    { "nCreatePaint", "(J)J", (void*) createPaint },
6052244fff29042926e21fa897ef5ab11148e35299John Reck    { "nUnref", "(J)V", (void*) unref },
6152244fff29042926e21fa897ef5ab11148e35299John Reck#endif
6252244fff29042926e21fa897ef5ab11148e35299John Reck};
6352244fff29042926e21fa897ef5ab11148e35299John Reck
6452244fff29042926e21fa897ef5ab11148e35299John Reckint register_android_graphics_CanvasProperty(JNIEnv* env) {
6552244fff29042926e21fa897ef5ab11148e35299John Reck    return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
6652244fff29042926e21fa897ef5ab11148e35299John Reck}
6752244fff29042926e21fa897ef5ab11148e35299John Reck
6852244fff29042926e21fa897ef5ab11148e35299John Reck}; // namespace android
69