1 /* 2 * Copyright (C) 2010 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 com.android.gallery3d.glrenderer; 18 19 import android.content.Context; 20 import android.graphics.Bitmap; 21 import android.graphics.BitmapFactory; 22 23 import com.android.gallery3d.common.Utils; 24 25 // ResourceTexture is a texture whose Bitmap is decoded from a resource. 26 // By default ResourceTexture is not opaque. 27 public class ResourceTexture extends UploadedTexture { 28 29 protected final Context mContext; 30 protected final int mResId; 31 ResourceTexture(Context context, int resId)32 public ResourceTexture(Context context, int resId) { 33 Utils.checkNotNull(context); 34 mContext = context; 35 mResId = resId; 36 setOpaque(false); 37 } 38 39 @Override onGetBitmap()40 protected Bitmap onGetBitmap() { 41 BitmapFactory.Options options = new BitmapFactory.Options(); 42 options.inPreferredConfig = Bitmap.Config.ARGB_8888; 43 return BitmapFactory.decodeResource( 44 mContext.getResources(), mResId, options); 45 } 46 47 @Override onFreeBitmap(Bitmap bitmap)48 protected void onFreeBitmap(Bitmap bitmap) { 49 if (!inFinalizer()) { 50 bitmap.recycle(); 51 } 52 } 53 } 54