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 <android_runtime/AndroidRuntime.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 JNINativeMethod gXfermodeMethods[] = {
51    {"finalizer", "(J)V", (void*) SkXfermodeGlue::finalizer}
52};
53
54static JNINativeMethod gAvoidMethods[] = {
55    {"nativeCreate", "(III)J", (void*) SkXfermodeGlue::avoid_create}
56};
57
58static JNINativeMethod gPixelXorMethods[] = {
59    {"nativeCreate", "(I)J", (void*) SkXfermodeGlue::pixelxor_create}
60};
61
62#include <android_runtime/AndroidRuntime.h>
63
64#define REG(env, name, array)                                              \
65    result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
66                                                  SK_ARRAY_COUNT(array));  \
67    if (result < 0) return result
68
69int register_android_graphics_Xfermode(JNIEnv* env) {
70    int result;
71
72    REG(env, "android/graphics/Xfermode", gXfermodeMethods);
73    REG(env, "android/graphics/AvoidXfermode", gAvoidMethods);
74    REG(env, "android/graphics/PixelXorXfermode", gPixelXorMethods);
75
76    return 0;
77}
78
79}
80