diff options
author | Chris Craik <ccraik@google.com> | 2014-05-23 23:21:48 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-23 23:21:49 +0000 |
commit | cd3a8245489fa36c528b075efe99a147cf4f6785 (patch) | |
tree | 6631a48645caf9c8142fec9e1ad0fbac0ab9c371 /core/jni | |
parent | c1631fd8908c73b161797919c664edecc9d0c6c4 (diff) | |
parent | 0fa2bd699ab5539c0ce6b79eb6b4b681734b8bb5 (diff) | |
download | frameworks_base-cd3a8245489fa36c528b075efe99a147cf4f6785.zip frameworks_base-cd3a8245489fa36c528b075efe99a147cf4f6785.tar.gz frameworks_base-cd3a8245489fa36c528b075efe99a147cf4f6785.tar.bz2 |
Merge "DO NOT MERGE Inspect SkShader to determine hw shader." into lmp-preview-dev
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/android/graphics/Shader.cpp | 297 | ||||
-rw-r--r-- | core/jni/android_view_GLES20Canvas.cpp | 24 |
2 files changed, 4 insertions, 317 deletions
diff --git a/core/jni/android/graphics/Shader.cpp b/core/jni/android/graphics/Shader.cpp index b389d9e..0cfcaef 100644 --- a/core/jni/android/graphics/Shader.cpp +++ b/core/jni/android/graphics/Shader.cpp @@ -50,26 +50,16 @@ static jint Color_HSVToColor(JNIEnv* env, jobject, jint alpha, jfloatArray hsvAr /////////////////////////////////////////////////////////////////////////////////////////////// -static void Shader_destructor(JNIEnv* env, jobject o, jlong shaderHandle, jlong skiaShaderHandle) +static void Shader_destructor(JNIEnv* env, jobject o, jlong shaderHandle) { SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - SkiaShader* skiaShader = reinterpret_cast<SkiaShader*>(skiaShaderHandle); SkSafeUnref(shader); - // skiaShader == NULL when not !USE_OPENGL_RENDERER, so no need to delete it outside the ifdef -#ifdef USE_OPENGL_RENDERER - if (android::uirenderer::Caches::hasInstance()) { - android::uirenderer::Caches::getInstance().resourceCache.destructor(skiaShader); - } else { - delete skiaShader; - } -#endif } static void Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle, - jlong skiaShaderHandle, jlong matrixHandle) + jlong matrixHandle) { SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - SkiaShader* skiaShader = reinterpret_cast<SkiaShader*>(skiaShaderHandle); const SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); if (shader) { if (NULL == matrix) { @@ -78,9 +68,6 @@ static void Shader_setLocalMatrix(JNIEnv* env, jobject o, jlong shaderHandle, else { shader->setLocalMatrix(*matrix); } -#ifdef USE_OPENGL_RENDERER - skiaShader->setMatrix(const_cast<SkMatrix*>(matrix)); -#endif } } @@ -98,20 +85,6 @@ static jlong BitmapShader_constructor(JNIEnv* env, jobject o, jlong bitmapHandle return reinterpret_cast<jlong>(s); } -static jlong BitmapShader_postConstructor(JNIEnv* env, jobject o, jlong shaderHandle, - jlong bitmapHandle, jint tileModeX, jint tileModeY) { - SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); -#ifdef USE_OPENGL_RENDERER - SkiaShader* skiaShader = new SkiaBitmapShader(bitmap, shader, - static_cast<SkShader::TileMode>(tileModeX), static_cast<SkShader::TileMode>(tileModeY), - NULL, !shader->isOpaque()); - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - /////////////////////////////////////////////////////////////////////////////////////////////// static jlong LinearGradient_create1(JNIEnv* env, jobject o, @@ -141,105 +114,6 @@ static jlong LinearGradient_create1(JNIEnv* env, jobject o, return reinterpret_cast<jlong>(shader); } -static jlong LinearGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle, - jfloat x0, jfloat y0, jfloat x1, jfloat y1, jintArray colorArray, - jfloatArray posArray, jint tileMode) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - size_t count = env->GetArrayLength(colorArray); - const jint* colorValues = env->GetIntArrayElements(colorArray, NULL); - - jfloat* storedBounds = new jfloat[4]; - storedBounds[0] = x0; storedBounds[1] = y0; - storedBounds[2] = x1; storedBounds[3] = y1; - - bool missFirst = false; - bool missLast = false; - size_t stopCount = count; - - jfloat* storedPositions = NULL; - if (posArray) { - AutoJavaFloatArray autoPos(env, posArray, count); - const float* posValues = autoPos.ptr(); - - missFirst = posValues[0] != 0.0f; - missLast = posValues[count - 1] != 1.0f; - - stopCount += missFirst + missLast; - storedPositions = new jfloat[stopCount]; - - if (missFirst) { - storedPositions[0] = 0.0f; - } - - for (size_t i = missFirst; i < count + missFirst; i++) { - storedPositions[i] = posValues[i - missFirst]; - } - - if (missLast) { - storedPositions[stopCount - 1] = 1.0f; - } - } else { - storedPositions = new jfloat[count]; - storedPositions[0] = 0.0f; - const jfloat step = 1.0f / (count - 1); - for (size_t i = 1; i < count - 1; i++) { - storedPositions[i] = step * i; - } - storedPositions[count - 1] = 1.0f; - } - - uint32_t* storedColors = new uint32_t[stopCount]; - - if (missFirst) { - storedColors[0] = static_cast<uint32_t>(colorValues[0]); - } - - for (size_t i = missFirst; i < count + missFirst; i++) { - storedColors[i] = static_cast<uint32_t>(colorValues[i - missFirst]); - } - - if (missLast) { - storedColors[stopCount - 1] = static_cast<uint32_t>(colorValues[count - 1]); - } - - SkiaShader* skiaShader = new SkiaLinearGradientShader(storedBounds, storedColors, - storedPositions, stopCount, shader, static_cast<SkShader::TileMode>(tileMode), NULL, - !shader->isOpaque()); - - env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT); - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - -static jlong LinearGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle, - jfloat x0, jfloat y0, jfloat x1, jfloat y1, jint color0, jint color1, jint tileMode) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - float* storedBounds = new float[4]; - storedBounds[0] = x0; storedBounds[1] = y0; - storedBounds[2] = x1; storedBounds[3] = y1; - - float* storedPositions = new float[2]; - storedPositions[0] = 0.0f; - storedPositions[1] = 1.0f; - - uint32_t* storedColors = new uint32_t[2]; - storedColors[0] = static_cast<uint32_t>(color0); - storedColors[1] = static_cast<uint32_t>(color1); - - SkiaShader* skiaShader = new SkiaLinearGradientShader(storedBounds, storedColors, - storedPositions, 2, shader, static_cast<SkShader::TileMode>(tileMode), NULL, - !shader->isOpaque()); - - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - static jlong LinearGradient_create2(JNIEnv* env, jobject o, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jint color0, jint color1, jint tileMode) @@ -300,67 +174,6 @@ static jlong RadialGradient_create2(JNIEnv* env, jobject, jfloat x, jfloat y, jf return reinterpret_cast<jlong>(s); } -static jlong RadialGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle, - jfloat x, jfloat y, jfloat radius, jintArray colorArray, jfloatArray posArray, jint tileMode) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - size_t count = env->GetArrayLength(colorArray); - const jint* colorValues = env->GetIntArrayElements(colorArray, NULL); - - jfloat* storedPositions = new jfloat[count]; - uint32_t* storedColors = new uint32_t[count]; - for (size_t i = 0; i < count; i++) { - storedColors[i] = static_cast<uint32_t>(colorValues[i]); - } - - if (posArray) { - AutoJavaFloatArray autoPos(env, posArray, count); - const float* posValues = autoPos.ptr(); - for (size_t i = 0; i < count; i++) { - storedPositions[i] = posValues[i]; - } - } else { - storedPositions[0] = 0.0f; - const jfloat step = 1.0f / (count - 1); - for (size_t i = 1; i < count - 1; i++) { - storedPositions[i] = step * i; - } - storedPositions[count - 1] = 1.0f; - } - - SkiaShader* skiaShader = new SkiaCircularGradientShader(x, y, radius, storedColors, - storedPositions, count, shader, (SkShader::TileMode) tileMode, NULL, - !shader->isOpaque()); - - env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT); - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - -static jlong RadialGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle, - jfloat x, jfloat y, jfloat radius, jint color0, jint color1, jint tileMode) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - float* storedPositions = new float[2]; - storedPositions[0] = 0.0f; - storedPositions[1] = 1.0f; - - uint32_t* storedColors = new uint32_t[2]; - storedColors[0] = static_cast<uint32_t>(color0); - storedColors[1] = static_cast<uint32_t>(color1); - - SkiaShader* skiaShader = new SkiaCircularGradientShader(x, y, radius, storedColors, - storedPositions, 2, shader, (SkShader::TileMode) tileMode, NULL, - !shader->isOpaque()); - - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - /////////////////////////////////////////////////////////////////////////////// static jlong SweepGradient_create1(JNIEnv* env, jobject, jfloat x, jfloat y, @@ -393,65 +206,6 @@ static jlong SweepGradient_create2(JNIEnv* env, jobject, jfloat x, jfloat y, return reinterpret_cast<jlong>(s); } -static jlong SweepGradient_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle, - jfloat x, jfloat y, jintArray colorArray, jfloatArray posArray) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - size_t count = env->GetArrayLength(colorArray); - const jint* colorValues = env->GetIntArrayElements(colorArray, NULL); - - jfloat* storedPositions = new jfloat[count]; - uint32_t* storedColors = new uint32_t[count]; - for (size_t i = 0; i < count; i++) { - storedColors[i] = static_cast<uint32_t>(colorValues[i]); - } - - if (posArray) { - AutoJavaFloatArray autoPos(env, posArray, count); - const float* posValues = autoPos.ptr(); - for (size_t i = 0; i < count; i++) { - storedPositions[i] = posValues[i]; - } - } else { - storedPositions[0] = 0.0f; - const jfloat step = 1.0f / (count - 1); - for (size_t i = 1; i < count - 1; i++) { - storedPositions[i] = step * i; - } - storedPositions[count - 1] = 1.0f; - } - - SkiaShader* skiaShader = new SkiaSweepGradientShader(x, y, storedColors, storedPositions, count, - shader, NULL, !shader->isOpaque()); - - env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT); - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - -static jlong SweepGradient_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle, - jfloat x, jfloat y, jint color0, jint color1) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader*>(shaderHandle); - float* storedPositions = new float[2]; - storedPositions[0] = 0.0f; - storedPositions[1] = 1.0f; - - uint32_t* storedColors = new uint32_t[2]; - storedColors[0] = static_cast<uint32_t>(color0); - storedColors[1] = static_cast<uint32_t>(color1); - - SkiaShader* skiaShader = new SkiaSweepGradientShader(x, y, storedColors, storedPositions, 2, - shader, NULL, !shader->isOpaque()); - - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - /////////////////////////////////////////////////////////////////////////////////////////////// static jlong ComposeShader_create1(JNIEnv* env, jobject o, @@ -476,40 +230,6 @@ static jlong ComposeShader_create2(JNIEnv* env, jobject o, return reinterpret_cast<jlong>(shader); } -static jlong ComposeShader_postCreate2(JNIEnv* env, jobject o, jlong shaderHandle, - jlong shaderAHandle, jlong shaderBHandle, jint porterDuffModeHandle) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader *>(shaderHandle); - SkiaShader* shaderA = reinterpret_cast<SkiaShader *>(shaderAHandle); - SkiaShader* shaderB = reinterpret_cast<SkiaShader *>(shaderBHandle); - SkPorterDuff::Mode porterDuffMode = static_cast<SkPorterDuff::Mode>(porterDuffModeHandle); - SkXfermode::Mode mode = SkPorterDuff::ToXfermodeMode(porterDuffMode); - SkiaShader* skiaShader = new SkiaComposeShader(shaderA, shaderB, mode, shader); - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - -static jlong ComposeShader_postCreate1(JNIEnv* env, jobject o, jlong shaderHandle, - jlong shaderAHandle, jlong shaderBHandle, jlong modeHandle) { -#ifdef USE_OPENGL_RENDERER - SkShader* shader = reinterpret_cast<SkShader *>(shaderHandle); - SkiaShader* shaderA = reinterpret_cast<SkiaShader *>(shaderAHandle); - SkiaShader* shaderB = reinterpret_cast<SkiaShader *>(shaderBHandle); - SkXfermode* mode = reinterpret_cast<SkXfermode *>(modeHandle); - SkXfermode::Mode skiaMode; - if (!SkXfermode::AsMode(mode, &skiaMode)) { - // TODO: Support other modes - skiaMode = SkXfermode::kSrcOver_Mode; - } - SkiaShader* skiaShader = new SkiaComposeShader(shaderA, shaderB, skiaMode, shader); - return reinterpret_cast<jlong>(skiaShader); -#else - return NULL; -#endif -} - /////////////////////////////////////////////////////////////////////////////////////////////// static JNINativeMethod gColorMethods[] = { @@ -518,41 +238,32 @@ static JNINativeMethod gColorMethods[] = { }; static JNINativeMethod gShaderMethods[] = { - { "nativeDestructor", "(JJ)V", (void*)Shader_destructor }, - { "nativeSetLocalMatrix", "(JJJ)V", (void*)Shader_setLocalMatrix } + { "nativeDestructor", "(J)V", (void*)Shader_destructor }, + { "nativeSetLocalMatrix", "(JJ)V", (void*)Shader_setLocalMatrix } }; static JNINativeMethod gBitmapShaderMethods[] = { { "nativeCreate", "(JII)J", (void*)BitmapShader_constructor }, - { "nativePostCreate", "(JJII)J", (void*)BitmapShader_postConstructor } }; static JNINativeMethod gLinearGradientMethods[] = { { "nativeCreate1", "(FFFF[I[FI)J", (void*)LinearGradient_create1 }, { "nativeCreate2", "(FFFFIII)J", (void*)LinearGradient_create2 }, - { "nativePostCreate1", "(JFFFF[I[FI)J", (void*)LinearGradient_postCreate1 }, - { "nativePostCreate2", "(JFFFFIII)J", (void*)LinearGradient_postCreate2 } }; static JNINativeMethod gRadialGradientMethods[] = { { "nativeCreate1", "(FFF[I[FI)J", (void*)RadialGradient_create1 }, { "nativeCreate2", "(FFFIII)J", (void*)RadialGradient_create2 }, - { "nativePostCreate1", "(JFFF[I[FI)J", (void*)RadialGradient_postCreate1 }, - { "nativePostCreate2", "(JFFFIII)J", (void*)RadialGradient_postCreate2 } }; static JNINativeMethod gSweepGradientMethods[] = { { "nativeCreate1", "(FF[I[F)J", (void*)SweepGradient_create1 }, { "nativeCreate2", "(FFII)J", (void*)SweepGradient_create2 }, - { "nativePostCreate1", "(JFF[I[F)J", (void*)SweepGradient_postCreate1 }, - { "nativePostCreate2", "(JFFII)J", (void*)SweepGradient_postCreate2 } }; static JNINativeMethod gComposeShaderMethods[] = { { "nativeCreate1", "(JJJ)J", (void*)ComposeShader_create1 }, { "nativeCreate2", "(JJI)J", (void*)ComposeShader_create2 }, - { "nativePostCreate1", "(JJJJ)J", (void*)ComposeShader_postCreate1 }, - { "nativePostCreate2", "(JJJI)J", (void*)ComposeShader_postCreate2 } }; #include <android_runtime/AndroidRuntime.h> diff --git a/core/jni/android_view_GLES20Canvas.cpp b/core/jni/android_view_GLES20Canvas.cpp index 27d3f39..c5dd06f 100644 --- a/core/jni/android_view_GLES20Canvas.cpp +++ b/core/jni/android_view_GLES20Canvas.cpp @@ -45,7 +45,6 @@ #include <DisplayListRenderer.h> #include <LayerRenderer.h> #include <OpenGLRenderer.h> -#include <SkiaShader.h> #include <Stencil.h> #include <Rect.h> #include <RenderNode.h> @@ -85,8 +84,6 @@ using namespace uirenderer; #define RENDERER_LOGD(...) #endif -#define MODIFIER_SHADER 2 - // ---------------------------------------------------------------------------- static struct { @@ -616,24 +613,6 @@ static void android_view_GLES20Canvas_drawLines(JNIEnv* env, jobject clazz, } // ---------------------------------------------------------------------------- -// Shaders and color filters -// ---------------------------------------------------------------------------- - -static void android_view_GLES20Canvas_resetModifiers(JNIEnv* env, jobject clazz, - jlong rendererPtr, jint modifiers) { - OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererPtr); - if (modifiers & MODIFIER_SHADER) renderer->resetShader(); -} - -static void android_view_GLES20Canvas_setupShader(JNIEnv* env, jobject clazz, - jlong rendererPtr, jlong shaderPtr) { - OpenGLRenderer* renderer = reinterpret_cast<OpenGLRenderer*>(rendererPtr); - SkiaShader* shader = reinterpret_cast<SkiaShader*>(shaderPtr); - renderer->setupShader(shader); -} - - -// ---------------------------------------------------------------------------- // Draw filters // ---------------------------------------------------------------------------- @@ -1091,9 +1070,6 @@ static JNINativeMethod gMethods[] = { { "nDrawPath", "(JJJ)V", (void*) android_view_GLES20Canvas_drawPath }, { "nDrawLines", "(J[FIIJ)V", (void*) android_view_GLES20Canvas_drawLines }, - { "nResetModifiers", "(JI)V", (void*) android_view_GLES20Canvas_resetModifiers }, - { "nSetupShader", "(JJ)V", (void*) android_view_GLES20Canvas_setupShader }, - { "nSetupPaintFilter", "(JII)V", (void*) android_view_GLES20Canvas_setupPaintFilter }, { "nResetPaintFilter", "(J)V", (void*) android_view_GLES20Canvas_resetPaintFilter }, |