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 /** 20 * Shader used to draw a bitmap as a texture. The bitmap can be repeated or 21 * mirrored by setting the tiling mode. 22 */ 23 public class BitmapShader extends Shader { 24 /** 25 * Prevent garbage collection. 26 * @hide 27 */ 28 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) 29 public final Bitmap mBitmap; 30 31 /** 32 * Call this to create a new shader that will draw with a bitmap. 33 * 34 * @param bitmap The bitmap to use inside the shader 35 * @param tileX The tiling mode for x to draw the bitmap in. 36 * @param tileY The tiling mode for y to draw the bitmap in. 37 */ BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY)38 public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) { 39 mBitmap = bitmap; 40 final int b = bitmap.ni(); 41 native_instance = nativeCreate(b, tileX.nativeInt, tileY.nativeInt); 42 native_shader = nativePostCreate(native_instance, b, tileX.nativeInt, tileY.nativeInt); 43 } 44 nativeCreate(int native_bitmap, int shaderTileModeX, int shaderTileModeY)45 private static native int nativeCreate(int native_bitmap, int shaderTileModeX, 46 int shaderTileModeY); nativePostCreate(int native_shader, int native_bitmap, int shaderTileModeX, int shaderTileModeY)47 private static native int nativePostCreate(int native_shader, int native_bitmap, 48 int shaderTileModeX, int shaderTileModeY); 49 } 50