Home | History | Annotate | Download | only in graphics
      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 
     24 namespace android {
     25 
     26 class SkXfermodeGlue {
     27 public:
     28 
     29     static void finalizer(JNIEnv* env, jobject, SkXfermode* obj)
     30     {
     31         SkSafeUnref(obj);
     32     }
     33 
     34     static SkXfermode* avoid_create(JNIEnv* env, jobject, SkColor opColor,
     35                                 U8CPU tolerance, SkAvoidXfermode::Mode mode)
     36     {
     37         return new SkAvoidXfermode(opColor, tolerance, mode);
     38     }
     39 
     40     static SkXfermode* pixelxor_create(JNIEnv* env, jobject, SkColor opColor)
     41     {
     42         return new SkPixelXorXfermode(opColor);
     43     }
     44 };
     45 
     46 ///////////////////////////////////////////////////////////////////////////////
     47 
     48 static JNINativeMethod gXfermodeMethods[] = {
     49     {"finalizer", "(I)V", (void*) SkXfermodeGlue::finalizer}
     50 };
     51 
     52 static JNINativeMethod gAvoidMethods[] = {
     53     {"nativeCreate", "(III)I", (void*) SkXfermodeGlue::avoid_create}
     54 };
     55 
     56 static JNINativeMethod gPixelXorMethods[] = {
     57     {"nativeCreate", "(I)I", (void*) SkXfermodeGlue::pixelxor_create}
     58 };
     59 
     60 #include <android_runtime/AndroidRuntime.h>
     61 
     62 #define REG(env, name, array)                                              \
     63     result = android::AndroidRuntime::registerNativeMethods(env, name, array, \
     64                                                   SK_ARRAY_COUNT(array));  \
     65     if (result < 0) return result
     66 
     67 int register_android_graphics_Xfermode(JNIEnv* env) {
     68     int result;
     69 
     70     REG(env, "android/graphics/Xfermode", gXfermodeMethods);
     71     REG(env, "android/graphics/AvoidXfermode", gAvoidMethods);
     72     REG(env, "android/graphics/PixelXorXfermode", gPixelXorMethods);
     73 
     74     return 0;
     75 }
     76 
     77 }
     78