1104c45677660586026a7e74ef8c47d396403d50eMichael Jurka/*
2104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * Copyright (C) 2010 The Android Open Source Project
3104c45677660586026a7e74ef8c47d396403d50eMichael Jurka *
4104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * Licensed under the Apache License, Version 2.0 (the "License");
5104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * you may not use this file except in compliance with the License.
6104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * You may obtain a copy of the License at
7104c45677660586026a7e74ef8c47d396403d50eMichael Jurka *
8104c45677660586026a7e74ef8c47d396403d50eMichael Jurka *      http://www.apache.org/licenses/LICENSE-2.0
9104c45677660586026a7e74ef8c47d396403d50eMichael Jurka *
10104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * Unless required by applicable law or agreed to in writing, software
11104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * distributed under the License is distributed on an "AS IS" BASIS,
12104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * See the License for the specific language governing permissions and
14104c45677660586026a7e74ef8c47d396403d50eMichael Jurka * limitations under the License.
15104c45677660586026a7e74ef8c47d396403d50eMichael Jurka */
16104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
17104c45677660586026a7e74ef8c47d396403d50eMichael Jurkapackage com.android.gallery3d.glrenderer;
18104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
19104c45677660586026a7e74ef8c47d396403d50eMichael Jurkaimport android.graphics.Bitmap;
20104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
21104c45677660586026a7e74ef8c47d396403d50eMichael Jurkaimport junit.framework.Assert;
22104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
23104c45677660586026a7e74ef8c47d396403d50eMichael Jurka// BitmapTexture is a texture whose content is specified by a fixed Bitmap.
24104c45677660586026a7e74ef8c47d396403d50eMichael Jurka//
25104c45677660586026a7e74ef8c47d396403d50eMichael Jurka// The texture does not own the Bitmap. The user should make sure the Bitmap
26104c45677660586026a7e74ef8c47d396403d50eMichael Jurka// is valid during the texture's lifetime. When the texture is recycled, it
27104c45677660586026a7e74ef8c47d396403d50eMichael Jurka// does not free the Bitmap.
28104c45677660586026a7e74ef8c47d396403d50eMichael Jurkapublic class BitmapTexture extends UploadedTexture {
29104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    protected Bitmap mContentBitmap;
30104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
31104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    public BitmapTexture(Bitmap bitmap) {
32104c45677660586026a7e74ef8c47d396403d50eMichael Jurka        this(bitmap, false);
33104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    }
34104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
35104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    public BitmapTexture(Bitmap bitmap, boolean hasBorder) {
36104c45677660586026a7e74ef8c47d396403d50eMichael Jurka        super(hasBorder);
37104c45677660586026a7e74ef8c47d396403d50eMichael Jurka        Assert.assertTrue(bitmap != null && !bitmap.isRecycled());
38104c45677660586026a7e74ef8c47d396403d50eMichael Jurka        mContentBitmap = bitmap;
39104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    }
40104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
41104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    @Override
42104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    protected void onFreeBitmap(Bitmap bitmap) {
43104c45677660586026a7e74ef8c47d396403d50eMichael Jurka        // Do nothing.
44104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    }
45104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
46104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    @Override
47104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    protected Bitmap onGetBitmap() {
48104c45677660586026a7e74ef8c47d396403d50eMichael Jurka        return mContentBitmap;
49104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    }
50104c45677660586026a7e74ef8c47d396403d50eMichael Jurka
51104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    public Bitmap getBitmap() {
52104c45677660586026a7e74ef8c47d396403d50eMichael Jurka        return mContentBitmap;
53104c45677660586026a7e74ef8c47d396403d50eMichael Jurka    }
54104c45677660586026a7e74ef8c47d396403d50eMichael Jurka}
55