1 /* 2 * Copyright (C) 2009 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.cooliris.media; 18 19 import android.graphics.Bitmap; 20 21 public abstract class Texture { 22 23 public static final int STATE_UNLOADED = 0; 24 public static final int STATE_QUEUED = 1; 25 public static final int STATE_LOADING = 2; 26 public static final int STATE_LOADED = 3; 27 public static final int STATE_ERROR = 4; 28 29 int mState = STATE_UNLOADED; 30 int mId; 31 int mWidth; 32 int mHeight; 33 float mNormalizedWidth; 34 float mNormalizedHeight; 35 Bitmap mBitmap; 36 37 public boolean isCached() { 38 return false; 39 } 40 41 public final void clear() { 42 mId = 0; 43 mState = STATE_UNLOADED; 44 mWidth = 0; 45 mHeight = 0; 46 mNormalizedWidth = 0; 47 mNormalizedHeight = 0; 48 if (mBitmap != null) { 49 mBitmap.recycle(); 50 mBitmap = null; 51 } 52 } 53 54 public final boolean isLoaded() { 55 return mState == STATE_LOADED; 56 } 57 58 public final int getState() { 59 return mState; 60 } 61 62 public final int getWidth() { 63 return mWidth; 64 } 65 66 public final int getHeight() { 67 return mHeight; 68 } 69 70 public final float getNormalizedWidth() { 71 return mNormalizedWidth; 72 } 73 74 public final float getNormalizedHeight() { 75 return mNormalizedHeight; 76 } 77 78 /** If this returns true, the texture will be enqueued. */ 79 protected boolean shouldQueue() { 80 return true; 81 } 82 83 /** Returns a bitmap, or null if an error occurs. */ 84 protected abstract Bitmap load(RenderView view); 85 86 public boolean isUncachedVideo() { 87 return false; 88 } 89 } 90