1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.graphics; 18 19 /** A subclass of shader that returns the coposition of two other shaders, combined by 20 an {@link android.graphics.Xfermode} subclass. 21 */ 22 public class ComposeShader extends Shader { 23 /** Create a new compose shader, given shaders A, B, and a combining mode. 24 When the mode is applied, it will be given the result from shader A as its 25 "dst", and the result of from shader B as its "src". 26 @param shaderA The colors from this shader are seen as the "dst" by the mode 27 @param shaderB The colors from this shader are seen as the "src" by the mode 28 @param mode The mode that combines the colors from the two shaders. If mode 29 is null, then SRC_OVER is assumed. 30 */ ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode)31 public ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode) { 32 native_instance = nativeCreate1(shaderA.native_instance, shaderB.native_instance, 33 (mode != null) ? mode.native_instance : 0); 34 } 35 36 /** Create a new compose shader, given shaders A, B, and a combining PorterDuff mode. 37 When the mode is applied, it will be given the result from shader A as its 38 "dst", and the result of from shader B as its "src". 39 @param shaderA The colors from this shader are seen as the "dst" by the mode 40 @param shaderB The colors from this shader are seen as the "src" by the mode 41 @param mode The PorterDuff mode that combines the colors from the two shaders. 42 */ ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode)43 public ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode) { 44 native_instance = nativeCreate2(shaderA.native_instance, shaderB.native_instance, 45 mode.nativeInt); 46 } 47 nativeCreate1(int native_shaderA, int native_shaderB, int native_mode)48 private static native int nativeCreate1(int native_shaderA, int native_shaderB, int native_mode); nativeCreate2(int native_shaderA, int native_shaderB, int porterDuffMode)49 private static native int nativeCreate2(int native_shaderA, int native_shaderB, int porterDuffMode); 50 } 51 52