The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* libs/android_runtime/android/graphics/ColorFilter.cpp |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include "jni.h" |
| 19 | #include "GraphicsJNI.h" |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 20 | #include "core_jni_helpers.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
| 22 | #include "SkColorFilter.h" |
| 23 | #include "SkColorMatrixFilter.h" |
Chris Craik | 1526a45 | 2015-03-06 18:42:15 +0000 | [diff] [blame] | 24 | #include "SkXfermode.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
Chet Haase | ad93c2b | 2010-10-22 16:17:12 -0700 | [diff] [blame] | 26 | #include <Caches.h> |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 27 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 30 | using namespace uirenderer; |
| 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | class SkColorFilterGlue { |
| 33 | public: |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 34 | static void finalizer(JNIEnv* env, jobject clazz, jlong skFilterHandle) { |
| 35 | SkColorFilter* filter = reinterpret_cast<SkColorFilter *>(skFilterHandle); |
| 36 | if (filter) SkSafeUnref(filter); |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Chris Craik | 1526a45 | 2015-03-06 18:42:15 +0000 | [diff] [blame] | 39 | static jlong CreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor, jint modeHandle) { |
| 40 | SkXfermode::Mode mode = static_cast<SkXfermode::Mode>(modeHandle); |
| 41 | return reinterpret_cast<jlong>(SkColorFilter::CreateModeFilter(srcColor, mode)); |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 44 | static jlong CreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) { |
| 45 | return reinterpret_cast<jlong>(SkColorFilter::CreateLightingFilter(mul, add)); |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 48 | static jlong CreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) { |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 49 | AutoJavaFloatArray autoArray(env, jarray, 20); |
| 50 | const float* src = autoArray.ptr(); |
| 51 | |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 52 | #ifdef SK_SCALAR_IS_FLOAT |
Leon Scroggins | cc11f15 | 2014-03-31 16:52:13 -0400 | [diff] [blame] | 53 | return reinterpret_cast<jlong>(SkColorMatrixFilter::Create(src)); |
Leon Scroggins | 46cb9bd | 2014-03-06 15:36:39 -0500 | [diff] [blame] | 54 | #else |
| 55 | SkASSERT(false); |
Romain Guy | 1639351 | 2010-08-08 00:14:31 -0700 | [diff] [blame] | 56 | #endif |
Romain Guy | db1938e | 2010-08-02 18:50:22 -0700 | [diff] [blame] | 57 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static JNINativeMethod colorfilter_methods[] = { |
Derek Sollenberger | 76d3a1b | 2013-12-10 12:28:58 -0500 | [diff] [blame] | 61 | {"destroyFilter", "(J)V", (void*) SkColorFilterGlue::finalizer} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | static JNINativeMethod porterduff_methods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 65 | { "native_CreatePorterDuffFilter", "(II)J", (void*) SkColorFilterGlue::CreatePorterDuffFilter }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | static JNINativeMethod lighting_methods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 69 | { "native_CreateLightingFilter", "(II)J", (void*) SkColorFilterGlue::CreateLightingFilter }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static JNINativeMethod colormatrix_methods[] = { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 73 | { "nativeColorMatrixFilter", "([F)J", (void*) SkColorFilterGlue::CreateColorMatrixFilter }, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | }; |
| 75 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | int register_android_graphics_ColorFilter(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 77 | android::RegisterMethodsOrDie(env, "android/graphics/ColorFilter", colorfilter_methods, |
| 78 | NELEM(colorfilter_methods)); |
| 79 | android::RegisterMethodsOrDie(env, "android/graphics/PorterDuffColorFilter", porterduff_methods, |
| 80 | NELEM(porterduff_methods)); |
| 81 | android::RegisterMethodsOrDie(env, "android/graphics/LightingColorFilter", lighting_methods, |
| 82 | NELEM(lighting_methods)); |
| 83 | android::RegisterMethodsOrDie(env, "android/graphics/ColorMatrixColorFilter", |
| 84 | colormatrix_methods, NELEM(colormatrix_methods)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | } |