CanvasProperty.cpp revision 76f6a86de25e1bf74717e047e55fd44b089673f3
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"
196ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod#include "Paint.h"
20ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe#include <core_jni_helpers.h>
2152244fff29042926e21fa897ef5ab11148e35299John Reck
229fa4071c4768c63902c6a74a4b480b51a8b95d43John Reck#include <utils/RefBase.h>
2352244fff29042926e21fa897ef5ab11148e35299John Reck#include <CanvasProperty.h>
2452244fff29042926e21fa897ef5ab11148e35299John Reck
2552244fff29042926e21fa897ef5ab11148e35299John Recknamespace android {
2652244fff29042926e21fa897ef5ab11148e35299John Reck
2752244fff29042926e21fa897ef5ab11148e35299John Reck#ifdef USE_OPENGL_RENDERER
28ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampestatic const bool kUseOpenGLRenderer = true;
29ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe#else
30ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampestatic const bool kUseOpenGLRenderer = false;
31ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe#endif
32ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe
33ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampeusing namespace uirenderer;
3452244fff29042926e21fa897ef5ab11148e35299John Reck
3552244fff29042926e21fa897ef5ab11148e35299John Reckstatic jlong createFloat(JNIEnv* env, jobject clazz, jfloat initialValue) {
369fa4071c4768c63902c6a74a4b480b51a8b95d43John Reck    return reinterpret_cast<jlong>(new CanvasPropertyPrimitive(initialValue));
3752244fff29042926e21fa897ef5ab11148e35299John Reck}
3852244fff29042926e21fa897ef5ab11148e35299John Reck
3952244fff29042926e21fa897ef5ab11148e35299John Reckstatic jlong createPaint(JNIEnv* env, jobject clazz, jlong paintPtr) {
406ba30b85ddfbe37c338ee8dde3dd33322eb38d47Behdad Esfahbod    const Paint* paint = reinterpret_cast<const Paint*>(paintPtr);
419fa4071c4768c63902c6a74a4b480b51a8b95d43John Reck    return reinterpret_cast<jlong>(new CanvasPropertyPaint(*paint));
4252244fff29042926e21fa897ef5ab11148e35299John Reck}
4352244fff29042926e21fa897ef5ab11148e35299John Reck
4452244fff29042926e21fa897ef5ab11148e35299John Reck// ----------------------------------------------------------------------------
4552244fff29042926e21fa897ef5ab11148e35299John Reck// JNI Glue
4652244fff29042926e21fa897ef5ab11148e35299John Reck// ----------------------------------------------------------------------------
4752244fff29042926e21fa897ef5ab11148e35299John Reck
4876f6a86de25e1bf74717e047e55fd44b089673f3Daniel Micaystatic const JNINativeMethod gMethods[] = {
4952244fff29042926e21fa897ef5ab11148e35299John Reck    { "nCreateFloat", "(F)J", (void*) createFloat },
5052244fff29042926e21fa897ef5ab11148e35299John Reck    { "nCreatePaint", "(J)J", (void*) createPaint },
5152244fff29042926e21fa897ef5ab11148e35299John Reck};
5252244fff29042926e21fa897ef5ab11148e35299John Reck
5352244fff29042926e21fa897ef5ab11148e35299John Reckint register_android_graphics_CanvasProperty(JNIEnv* env) {
54ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe    if (kUseOpenGLRenderer) {
55ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe        return RegisterMethodsOrDie(env, "android/graphics/CanvasProperty", gMethods,
56ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe                                    NELEM(gMethods));
57ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe    }
58ed6b9dff563c5e22f040ff37e12c0d771e0478aeAndreas Gampe    return 0;
5952244fff29042926e21fa897ef5ab11148e35299John Reck}
6052244fff29042926e21fa897ef5ab11148e35299John Reck
6152244fff29042926e21fa897ef5ab11148e35299John Reck}; // namespace android
62