blob: 5e004a37034203b18db38d149e1245b931a98120 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Romain Guy6926c72e2010-07-12 20:20:03 -070019/**
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 Project9066cfe2009-03-03 19:31:44 -080023public class BitmapShader extends Shader {
Romain Guy6926c72e2010-07-12 20:20:03 -070024 /**
Romain Guy0ba681b2010-08-12 15:37:00 -070025 * Prevent garbage collection.
Patrick Dubroyf890fab2010-12-19 16:47:17 -080026 * @hide
Romain Guy0ba681b2010-08-12 15:37:00 -070027 */
28 @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
Patrick Dubroyf890fab2010-12-19 16:47:17 -080029 public final Bitmap mBitmap;
Romain Guy0ba681b2010-08-12 15:37:00 -070030
Fabrice Di Meglioe3c526f2013-07-30 18:58:19 -070031 private TileMode mTileX;
32 private TileMode mTileY;
33
Romain Guy0ba681b2010-08-12 15:37:00 -070034 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 * 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 Guy0ba681b2010-08-12 15:37:00 -070042 mBitmap = bitmap;
Fabrice Di Meglioe3c526f2013-07-30 18:58:19 -070043 mTileX = tileX;
44 mTileY = tileY;
Ashok Bhat36bef0b2014-01-20 20:08:01 +000045 final long b = bitmap.ni();
Leon Scroggins III866cf652014-07-22 17:25:22 -040046 init(nativeCreate(b, tileX.nativeInt, tileY.nativeInt));
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 }
48
Fabrice Di Meglioe3c526f2013-07-30 18:58:19 -070049 /**
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 Bhat36bef0b2014-01-20 20:08:01 +000059 private static native long nativeCreate(long native_bitmap, int shaderTileModeX,
Romain Guy06f96e22010-07-30 19:18:16 -070060 int shaderTileModeY);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061}