BitmapScreenNail.java revision b29a27f475a2c449abdda8d4e03d30914feed8c6
1/* 2 * Copyright (C) 2012 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 com.android.gallery3d.ui; 18 19import android.graphics.Bitmap; 20import android.graphics.RectF; 21import android.util.Log; 22 23// This is a ScreenNail wraps a Bitmap. It also includes the rotation 24// information. The getWidth() and getHeight() methods return the width/height 25// before rotation. 26public class BitmapScreenNail implements ScreenNail { 27 private static final String TAG = "BitmapScreenNail"; 28 private final int mWidth; 29 private final int mHeight; 30 private final int mRotation; 31 private final Bitmap mBitmap; 32 private BitmapTexture mTexture; 33 34 public BitmapScreenNail(Bitmap bitmap, int rotation) { 35 mWidth = bitmap.getWidth(); 36 mHeight = bitmap.getHeight(); 37 mRotation = rotation; 38 mBitmap = bitmap; 39 // We create mTexture lazily, so we don't incur the cost if we don't 40 // actually need it. 41 } 42 43 @Override 44 public int getWidth() { 45 return mWidth; 46 } 47 48 @Override 49 public int getHeight() { 50 return mHeight; 51 } 52 53 @Override 54 public int getRotation() { 55 return mRotation; 56 } 57 58 @Override 59 public void noDraw() { 60 } 61 62 @Override 63 public void pauseDraw() { 64 if (mTexture != null) { 65 mTexture.recycle(); 66 } 67 } 68 69 @Override 70 public void draw(GLCanvas canvas, int x, int y, int width, int height) { 71 if (mTexture == null) { 72 mTexture = new BitmapTexture(mBitmap); 73 } 74 mTexture.draw(canvas, x, y, width, height); 75 } 76 77 @Override 78 public void draw(GLCanvas canvas, RectF source, RectF dest) { 79 if (mTexture == null) { 80 mTexture = new BitmapTexture(mBitmap); 81 } 82 canvas.drawTexture(mTexture, source, dest); 83 } 84} 85