Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_TEXTURE_H |
| 18 | #define ANDROID_HWUI_TEXTURE_H |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 19 | |
| 20 | #include <GLES2/gl2.h> |
| 21 | |
| 22 | namespace android { |
| 23 | namespace uirenderer { |
| 24 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 25 | class Caches; |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 26 | class UvMapper; |
| 27 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Represents an OpenGL texture. |
| 30 | */ |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 31 | class Texture { |
| 32 | public: |
| 33 | Texture(); |
| 34 | Texture(Caches& caches); |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 35 | |
Romain Guy | a404e16 | 2013-05-24 16:19:19 -0700 | [diff] [blame] | 36 | virtual ~Texture() { } |
| 37 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 38 | inline void setWrap(GLenum wrap, bool bindTexture = false, bool force = false, |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 39 | GLenum renderTarget = GL_TEXTURE_2D) { |
| 40 | setWrapST(wrap, wrap, bindTexture, force, renderTarget); |
| 41 | } |
| 42 | |
Romain Guy | a404e16 | 2013-05-24 16:19:19 -0700 | [diff] [blame] | 43 | virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false, |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 44 | bool force = false, GLenum renderTarget = GL_TEXTURE_2D); |
Romain Guy | e3c2685 | 2011-07-25 16:36:01 -0700 | [diff] [blame] | 45 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 46 | inline void setFilter(GLenum filter, bool bindTexture = false, bool force = false, |
Romain Guy | d21b6e1 | 2011-11-30 20:21:23 -0800 | [diff] [blame] | 47 | GLenum renderTarget = GL_TEXTURE_2D) { |
| 48 | setFilterMinMag(filter, filter, bindTexture, force, renderTarget); |
| 49 | } |
| 50 | |
Romain Guy | a404e16 | 2013-05-24 16:19:19 -0700 | [diff] [blame] | 51 | virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false, |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 52 | bool force = false, GLenum renderTarget = GL_TEXTURE_2D); |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 53 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 54 | /** |
Romain Guy | be1b127 | 2013-06-06 14:02:54 -0700 | [diff] [blame] | 55 | * Convenience method to call glDeleteTextures() on this texture's id. |
| 56 | */ |
| 57 | void deleteTexture() const; |
| 58 | |
| 59 | /** |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 60 | * Name of the texture. |
| 61 | */ |
| 62 | GLuint id; |
| 63 | /** |
Romain Guy | fe88094 | 2010-06-30 16:05:32 -0700 | [diff] [blame] | 64 | * Generation of the backing bitmap, |
| 65 | */ |
| 66 | uint32_t generation; |
| 67 | /** |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 68 | * Indicates whether the texture requires blending. |
| 69 | */ |
| 70 | bool blend; |
| 71 | /** |
| 72 | * Width of the backing bitmap. |
| 73 | */ |
Romain Guy | 7d139ba | 2010-07-02 11:20:34 -0700 | [diff] [blame] | 74 | uint32_t width; |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Height of the backing bitmap. |
| 77 | */ |
Romain Guy | 7d139ba | 2010-07-02 11:20:34 -0700 | [diff] [blame] | 78 | uint32_t height; |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Indicates whether this texture should be cleaned up after use. |
| 81 | */ |
| 82 | bool cleanup; |
Romain Guy | 9aaa826 | 2010-09-08 15:15:43 -0700 | [diff] [blame] | 83 | /** |
| 84 | * Optional, size of the original bitmap. |
| 85 | */ |
| 86 | uint32_t bitmapSize; |
Romain Guy | 713e1bb | 2012-10-16 18:44:09 -0700 | [diff] [blame] | 87 | /** |
| 88 | * Indicates whether this texture will use trilinear filtering. |
| 89 | */ |
| 90 | bool mipMap; |
Romain Guy | 8164c2d | 2010-10-25 18:03:28 -0700 | [diff] [blame] | 91 | |
Romain Guy | 3b748a4 | 2013-04-17 18:54:38 -0700 | [diff] [blame] | 92 | /** |
| 93 | * Optional, pointer to a texture coordinates mapper. |
| 94 | */ |
| 95 | const UvMapper* uvMapper; |
| 96 | |
John Reck | 860d155 | 2014-04-11 19:15:05 -0700 | [diff] [blame] | 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 | |
Romain Guy | 713e1bb | 2012-10-16 18:44:09 -0700 | [diff] [blame] | 103 | private: |
Romain Guy | 8164c2d | 2010-10-25 18:03:28 -0700 | [diff] [blame] | 104 | /** |
| 105 | * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE. |
| 106 | */ |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 107 | GLenum mWrapS; |
| 108 | GLenum mWrapT; |
Romain Guy | 9ace8f5 | 2011-07-07 20:50:11 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Last filters set on this texture. Defaults to GL_NEAREST. |
| 112 | */ |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 113 | GLenum mMinFilter; |
| 114 | GLenum mMagFilter; |
Romain Guy | e3c2685 | 2011-07-25 16:36:01 -0700 | [diff] [blame] | 115 | |
Romain Guy | 8aa195d | 2013-06-04 18:00:09 -0700 | [diff] [blame] | 116 | bool mFirstFilter; |
| 117 | bool mFirstWrap; |
| 118 | |
| 119 | Caches& mCaches; |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 120 | }; // struct Texture |
| 121 | |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 122 | class AutoTexture { |
| 123 | public: |
| 124 | AutoTexture(const Texture* texture): mTexture(texture) { } |
| 125 | ~AutoTexture() { |
| 126 | if (mTexture && mTexture->cleanup) { |
Romain Guy | be1b127 | 2013-06-06 14:02:54 -0700 | [diff] [blame] | 127 | mTexture->deleteTexture(); |
Romain Guy | 22158e1 | 2010-08-06 11:18:34 -0700 | [diff] [blame] | 128 | delete mTexture; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | private: |
| 133 | const Texture* mTexture; |
| 134 | }; // class AutoTexture |
| 135 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 136 | }; // namespace uirenderer |
| 137 | }; // namespace android |
| 138 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 139 | #endif // ANDROID_HWUI_TEXTURE_H |