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#ifndef ANDROID_HWUI_TEXTURE_H 18#define ANDROID_HWUI_TEXTURE_H 19 20#include <GLES2/gl2.h> 21 22namespace android { 23namespace uirenderer { 24 25class Caches; 26class UvMapper; 27 28/** 29 * Represents an OpenGL texture. 30 */ 31class Texture { 32public: 33 Texture(); 34 Texture(Caches& caches); 35 36 virtual ~Texture() { } 37 38 inline void setWrap(GLenum wrap, bool bindTexture = false, bool force = false, 39 GLenum renderTarget = GL_TEXTURE_2D) { 40 setWrapST(wrap, wrap, bindTexture, force, renderTarget); 41 } 42 43 virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false, 44 bool force = false, GLenum renderTarget = GL_TEXTURE_2D); 45 46 inline void setFilter(GLenum filter, bool bindTexture = false, bool force = false, 47 GLenum renderTarget = GL_TEXTURE_2D) { 48 setFilterMinMag(filter, filter, bindTexture, force, renderTarget); 49 } 50 51 virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false, 52 bool force = false, GLenum renderTarget = GL_TEXTURE_2D); 53 54 /** 55 * Convenience method to call glDeleteTextures() on this texture's id. 56 */ 57 void deleteTexture() const; 58 59 /** 60 * Name of the texture. 61 */ 62 GLuint id; 63 /** 64 * Generation of the backing bitmap, 65 */ 66 uint32_t generation; 67 /** 68 * Indicates whether the texture requires blending. 69 */ 70 bool blend; 71 /** 72 * Width of the backing bitmap. 73 */ 74 uint32_t width; 75 /** 76 * Height of the backing bitmap. 77 */ 78 uint32_t height; 79 /** 80 * Indicates whether this texture should be cleaned up after use. 81 */ 82 bool cleanup; 83 /** 84 * Optional, size of the original bitmap. 85 */ 86 uint32_t bitmapSize; 87 /** 88 * Indicates whether this texture will use trilinear filtering. 89 */ 90 bool mipMap; 91 92 /** 93 * Optional, pointer to a texture coordinates mapper. 94 */ 95 const UvMapper* uvMapper; 96 97private: 98 /** 99 * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE. 100 */ 101 GLenum mWrapS; 102 GLenum mWrapT; 103 104 /** 105 * Last filters set on this texture. Defaults to GL_NEAREST. 106 */ 107 GLenum mMinFilter; 108 GLenum mMagFilter; 109 110 bool mFirstFilter; 111 bool mFirstWrap; 112 113 Caches& mCaches; 114}; // struct Texture 115 116class AutoTexture { 117public: 118 AutoTexture(const Texture* texture): mTexture(texture) { } 119 ~AutoTexture() { 120 if (mTexture && mTexture->cleanup) { 121 mTexture->deleteTexture(); 122 delete mTexture; 123 } 124 } 125 126private: 127 const Texture* mTexture; 128}; // class AutoTexture 129 130}; // namespace uirenderer 131}; // namespace android 132 133#endif // ANDROID_HWUI_TEXTURE_H 134