blob: d03bcf0fe3ac9aa1b1381f3579f614ea3f5331ce [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/* 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 Gampeed6b9df2014-11-20 22:02:20 -080020#include "core_jni_helpers.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021
22#include "SkColorFilter.h"
23#include "SkColorMatrixFilter.h"
Chris Craik1526a452015-03-06 18:42:15 +000024#include "SkXfermode.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
Chet Haasead93c2b2010-10-22 16:17:12 -070026#include <Caches.h>
Romain Guydb1938e2010-08-02 18:50:22 -070027
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028namespace android {
29
Romain Guydb1938e2010-08-02 18:50:22 -070030using namespace uirenderer;
31
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080032class SkColorFilterGlue {
33public:
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050034 static void finalizer(JNIEnv* env, jobject clazz, jlong skFilterHandle) {
35 SkColorFilter* filter = reinterpret_cast<SkColorFilter *>(skFilterHandle);
36 if (filter) SkSafeUnref(filter);
Romain Guy16393512010-08-08 00:14:31 -070037 }
38
Chris Craik1526a452015-03-06 18:42:15 +000039 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 Guy16393512010-08-08 00:14:31 -070042 }
43
Ashok Bhat36bef0b2014-01-20 20:08:01 +000044 static jlong CreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) {
45 return reinterpret_cast<jlong>(SkColorFilter::CreateLightingFilter(mul, add));
Romain Guy16393512010-08-08 00:14:31 -070046 }
47
Ashok Bhat36bef0b2014-01-20 20:08:01 +000048 static jlong CreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) {
Romain Guy16393512010-08-08 00:14:31 -070049 AutoJavaFloatArray autoArray(env, jarray, 20);
50 const float* src = autoArray.ptr();
51
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050052#ifdef SK_SCALAR_IS_FLOAT
Leon Scrogginscc11f152014-03-31 16:52:13 -040053 return reinterpret_cast<jlong>(SkColorMatrixFilter::Create(src));
Leon Scroggins46cb9bd2014-03-06 15:36:39 -050054#else
55 SkASSERT(false);
Romain Guy16393512010-08-08 00:14:31 -070056#endif
Romain Guydb1938e2010-08-02 18:50:22 -070057 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058};
59
60static JNINativeMethod colorfilter_methods[] = {
Derek Sollenberger76d3a1b2013-12-10 12:28:58 -050061 {"destroyFilter", "(J)V", (void*) SkColorFilterGlue::finalizer}
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062};
63
64static JNINativeMethod porterduff_methods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000065 { "native_CreatePorterDuffFilter", "(II)J", (void*) SkColorFilterGlue::CreatePorterDuffFilter },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080066};
67
68static JNINativeMethod lighting_methods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000069 { "native_CreateLightingFilter", "(II)J", (void*) SkColorFilterGlue::CreateLightingFilter },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080070};
71
72static JNINativeMethod colormatrix_methods[] = {
Ashok Bhat36bef0b2014-01-20 20:08:01 +000073 { "nativeColorMatrixFilter", "([F)J", (void*) SkColorFilterGlue::CreateColorMatrixFilter },
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074};
75
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080076int register_android_graphics_ColorFilter(JNIEnv* env) {
Andreas Gampeed6b9df2014-11-20 22:02:20 -080077 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 Project9066cfe2009-03-03 19:31:44 -080085
86 return 0;
87}
88
89}