| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| Romain Guy | 6926c72e | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 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 | */ |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | public class BitmapShader extends Shader { |
| Romain Guy | 6926c72e | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 24 | /** |
| Romain Guy | 0ba681b | 2010-08-12 15:37:00 -0700 | [diff] [blame] | 25 | * Prevent garbage collection. |
| Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 26 | * @hide |
| Romain Guy | 0ba681b | 2010-08-12 15:37:00 -0700 | [diff] [blame] | 27 | */ |
| 28 | @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) |
| Patrick Dubroy | f890fab | 2010-12-19 16:47:17 -0800 | [diff] [blame] | 29 | public final Bitmap mBitmap; |
| Romain Guy | 0ba681b | 2010-08-12 15:37:00 -0700 | [diff] [blame] | 30 | |
| Fabrice Di Meglio | e3c526f | 2013-07-30 18:58:19 -0700 | [diff] [blame] | 31 | private TileMode mTileX; |
| 32 | private TileMode mTileY; |
| 33 | |
| Romain Guy | 0ba681b | 2010-08-12 15:37:00 -0700 | [diff] [blame] | 34 | /** |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | * Call this to create a new shader that will draw with a bitmap. |
| 36 | * |
| 37 | * @param bitmap The bitmap to use inside the shader |
| 38 | * @param tileX The tiling mode for x to draw the bitmap in. |
| 39 | * @param tileY The tiling mode for y to draw the bitmap in. |
| 40 | */ |
| 41 | public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) { |
| Romain Guy | 0ba681b | 2010-08-12 15:37:00 -0700 | [diff] [blame] | 42 | mBitmap = bitmap; |
| Fabrice Di Meglio | e3c526f | 2013-07-30 18:58:19 -0700 | [diff] [blame] | 43 | mTileX = tileX; |
| 44 | mTileY = tileY; |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 45 | final long b = bitmap.ni(); |
| Leon Scroggins III | 866cf65 | 2014-07-22 17:25:22 -0400 | [diff] [blame] | 46 | init(nativeCreate(b, tileX.nativeInt, tileY.nativeInt)); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | } |
| 48 | |
| Fabrice Di Meglio | e3c526f | 2013-07-30 18:58:19 -0700 | [diff] [blame] | 49 | /** |
| 50 | * @hide |
| 51 | */ |
| 52 | @Override |
| 53 | protected Shader copy() { |
| 54 | final BitmapShader copy = new BitmapShader(mBitmap, mTileX, mTileY); |
| 55 | copyLocalMatrix(copy); |
| 56 | return copy; |
| 57 | } |
| 58 | |
| Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 59 | private static native long nativeCreate(long native_bitmap, int shaderTileModeX, |
| Romain Guy | 06f96e2 | 2010-07-30 19:18:16 -0700 | [diff] [blame] | 60 | int shaderTileModeY); |
| The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | } |