blob: dfec462865791ed71677128e6f90b7b5d39f5deb [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:
Chris Craik8e93a7c2015-02-23 13:07:57 -080033 Texture(Caches& caches) : mCaches(caches) { }
Romain Guy9ace8f52011-07-07 20:50:11 -070034
Romain Guya404e162013-05-24 16:19:19 -070035 virtual ~Texture() { }
36
Romain Guy8aa195d2013-06-04 18:00:09 -070037 inline void setWrap(GLenum wrap, bool bindTexture = false, bool force = false,
Romain Guyd21b6e12011-11-30 20:21:23 -080038 GLenum renderTarget = GL_TEXTURE_2D) {
39 setWrapST(wrap, wrap, bindTexture, force, renderTarget);
40 }
41
Romain Guya404e162013-05-24 16:19:19 -070042 virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false,
Romain Guy8aa195d2013-06-04 18:00:09 -070043 bool force = false, GLenum renderTarget = GL_TEXTURE_2D);
Romain Guye3c26852011-07-25 16:36:01 -070044
Romain Guy8aa195d2013-06-04 18:00:09 -070045 inline void setFilter(GLenum filter, bool bindTexture = false, bool force = false,
Romain Guyd21b6e12011-11-30 20:21:23 -080046 GLenum renderTarget = GL_TEXTURE_2D) {
47 setFilterMinMag(filter, filter, bindTexture, force, renderTarget);
48 }
49
Romain Guya404e162013-05-24 16:19:19 -070050 virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false,
Romain Guy8aa195d2013-06-04 18:00:09 -070051 bool force = false, GLenum renderTarget = GL_TEXTURE_2D);
Romain Guy22158e12010-08-06 11:18:34 -070052
Romain Guyce0537b2010-06-29 21:05:21 -070053 /**
Romain Guybe1b1272013-06-06 14:02:54 -070054 * Convenience method to call glDeleteTextures() on this texture's id.
55 */
56 void deleteTexture() const;
57
58 /**
Romain Guyce0537b2010-06-29 21:05:21 -070059 * Name of the texture.
60 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080061 GLuint id = 0;
Romain Guyce0537b2010-06-29 21:05:21 -070062 /**
Romain Guyfe880942010-06-30 16:05:32 -070063 * Generation of the backing bitmap,
64 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080065 uint32_t generation = 0;
Romain Guyfe880942010-06-30 16:05:32 -070066 /**
Romain Guyce0537b2010-06-29 21:05:21 -070067 * Indicates whether the texture requires blending.
68 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080069 bool blend = false;
Romain Guyce0537b2010-06-29 21:05:21 -070070 /**
71 * Width of the backing bitmap.
72 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080073 uint32_t width = 0;
Romain Guyce0537b2010-06-29 21:05:21 -070074 /**
75 * Height of the backing bitmap.
76 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080077 uint32_t height = 0;
Romain Guy22158e12010-08-06 11:18:34 -070078 /**
79 * Indicates whether this texture should be cleaned up after use.
80 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080081 bool cleanup= false;
Romain Guy9aaa8262010-09-08 15:15:43 -070082 /**
83 * Optional, size of the original bitmap.
84 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080085 uint32_t bitmapSize = 0;
Romain Guy713e1bb2012-10-16 18:44:09 -070086 /**
87 * Indicates whether this texture will use trilinear filtering.
88 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080089 bool mipMap = false;
Romain Guy8164c2d2010-10-25 18:03:28 -070090
Romain Guy3b748a42013-04-17 18:54:38 -070091 /**
92 * Optional, pointer to a texture coordinates mapper.
93 */
Chris Craik8e93a7c2015-02-23 13:07:57 -080094 const UvMapper* uvMapper = nullptr;
Romain Guy3b748a42013-04-17 18:54:38 -070095
John Reck860d1552014-04-11 19:15:05 -070096 /**
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 */
Chris Craik8e93a7c2015-02-23 13:07:57 -0800100 bool isInUse = false;
John Reck860d1552014-04-11 19:15:05 -0700101
Romain Guy713e1bb2012-10-16 18:44:09 -0700102private:
Romain Guy8164c2d2010-10-25 18:03:28 -0700103 /**
Chris Craik8e93a7c2015-02-23 13:07:57 -0800104 * Last wrap modes set on this texture.
Romain Guy8164c2d2010-10-25 18:03:28 -0700105 */
Chris Craik8e93a7c2015-02-23 13:07:57 -0800106 GLenum mWrapS = GL_CLAMP_TO_EDGE;
107 GLenum mWrapT = GL_CLAMP_TO_EDGE;
Romain Guy9ace8f52011-07-07 20:50:11 -0700108
109 /**
Chris Craik8e93a7c2015-02-23 13:07:57 -0800110 * Last filters set on this texture.
Romain Guy9ace8f52011-07-07 20:50:11 -0700111 */
Chris Craik8e93a7c2015-02-23 13:07:57 -0800112 GLenum mMinFilter = GL_NEAREST;
113 GLenum mMagFilter = GL_NEAREST;
Romain Guye3c26852011-07-25 16:36:01 -0700114
Chris Craik8e93a7c2015-02-23 13:07:57 -0800115 bool mFirstFilter = true;
116 bool mFirstWrap = true;
Romain Guy8aa195d2013-06-04 18:00:09 -0700117
118 Caches& mCaches;
Romain Guyce0537b2010-06-29 21:05:21 -0700119}; // struct Texture
120
Romain Guy22158e12010-08-06 11:18:34 -0700121class AutoTexture {
122public:
123 AutoTexture(const Texture* texture): mTexture(texture) { }
124 ~AutoTexture() {
125 if (mTexture && mTexture->cleanup) {
Romain Guybe1b1272013-06-06 14:02:54 -0700126 mTexture->deleteTexture();
Romain Guy22158e12010-08-06 11:18:34 -0700127 delete mTexture;
128 }
129 }
130
131private:
132 const Texture* mTexture;
133}; // class AutoTexture
134
Romain Guyce0537b2010-06-29 21:05:21 -0700135}; // namespace uirenderer
136}; // namespace android
137
Romain Guy5b3b3522010-10-27 18:57:51 -0700138#endif // ANDROID_HWUI_TEXTURE_H