Xfermode.cpp revision 76f6a86de25e1bf74717e047e55fd44b089673f3
1/*
2 * Copyright (C) 2007 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 "core_jni_helpers.h"
20
21#include "SkAvoidXfermode.h"
22#include "SkPixelXorXfermode.h"
23
24namespace android {
25
26class SkXfermodeGlue {
27public:
28
29    static void finalizer(JNIEnv* env, jobject, jlong objHandle)
30    {
31        SkXfermode* obj = reinterpret_cast<SkXfermode *>(objHandle);
32        SkSafeUnref(obj);
33    }
34
35    static jlong avoid_create(JNIEnv* env, jobject, jint opColor,
36                                jint tolerance, jint modeHandle)
37    {
38        SkAvoidXfermode::Mode mode = static_cast<SkAvoidXfermode::Mode>(modeHandle);
39        return reinterpret_cast<jlong>(SkAvoidXfermode::Create(opColor, tolerance, mode));
40    }
41
42    static jlong pixelxor_create(JNIEnv* env, jobject, jint opColor)
43    {
44        return reinterpret_cast<jlong>(SkPixelXorXfermode::Create(opColor));
45    }
46};
47
48///////////////////////////////////////////////////////////////////////////////
49
50static const JNINativeMethod gXfermodeMethods[] = {
51    {"finalizer", "(J)V", (void*) SkXfermodeGlue::finalizer}
52};
53
54static const JNINativeMethod gAvoidMethods[] = {
55    {"nativeCreate", "(III)J", (void*) SkXfermodeGlue::avoid_create}
56};
57
58static const JNINativeMethod gPixelXorMethods[] = {
59    {"nativeCreate", "(I)J", (void*) SkXfermodeGlue::pixelxor_create}
60};
61
62int register_android_graphics_Xfermode(JNIEnv* env) {
63    android::RegisterMethodsOrDie(env, "android/graphics/Xfermode", gXfermodeMethods,
64                                  NELEM(gXfermodeMethods));
65    android::RegisterMethodsOrDie(env, "android/graphics/Xfermode", gXfermodeMethods,
66                                  NELEM(gXfermodeMethods));
67    android::RegisterMethodsOrDie(env, "android/graphics/AvoidXfermode", gAvoidMethods,
68                                  NELEM(gAvoidMethods));
69    android::RegisterMethodsOrDie(env, "android/graphics/PixelXorXfermode", gPixelXorMethods,
70                                  NELEM(gPixelXorMethods));
71
72    return 0;
73}
74
75}
76