diff options
author | Romain Guy <romainguy@google.com> | 2012-07-30 14:47:51 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2012-07-31 18:55:16 -0700 |
commit | 42e1e0d482d774cf18a55773e434f02edb9e4462 (patch) | |
tree | 33ac1bca20382f2e8ccbf176c89b3476f2ae5c9b /tests/HwAccelerationTest | |
parent | 8ab8fbbf46d8779f53301e7f706f97608eed7117 (diff) | |
download | frameworks_base-42e1e0d482d774cf18a55773e434f02edb9e4462.zip frameworks_base-42e1e0d482d774cf18a55773e434f02edb9e4462.tar.gz frameworks_base-42e1e0d482d774cf18a55773e434f02edb9e4462.tar.bz2 |
Improve gradients
Avoid using textures for common gradients (two stops from 0.0 to 1.0)
Change-Id: Iff55d21b126c8cfc4cfb701669f2339c8f6b131a
Diffstat (limited to 'tests/HwAccelerationTest')
-rw-r--r-- | tests/HwAccelerationTest/AndroidManifest.xml | 9 | ||||
-rw-r--r-- | tests/HwAccelerationTest/src/com/android/test/hwui/GradientStopsActivity.java | 116 |
2 files changed, 125 insertions, 0 deletions
diff --git a/tests/HwAccelerationTest/AndroidManifest.xml b/tests/HwAccelerationTest/AndroidManifest.xml index e7247a3..fad5993 100644 --- a/tests/HwAccelerationTest/AndroidManifest.xml +++ b/tests/HwAccelerationTest/AndroidManifest.xml @@ -33,6 +33,15 @@ <meta-data android:name="android.graphics.renderThread" android:value="true" /> <activity + android:name="GradientStopsActivity" + android:label="_GradientStops"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + + <activity android:name="PaintDrawFilterActivity" android:label="_DrawFilter"> <intent-filter> diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/GradientStopsActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/GradientStopsActivity.java new file mode 100644 index 0000000..ed00ecd --- /dev/null +++ b/tests/HwAccelerationTest/src/com/android/test/hwui/GradientStopsActivity.java @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.test.hwui; + +import android.app.Activity; +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.LinearGradient; +import android.graphics.Paint; +import android.graphics.Shader; +import android.os.Bundle; +import android.view.View; + +@SuppressWarnings("UnusedDeclaration") +public class GradientStopsActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(new GradientView(this)); + } + + private class GradientView extends View { + public GradientView(Context context) { + super(context); + } + + @Override + protected void onDraw(Canvas canvas) { + int[] colors = new int[] { 0xffff0000, 0xff0000ff }; + float[] positions = new float[] { 0.3f, 0.6f }; + LinearGradient gradient = new LinearGradient(0.0f, 0.0f, 256.0f, 0.0f, + colors, positions, Shader.TileMode.CLAMP); + + Paint paint = new Paint(); + paint.setShader(gradient); + + canvas.drawRect(0.0f, 0.0f, 256.0f, 50.0f, paint); + + colors = new int[] { 0xffff0000, 0xff0000ff, 0xff00ff00 }; + positions = new float[] { 0.3f, 0.6f, 1.0f }; + gradient = new LinearGradient(0.0f, 0.0f, 256.0f, 0.0f, + colors, positions, Shader.TileMode.CLAMP); + + paint.setShader(gradient); + + canvas.translate(0.0f, 75.0f); + canvas.drawRect(0.0f, 0.0f, 256.0f, 50.0f, paint); + + colors = new int[] { 0xffff0000, 0xff0000ff, 0xff00ff00 }; + positions = new float[] { 0.0f, 0.3f, 0.6f }; + gradient = new LinearGradient(0.0f, 0.0f, 256.0f, 0.0f, + colors, positions, Shader.TileMode.CLAMP); + + paint.setShader(gradient); + + canvas.translate(0.0f, 75.0f); + canvas.drawRect(0.0f, 0.0f, 256.0f, 50.0f, paint); + + colors = new int[] { 0xff000000, 0xffffffff }; + gradient = new LinearGradient(0.0f, 0.0f, 256.0f, 0.0f, + colors, null, Shader.TileMode.CLAMP); + + paint.setShader(gradient); + + canvas.translate(0.0f, 75.0f); + canvas.drawRect(0.0f, 0.0f, 256.0f, 50.0f, paint); + + gradient = new LinearGradient(0.0f, 0.0f, 256.0f, 0.0f, + colors, null, Shader.TileMode.REPEAT); + + paint.setShader(gradient); + + canvas.translate(0.0f, 75.0f); + canvas.drawRect(0.0f, 0.0f, 768.0f, 50.0f, paint); + + gradient = new LinearGradient(0.0f, 0.0f, 256.0f, 0.0f, + colors, null, Shader.TileMode.MIRROR); + + paint.setShader(gradient); + + canvas.translate(0.0f, 75.0f); + canvas.drawRect(0.0f, 0.0f, 768.0f, 50.0f, paint); + + gradient = new LinearGradient(0.0f, 0.0f, 256.0f, 0.0f, + colors, null, Shader.TileMode.CLAMP); + + paint.setShader(gradient); + + canvas.translate(0.0f, 75.0f); + canvas.drawRect(0.0f, 0.0f, 768.0f, 50.0f, paint); + + gradient = new LinearGradient(0.0f, 0.0f, 768.0f, 0.0f, + colors, null, Shader.TileMode.CLAMP); + + paint.setShader(gradient); + + canvas.translate(0.0f, 75.0f); + canvas.drawRect(0.0f, 0.0f, 768.0f, 50.0f, paint); + } + } +} |