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