Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 399542a7 authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Add support for SweepGradient in the GL renderer."

parents c2d59124 ee916f14
Loading
Loading
Loading
Loading
+57 −2
Original line number Diff line number Diff line
@@ -318,6 +318,59 @@ static SkShader* SweepGradient_create2(JNIEnv* env, jobject, float x, float y,
    return s;
}

static SkiaShader* SweepGradient_postCreate1(JNIEnv* env, jobject o, SkShader* shader,
        float x, float y, jintArray colorArray, jfloatArray posArray) {
#ifdef USE_OPENGL_RENDERER
    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;
        storedPositions[1] = 1.0f;
    }

    SkiaShader* skiaShader = new SkiaSweepGradientShader(x, y, storedColors, storedPositions, count,
            shader, NULL, (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);

    env->ReleaseIntArrayElements(colorArray, const_cast<jint*>(colorValues), JNI_ABORT);
    return skiaShader;
#else
    return NULL;
#endif
}

static SkiaShader* SweepGradient_postCreate2(JNIEnv* env, jobject o, SkShader* shader,
        float x, float y, int color0, int color1) {
#ifdef USE_OPENGL_RENDERER
    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->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);

    return skiaShader;
#else
    return NULL;
#endif
}

///////////////////////////////////////////////////////////////////////////////////////////////

static SkShader* ComposeShader_create1(JNIEnv* env, jobject o,
@@ -390,7 +443,9 @@ static JNINativeMethod gRadialGradientMethods[] = {

static JNINativeMethod gSweepGradientMethods[] = {
    {"nativeCreate1",      "(FF[I[F)I",  (void*)SweepGradient_create1     },
    {"nativeCreate2",   "(FFII)I",    (void*)SweepGradient_create2   }
    {"nativeCreate2",      "(FFII)I",    (void*)SweepGradient_create2     },
    { "nativePostCreate1", "(IFF[I[F)I", (void*)SweepGradient_postCreate1 },
    { "nativePostCreate2", "(IFFII)I",   (void*)SweepGradient_postCreate2 }
};

static JNINativeMethod gComposeShaderMethods[] = {
+2 −1
Original line number Diff line number Diff line
@@ -71,7 +71,8 @@ public class Shader {
     * @param localM The shader's new local matrix, or null to specify identity
     */
    public void setLocalMatrix(Matrix localM) {
        nativeSetLocalMatrix(native_instance, native_shader, localM.native_instance);
        nativeSetLocalMatrix(native_instance, native_shader,
                localM == null ? 0 : localM.native_instance);
    }

    protected void finalize() throws Throwable {
+9 −4
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public class SweepGradient extends Shader {
                        "color and position arrays must be of equal length");
        }
        native_instance = nativeCreate1(cx, cy, colors, positions);
        native_shader = nativePostCreate1(native_instance, cx, cy, colors, positions);
    }

    /**
@@ -54,11 +55,15 @@ public class SweepGradient extends Shader {
     */
    public SweepGradient(float cx, float cy, int color0, int color1) {
        native_instance = nativeCreate2(cx, cy, color0, color1);
        native_shader = nativePostCreate2(native_instance, cx, cy, color0, color1);
    }

    private static native int nativeCreate1(float x, float y,
                                            int colors[], float positions[]);
    private static native int nativeCreate2(float x, float y,
    private static native int nativeCreate1(float x, float y, int colors[], float positions[]);
    private static native int nativeCreate2(float x, float y, int color0, int color1);

    private static native int nativePostCreate1(int native_shader, float cx, float cy,
            int[] colors, float[] positions);    
    private static native int nativePostCreate2(int native_shader, float cx, float cy,
            int color0, int color1);
}
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ void GradientCache::clear() {
    mCache.clear();
}

Texture* GradientCache::addLinearGradient(SkShader* shader, float* bounds, uint32_t* colors,
Texture* GradientCache::addLinearGradient(SkShader* shader, uint32_t* colors,
        float* positions, int count, SkShader::TileMode tileMode) {
    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1024, 1);
+2 −2
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@ public:
     * Adds a new linear gradient to the cache. The generated texture is
     * returned.
     */
    Texture* addLinearGradient(SkShader* shader, float* bounds, uint32_t* colors,
            float* positions, int count, SkShader::TileMode tileMode);
    Texture* addLinearGradient(SkShader* shader, uint32_t* colors, float* positions,
            int count, SkShader::TileMode tileMode = SkShader::kClamp_TileMode);
    /**
     * Returns the texture associated with the specified shader.
     */
Loading