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

Commit f9764a4f authored by Romain Guy's avatar Romain Guy
Browse files

Add program for linear gradient.

This change adds a new DrawLinearGradientProgram class to enable the drawing
of linear gradients. Two new vertex and fragment shaders are introduced,
based on DrawTextureProgram's shaders.

Change-Id: I885afc076bb6cef8cd3962ae21a086fa6a03bf96
parent 7fac2e18
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -241,8 +241,8 @@ static void android_view_GLES20Canvas_setupBitmapShader(JNIEnv* env, jobject can
static void android_view_GLES20Canvas_setupLinearShader(JNIEnv* env, jobject canvas,
        OpenGLRenderer* renderer, SkShader* shader, float* bounds, uint32_t* colors,
        float* positions, SkShader::TileMode tileMode, SkMatrix* matrix) {
    renderer->setupLinearGradientShader(bounds, colors, positions, tileMode, matrix,
            (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
    renderer->setupLinearGradientShader(shader, bounds, colors, positions, tileMode,
            matrix, (shader->getFlags() & SkShader::kOpaqueAlpha_Flag) == 0);
}

// ----------------------------------------------------------------------------
+5 −2
Original line number Diff line number Diff line
@@ -80,9 +80,12 @@ public class LinearGradient extends Shader {
    }
    
    protected void finalize() throws Throwable {
        try {
            super.finalize();
        } finally {
            nativeDestructor(native_instance);
        }
    }

    private native void nativeDestructor(int native_shader);
	private native int nativeCreate1(float x0, float y0, float x1, float y1,
+5 −2
Original line number Diff line number Diff line
@@ -79,9 +79,12 @@ public class Shader {
    }

    protected void finalize() throws Throwable {
        try {
            super.finalize();
        } finally {
            nativeDestructor(native_instance);
        }
    }

    private static native void nativeDestructor(int native_shader);
    private static native boolean nativeGetLocalMatrix(int native_shader,
+5 −1
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ OpenGLRenderer::OpenGLRenderer():

    mDrawColorProgram = new DrawColorProgram;
    mDrawTextureProgram = new DrawTextureProgram;
    mDrawLinearGradientProgram = new DrawLinearGradientProgram;
    mCurrentProgram = mDrawTextureProgram;

    mShader = kShaderNone;
@@ -521,6 +522,7 @@ void OpenGLRenderer::drawRect(float left, float top, float right, float bottom,

void OpenGLRenderer::resetShader() {
    mShader = OpenGLRenderer::kShaderNone;
    mShaderKey = NULL;
    mShaderBlend = false;
    mShaderTileX = SkShader::kClamp_TileMode;
    mShaderTileY = SkShader::kClamp_TileMode;
@@ -536,9 +538,11 @@ void OpenGLRenderer::setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tile
    mShaderMatrix = matrix;
}

void OpenGLRenderer::setupLinearGradientShader(float* bounds, uint32_t* colors,
void OpenGLRenderer::setupLinearGradientShader(SkShader* shader, float* bounds,uint32_t* colors,
        float* positions, SkShader::TileMode tileMode, SkMatrix* matrix, bool hasAlpha) {
    // TODO: We should use a struct to describe each shader
    mShader = OpenGLRenderer::kShaderLinearGradient;
    mShaderKey = shader;
    mShaderBlend = hasAlpha;
    mShaderTileX = tileMode;
    mShaderTileY = tileMode;
+4 −2
Original line number Diff line number Diff line
@@ -103,8 +103,8 @@ public:
    void resetShader();
    void setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tileX, SkShader::TileMode tileY,
            SkMatrix* matrix, bool hasAlpha);
    void setupLinearGradientShader(float* bounds, uint32_t* colors, float* positions,
            SkShader::TileMode tileMode, SkMatrix* matrix, bool hasAlpha);
    void setupLinearGradientShader(SkShader* shader, float* bounds, uint32_t* colors,
            float* positions, SkShader::TileMode tileMode, SkMatrix* matrix, bool hasAlpha);

private:
    /**
@@ -309,6 +309,7 @@ private:
    sp<Program> mCurrentProgram;
    sp<DrawColorProgram> mDrawColorProgram;
    sp<DrawTextureProgram> mDrawTextureProgram;
    sp<DrawLinearGradientProgram> mDrawLinearGradientProgram;

    // Used to draw textured quads
    TextureVertex mDrawTextureVertices[4];
@@ -323,6 +324,7 @@ private:

    // Skia shaders
    ShaderType mShader;
    SkShader* mShaderKey;
    bool mShaderBlend;
    SkShader::TileMode mShaderTileX;
    SkShader::TileMode mShaderTileY;
Loading