ComposeShader.java revision b3061e82ebfaefdbf33b35f78e5e87de7abd5591
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 17package android.graphics; 18 19/** A subclass of shader that returns the composition of two other shaders, combined by 20 an {@link android.graphics.Xfermode} subclass. 21*/ 22public class ComposeShader extends Shader { 23 24 private int mPorterDuffMode; 25 final Shader mShaderA; 26 final Shader mShaderB; 27 28 /** Create a new compose shader, given shaders A, B, and a combining mode. 29 When the mode is applied, it will be given the result from shader A as its 30 "dst", and the result from shader B as its "src". 31 @param shaderA The colors from this shader are seen as the "dst" by the mode 32 @param shaderB The colors from this shader are seen as the "src" by the mode 33 @param mode The mode that combines the colors from the two shaders. If mode 34 is null, then SRC_OVER is assumed. 35 */ 36 public ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode) { 37 this(shaderA, shaderB, mode.porterDuffMode); 38 } 39 40 /** Create a new compose shader, given shaders A, B, and a combining PorterDuff mode. 41 When the mode is applied, it will be given the result from shader A as its 42 "dst", and the result from shader B as its "src". 43 @param shaderA The colors from this shader are seen as the "dst" by the mode 44 @param shaderB The colors from this shader are seen as the "src" by the mode 45 @param mode The PorterDuff mode that combines the colors from the two shaders. 46 */ 47 public ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode) { 48 this(shaderA, shaderB, mode.nativeInt); 49 } 50 51 private ComposeShader(Shader shaderA, Shader shaderB, int nativeMode) { 52 mShaderA = shaderA; 53 mShaderB = shaderB; 54 mPorterDuffMode = nativeMode; 55 init(nativeCreate(shaderA.getNativeInstance(), shaderB.getNativeInstance(), 56 nativeMode)); 57 } 58 59 /** 60 * @hide 61 */ 62 @Override 63 protected Shader copy() { 64 final ComposeShader copy = new ComposeShader( 65 mShaderA.copy(), mShaderB.copy(), mPorterDuffMode); 66 copyLocalMatrix(copy); 67 return copy; 68 } 69 70 private static native long nativeCreate(long native_shaderA, long native_shaderB, 71 int porterDuffMode); 72} 73