summaryrefslogtreecommitdiffstats
path: root/core/jni
diff options
context:
space:
mode:
Diffstat (limited to 'core/jni')
-rw-r--r--core/jni/android/graphics/ColorFilter.cpp65
-rw-r--r--core/jni/android_view_GLES20Canvas.cpp14
2 files changed, 57 insertions, 22 deletions
diff --git a/core/jni/android/graphics/ColorFilter.cpp b/core/jni/android/graphics/ColorFilter.cpp
index ebfb209..848234f 100644
--- a/core/jni/android/graphics/ColorFilter.cpp
+++ b/core/jni/android/graphics/ColorFilter.cpp
@@ -23,28 +23,38 @@
#include "SkColorMatrixFilter.h"
#include "SkPorterDuff.h"
+#include <SkiaColorFilter.h>
+
namespace android {
+using namespace uirenderer;
+
class SkColorFilterGlue {
public:
-
- static void finalizer(JNIEnv* env, jobject clazz, SkColorFilter* obj) {
+ static void finalizer(JNIEnv* env, jobject clazz, SkColorFilter* obj, SkiaColorFilter* f) {
+ delete f;
obj->safeUnref();
}
- static SkColorFilter* CreatePorterDuffFilter(JNIEnv* env, jobject,
- jint srcColor, SkPorterDuff::Mode mode) {
- return SkColorFilter::CreateModeFilter(srcColor,
- SkPorterDuff::ToXfermodeMode(mode));
+ static SkColorFilter* CreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor,
+ SkPorterDuff::Mode mode) {
+ return SkColorFilter::CreateModeFilter(srcColor, SkPorterDuff::ToXfermodeMode(mode));
}
- static SkColorFilter* CreateLightingFilter(JNIEnv* env, jobject,
- jint mul, jint add) {
+ static SkiaColorFilter* glCreatePorterDuffFilter(JNIEnv* env, jobject, jint srcColor,
+ SkPorterDuff::Mode mode) {
+ return new SkiaBlendFilter(srcColor, SkPorterDuff::ToXfermodeMode(mode));
+ }
+
+ static SkColorFilter* CreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) {
return SkColorFilter::CreateLightingFilter(mul, add);
}
- static SkColorFilter* CreateColorMatrixFilter(JNIEnv* env, jobject,
- jfloatArray jarray) {
+ static SkiaColorFilter* glCreateLightingFilter(JNIEnv* env, jobject, jint mul, jint add) {
+ return new SkiaLightingFilter(mul, add);
+ }
+
+ static SkColorFilter* CreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) {
AutoJavaFloatArray autoArray(env, jarray, 20);
const float* src = autoArray.ptr();
@@ -58,26 +68,44 @@ public:
return new SkColorMatrixFilter(src);
#endif
}
-
+
+ static SkiaColorFilter* glCreateColorMatrixFilter(JNIEnv* env, jobject, jfloatArray jarray) {
+ AutoJavaFloatArray autoArray(env, jarray, 20);
+ const float* src = autoArray.ptr();
+
+ float* colorMatrix = new float[16];
+ memcpy(colorMatrix, src, 4 * sizeof(float));
+ memcpy(&colorMatrix[4], &src[5], 4 * sizeof(float));
+ memcpy(&colorMatrix[8], &src[10], 4 * sizeof(float));
+ memcpy(&colorMatrix[12], &src[15], 4 * sizeof(float));
+
+ float* colorVector = new float[4];
+ colorVector[0] = src[4];
+ colorVector[1] = src[9];
+ colorVector[2] = src[14];
+ colorVector[3] = src[19];
+
+ return new SkiaColorMatrixFilter(colorMatrix, colorVector);
+ }
};
static JNINativeMethod colorfilter_methods[] = {
- {"finalizer", "(I)V", (void*) SkColorFilterGlue::finalizer}
+ {"finalizer", "(II)V", (void*) SkColorFilterGlue::finalizer}
};
static JNINativeMethod porterduff_methods[] = {
- {"native_CreatePorterDuffFilter","(II)I",
- (void*) SkColorFilterGlue::CreatePorterDuffFilter}
+ { "native_CreatePorterDuffFilter", "(II)I", (void*) SkColorFilterGlue::CreatePorterDuffFilter },
+ { "nCreatePorterDuffFilter", "(II)I", (void*) SkColorFilterGlue::glCreatePorterDuffFilter }
};
static JNINativeMethod lighting_methods[] = {
- {"native_CreateLightingFilter","(II)I",
- (void*) SkColorFilterGlue::CreateLightingFilter}
+ { "native_CreateLightingFilter", "(II)I", (void*) SkColorFilterGlue::CreateLightingFilter },
+ { "nCreateLightingFilter", "(II)I", (void*) SkColorFilterGlue::glCreateLightingFilter },
};
static JNINativeMethod colormatrix_methods[] = {
- {"nativeColorMatrixFilter","([F)I",
- (void*) SkColorFilterGlue::CreateColorMatrixFilter}
+ { "nativeColorMatrixFilter", "([F)I", (void*) SkColorFilterGlue::CreateColorMatrixFilter },
+ { "nColorMatrixFilter", "([F)I", (void*) SkColorFilterGlue::glCreateColorMatrixFilter }
};
#define REG(env, name, array) \
@@ -85,7 +113,6 @@ static JNINativeMethod colormatrix_methods[] = {
SK_ARRAY_COUNT(array)); \
if (result < 0) return result
-
int register_android_graphics_ColorFilter(JNIEnv* env) {
int result;
diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp
index ece9636..142e194 100644
--- a/core/jni/android_view_GLES20Canvas.cpp
+++ b/core/jni/android_view_GLES20Canvas.cpp
@@ -31,6 +31,7 @@
#include <OpenGLRenderer.h>
#include <SkiaShader.h>
+#include <SkiaColorFilter.h>
#include <Rect.h>
#include <ui/Rect.h>
@@ -228,12 +229,13 @@ static void android_view_GLES20Canvas_drawRect(JNIEnv* env, jobject canvas,
}
// ----------------------------------------------------------------------------
-// Shaders
+// Shaders and color filters
// ----------------------------------------------------------------------------
-static void android_view_GLES20Canvas_resetShader(JNIEnv* env, jobject canvas,
+static void android_view_GLES20Canvas_resetModifiers(JNIEnv* env, jobject canvas,
OpenGLRenderer* renderer) {
renderer->resetShader();
+ renderer->resetColorFilter();
}
static void android_view_GLES20Canvas_setupShader(JNIEnv* env, jobject canvas,
@@ -241,6 +243,11 @@ static void android_view_GLES20Canvas_setupShader(JNIEnv* env, jobject canvas,
renderer->setupShader(shader);
}
+static void android_view_GLES20Canvas_setupColorFilter(JNIEnv* env, jobject canvas,
+ OpenGLRenderer* renderer, SkiaColorFilter* filter) {
+ renderer->setupColorFilter(filter);
+}
+
// ----------------------------------------------------------------------------
// Text
// ----------------------------------------------------------------------------
@@ -311,8 +318,9 @@ static JNINativeMethod gMethods[] = {
{ "nDrawColor", "(III)V", (void*) android_view_GLES20Canvas_drawColor },
{ "nDrawRect", "(IFFFFI)V", (void*) android_view_GLES20Canvas_drawRect },
- { "nResetShader", "(I)V", (void*) android_view_GLES20Canvas_resetShader },
+ { "nResetModifiers", "(I)V", (void*) android_view_GLES20Canvas_resetModifiers },
{ "nSetupShader", "(II)V", (void*) android_view_GLES20Canvas_setupShader },
+ { "nSetupColorFilter", "(II)V", (void*) android_view_GLES20Canvas_setupColorFilter },
{ "nDrawText", "(I[CIIFFII)V", (void*) android_view_GLES20Canvas_drawTextArray },
{ "nDrawText", "(ILjava/lang/String;IIFFII)V",