• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 namespace android {
23 namespace uirenderer {
24 
25 class Caches;
26 class UvMapper;
27 
28 /**
29  * Represents an OpenGL texture.
30  */
31 class Texture {
32 public:
33     Texture();
34     Texture(Caches& caches);
35 
~Texture()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 
97     /**
98      * Whether or not the Texture is marked in use and thus not evictable for
99      * the current frame. This is reset at the start of a new frame.
100      */
101     bool isInUse;
102 
103 private:
104     /**
105      * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE.
106      */
107     GLenum mWrapS;
108     GLenum mWrapT;
109 
110     /**
111      * Last filters set on this texture. Defaults to GL_NEAREST.
112      */
113     GLenum mMinFilter;
114     GLenum mMagFilter;
115 
116     bool mFirstFilter;
117     bool mFirstWrap;
118 
119     Caches& mCaches;
120 }; // struct Texture
121 
122 class AutoTexture {
123 public:
AutoTexture(const Texture * texture)124     AutoTexture(const Texture* texture): mTexture(texture) { }
~AutoTexture()125     ~AutoTexture() {
126         if (mTexture && mTexture->cleanup) {
127             mTexture->deleteTexture();
128             delete mTexture;
129         }
130     }
131 
132 private:
133     const Texture* mTexture;
134 }; // class AutoTexture
135 
136 }; // namespace uirenderer
137 }; // namespace android
138 
139 #endif // ANDROID_HWUI_TEXTURE_H
140