blob: d5601f801fcd7694d149a152177cbd46d20662bc [file] [log] [blame]
Romain Guyce0537b2010-06-29 21:05:21 -07001/*
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 Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_TEXTURE_H
18#define ANDROID_HWUI_TEXTURE_H
Romain Guyce0537b2010-06-29 21:05:21 -070019
20#include <GLES2/gl2.h>
21
22namespace android {
23namespace uirenderer {
24
Romain Guy8aa195d2013-06-04 18:00:09 -070025class Caches;
Romain Guy3b748a42013-04-17 18:54:38 -070026class UvMapper;
27
Romain Guyce0537b2010-06-29 21:05:21 -070028/**
29 * Represents an OpenGL texture.
30 */
Romain Guy8aa195d2013-06-04 18:00:09 -070031class Texture {
32public:
33 Texture();
34 Texture(Caches& caches);
Romain Guy9ace8f52011-07-07 20:50:11 -070035
Romain Guya404e162013-05-24 16:19:19 -070036 virtual ~Texture() { }
37
Romain Guy8aa195d2013-06-04 18:00:09 -070038 inline void setWrap(GLenum wrap, bool bindTexture = false, bool force = false,
Romain Guyd21b6e12011-11-30 20:21:23 -080039 GLenum renderTarget = GL_TEXTURE_2D) {
40 setWrapST(wrap, wrap, bindTexture, force, renderTarget);
41 }
42
Romain Guya404e162013-05-24 16:19:19 -070043 virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false,
Romain Guy8aa195d2013-06-04 18:00:09 -070044 bool force = false, GLenum renderTarget = GL_TEXTURE_2D);
Romain Guye3c26852011-07-25 16:36:01 -070045
Romain Guy8aa195d2013-06-04 18:00:09 -070046 inline void setFilter(GLenum filter, bool bindTexture = false, bool force = false,
Romain Guyd21b6e12011-11-30 20:21:23 -080047 GLenum renderTarget = GL_TEXTURE_2D) {
48 setFilterMinMag(filter, filter, bindTexture, force, renderTarget);
49 }
50
Romain Guya404e162013-05-24 16:19:19 -070051 virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false,
Romain Guy8aa195d2013-06-04 18:00:09 -070052 bool force = false, GLenum renderTarget = GL_TEXTURE_2D);
Romain Guy22158e12010-08-06 11:18:34 -070053
Romain Guyce0537b2010-06-29 21:05:21 -070054 /**
Romain Guybe1b1272013-06-06 14:02:54 -070055 * Convenience method to call glDeleteTextures() on this texture's id.
56 */
57 void deleteTexture() const;
58
59 /**
Romain Guyce0537b2010-06-29 21:05:21 -070060 * Name of the texture.
61 */
62 GLuint id;
63 /**
Romain Guyfe880942010-06-30 16:05:32 -070064 * Generation of the backing bitmap,
65 */
66 uint32_t generation;
67 /**
Romain Guyce0537b2010-06-29 21:05:21 -070068 * Indicates whether the texture requires blending.
69 */
70 bool blend;
71 /**
72 * Width of the backing bitmap.
73 */
Romain Guy7d139ba2010-07-02 11:20:34 -070074 uint32_t width;
Romain Guyce0537b2010-06-29 21:05:21 -070075 /**
76 * Height of the backing bitmap.
77 */
Romain Guy7d139ba2010-07-02 11:20:34 -070078 uint32_t height;
Romain Guy22158e12010-08-06 11:18:34 -070079 /**
80 * Indicates whether this texture should be cleaned up after use.
81 */
82 bool cleanup;
Romain Guy9aaa8262010-09-08 15:15:43 -070083 /**
84 * Optional, size of the original bitmap.
85 */
86 uint32_t bitmapSize;
Romain Guy713e1bb2012-10-16 18:44:09 -070087 /**
88 * Indicates whether this texture will use trilinear filtering.
89 */
90 bool mipMap;
Romain Guy8164c2d2010-10-25 18:03:28 -070091
Romain Guy3b748a42013-04-17 18:54:38 -070092 /**
93 * Optional, pointer to a texture coordinates mapper.
94 */
95 const UvMapper* uvMapper;
96
John Reck860d1552014-04-11 19:15:05 -070097 /**
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 Guy713e1bb2012-10-16 18:44:09 -0700103private:
Romain Guy8164c2d2010-10-25 18:03:28 -0700104 /**
105 * Last wrap modes set on this texture. Defaults to GL_CLAMP_TO_EDGE.
106 */
Romain Guy8aa195d2013-06-04 18:00:09 -0700107 GLenum mWrapS;
108 GLenum mWrapT;
Romain Guy9ace8f52011-07-07 20:50:11 -0700109
110 /**
111 * Last filters set on this texture. Defaults to GL_NEAREST.
112 */
Romain Guy8aa195d2013-06-04 18:00:09 -0700113 GLenum mMinFilter;
114 GLenum mMagFilter;
Romain Guye3c26852011-07-25 16:36:01 -0700115
Romain Guy8aa195d2013-06-04 18:00:09 -0700116 bool mFirstFilter;
117 bool mFirstWrap;
118
119 Caches& mCaches;
Romain Guyce0537b2010-06-29 21:05:21 -0700120}; // struct Texture
121
Romain Guy22158e12010-08-06 11:18:34 -0700122class AutoTexture {
123public:
124 AutoTexture(const Texture* texture): mTexture(texture) { }
125 ~AutoTexture() {
126 if (mTexture && mTexture->cleanup) {
Romain Guybe1b1272013-06-06 14:02:54 -0700127 mTexture->deleteTexture();
Romain Guy22158e12010-08-06 11:18:34 -0700128 delete mTexture;
129 }
130 }
131
132private:
133 const Texture* mTexture;
134}; // class AutoTexture
135
Romain Guyce0537b2010-06-29 21:05:21 -0700136}; // namespace uirenderer
137}; // namespace android
138
Romain Guy5b3b3522010-10-27 18:57:51 -0700139#endif // ANDROID_HWUI_TEXTURE_H