1ce0537b80087a6225273040a987414b1dd081aa0Romain Guy/*
2ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * Copyright (C) 2010 The Android Open Source Project
3ce0537b80087a6225273040a987414b1dd081aa0Romain Guy *
4ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * you may not use this file except in compliance with the License.
6ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * You may obtain a copy of the License at
7ce0537b80087a6225273040a987414b1dd081aa0Romain Guy *
8ce0537b80087a6225273040a987414b1dd081aa0Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9ce0537b80087a6225273040a987414b1dd081aa0Romain Guy *
10ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * Unless required by applicable law or agreed to in writing, software
11ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * See the License for the specific language governing permissions and
14ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * limitations under the License.
15ce0537b80087a6225273040a987414b1dd081aa0Romain Guy */
16ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_TEXTURE_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_TEXTURE_H
19ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
2038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck#include "GpuMemoryTracker.h"
2198fa4f9e7b33a3004ce9142c9acd4300391b9a0esergeyv#include "hwui/Bitmap.h"
22caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy#include "utils/Color.h"
23caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
24caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy#include <memory>
25caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
26caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy#include <math/mat3.h>
27caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
28caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy#include <ui/ColorSpace.h>
2938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
30ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <GLES2/gl2.h>
3166c3a829dc129b6081979facf5a652d5d9f1f51aChris Craik#include <GLES3/gl3.h>
32694d499662838123f474f41b31dea84ec5d563f0sergeyv#include <EGL/egl.h>
33694d499662838123f474f41b31dea84ec5d563f0sergeyv#include <EGL/eglext.h>
34694d499662838123f474f41b31dea84ec5d563f0sergeyv#include <SkBitmap.h>
35ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
36ce0537b80087a6225273040a987414b1dd081aa0Romain Guynamespace android {
37694d499662838123f474f41b31dea84ec5d563f0sergeyv
38694d499662838123f474f41b31dea84ec5d563f0sergeyvclass GraphicBuffer;
39694d499662838123f474f41b31dea84ec5d563f0sergeyv
40ce0537b80087a6225273040a987414b1dd081aa0Romain Guynamespace uirenderer {
41ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
428aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guyclass Caches;
433b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guyclass UvMapper;
4438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reckclass Layer;
453b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
46ce0537b80087a6225273040a987414b1dd081aa0Romain Guy/**
47ce0537b80087a6225273040a987414b1dd081aa0Romain Guy * Represents an OpenGL texture.
48ce0537b80087a6225273040a987414b1dd081aa0Romain Guy */
4938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reckclass Texture : public GpuMemoryTracker {
508aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guypublic:
51efb4b06493fe7b1604c762a448b13c7af2845a8dRomain Guy    static SkBitmap uploadToN32(const SkBitmap& bitmap,
52efb4b06493fe7b1604c762a448b13c7af2845a8dRomain Guy            bool hasLinearBlending, sk_sp<SkColorSpace> sRGB);
53caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    static bool hasUnsupportedColorType(const SkImageInfo& info, bool hasLinearBlending);
54694d499662838123f474f41b31dea84ec5d563f0sergeyv    static void colorTypeToGlFormatAndType(const Caches& caches, SkColorType colorType,
55694d499662838123f474f41b31dea84ec5d563f0sergeyv            bool needSRGB, GLint* outInternalFormat, GLint* outFormat, GLint* outType);
56694d499662838123f474f41b31dea84ec5d563f0sergeyv
5705160d70d14180fef3782a63dff2e822b51c3cf5Chih-Hung Hsieh    explicit Texture(Caches& caches)
5838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck        : GpuMemoryTracker(GpuObjectType::Texture)
5938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck        , mCaches(caches)
6038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    { }
619ace8f5e79e76893fe4ca9e4d10f6c4056330485Romain Guy
62a404e16e4933857464046d763ed7629cd0c86cbfRomain Guy    virtual ~Texture() { }
63a404e16e4933857464046d763ed7629cd0c86cbfRomain Guy
642a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv    inline void setWrap(GLenum wrap, bool bindTexture = false, bool force = false) {
652a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv        setWrapST(wrap, wrap, bindTexture, force);
66d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy    }
67d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy
68a404e16e4933857464046d763ed7629cd0c86cbfRomain Guy    virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false,
692a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv            bool force = false);
70e3c26851dc315b730ea0fe5ef35bb1db81f6d675Romain Guy
712a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv    inline void setFilter(GLenum filter, bool bindTexture = false, bool force = false) {
722a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv        setFilterMinMag(filter, filter, bindTexture, force);
73d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy    }
74d21b6e1fe337b35f62cf2028e9bd0637fd009a75Romain Guy
75a404e16e4933857464046d763ed7629cd0c86cbfRomain Guy    virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false,
762a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv            bool force = false);
7722158e139a3d6c6a9787ca0de224e9368f643284Romain Guy
78ce0537b80087a6225273040a987414b1dd081aa0Romain Guy    /**
79be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy     * Convenience method to call glDeleteTextures() on this texture's id.
80be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy     */
8138e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    void deleteTexture();
82be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy
83be1b127c7bec252e0c6ab0e06ed6babed07d496fRomain Guy    /**
8438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * Sets the width, height, and format of the texture along with allocating
8538e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * the texture ID. Does nothing if the width, height, and format are already
8638e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * the requested values.
8738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     *
8838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * The image data is undefined after calling this.
89ce0537b80087a6225273040a987414b1dd081aa0Romain Guy     */
90253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    void resize(uint32_t width, uint32_t height, GLint internalFormat, GLint format) {
91253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy        upload(internalFormat, width, height, format, GL_UNSIGNED_BYTE, nullptr);
9238e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    }
9338e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
94ce0537b80087a6225273040a987414b1dd081aa0Romain Guy    /**
9598fa4f9e7b33a3004ce9142c9acd4300391b9a0esergeyv     * Updates this Texture with the contents of the provided Bitmap,
9638e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * also setting the appropriate width, height, and format. It is not necessary
9738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * to call resize() prior to this.
9838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     *
9998fa4f9e7b33a3004ce9142c9acd4300391b9a0esergeyv     * Note this does not set the generation from the Bitmap.
100fe8809471a40cac8acc984adfa51c39e13e83947Romain Guy     */
10198fa4f9e7b33a3004ce9142c9acd4300391b9a0esergeyv    void upload(Bitmap& source);
10238e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
103fe8809471a40cac8acc984adfa51c39e13e83947Romain Guy    /**
10438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * Basically glTexImage2D/glTexSubImage2D.
105ce0537b80087a6225273040a987414b1dd081aa0Romain Guy     */
106253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    void upload(GLint internalFormat, uint32_t width, uint32_t height,
10738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck            GLenum format, GLenum type, const void* pixels);
10838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
109ce0537b80087a6225273040a987414b1dd081aa0Romain Guy    /**
11038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * Wraps an existing texture.
111ce0537b80087a6225273040a987414b1dd081aa0Romain Guy     */
1122a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv    void wrap(GLuint id, uint32_t width, uint32_t height, GLint internalFormat,
1132a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv            GLint format, GLenum target);
11438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
11538e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    GLuint id() const {
11638e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck        return mId;
11738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    }
11838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
11938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    uint32_t width() const {
12038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck        return mWidth;
12138e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    }
12238e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
12338e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    uint32_t height() const {
12438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck        return mHeight;
12538e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    }
12638e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
12738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    GLint format() const {
12838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck        return mFormat;
12938e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    }
13038e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
131253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    GLint internalFormat() const {
132253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy        return mInternalFormat;
133253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    }
134253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy
1352a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv    GLenum target() const {
1362a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv        return mTarget;
1372a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv    }
1382a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv
139ce0537b80087a6225273040a987414b1dd081aa0Romain Guy    /**
140caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy     * Returns nullptr if this texture does not require color space conversion
141caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy     * to sRGB, or a valid pointer to a ColorSpaceConnector if a conversion
142caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy     * is required.
143caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy     */
144caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    constexpr const ColorSpaceConnector* getColorSpaceConnector() const {
145caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        return mConnector.get();
146caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    }
147caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
148caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    constexpr bool hasColorSpaceConversion() const {
149caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        return mConnector.get() != nullptr;
150caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    }
151caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
152caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    TransferFunctionType getTransferFunctionType() const;
153caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
154caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    /**
155636afc1877882dc9cf73b49f8a68c73cc418d8cdRomain Guy     * Returns true if this texture uses a linear encoding format.
156636afc1877882dc9cf73b49f8a68c73cc418d8cdRomain Guy     */
157caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    constexpr bool isLinear() const {
158caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy        return mInternalFormat == GL_RGBA16F;
159caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    }
160636afc1877882dc9cf73b49f8a68c73cc418d8cdRomain Guy
161636afc1877882dc9cf73b49f8a68c73cc418d8cdRomain Guy    /**
16238e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * Generation of the backing bitmap,
163ce0537b80087a6225273040a987414b1dd081aa0Romain Guy     */
16438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    uint32_t generation = 0;
16538e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    /**
16638e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     * Indicates whether the texture requires blending.
16738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck     */
16838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    bool blend = false;
16922158e139a3d6c6a9787ca0de224e9368f643284Romain Guy    /**
17022158e139a3d6c6a9787ca0de224e9368f643284Romain Guy     * Indicates whether this texture should be cleaned up after use.
17122158e139a3d6c6a9787ca0de224e9368f643284Romain Guy     */
172e2bb380bc26749782c873e5488cfdf4e42b27346Chris Craik    bool cleanup = false;
1739aaa8269a3e7291aab84d01c3fc9c744d8f2d2f4Romain Guy    /**
1749aaa8269a3e7291aab84d01c3fc9c744d8f2d2f4Romain Guy     * Optional, size of the original bitmap.
1759aaa8269a3e7291aab84d01c3fc9c744d8f2d2f4Romain Guy     */
1768e93a7c9377b4ae43ecfb408f4906a09f6c83c03Chris Craik    uint32_t bitmapSize = 0;
177713e1bb9df6bdfc21bd5c40d1a6ecf6c822a4be5Romain Guy    /**
178713e1bb9df6bdfc21bd5c40d1a6ecf6c822a4be5Romain Guy     * Indicates whether this texture will use trilinear filtering.
179713e1bb9df6bdfc21bd5c40d1a6ecf6c822a4be5Romain Guy     */
1808e93a7c9377b4ae43ecfb408f4906a09f6c83c03Chris Craik    bool mipMap = false;
1818164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy
1823b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy    /**
1833b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     * Optional, pointer to a texture coordinates mapper.
1843b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy     */
1858e93a7c9377b4ae43ecfb408f4906a09f6c83c03Chris Craik    const UvMapper* uvMapper = nullptr;
1863b748a44c6bd2ea05fe16839caf73dbe50bd7ae9Romain Guy
187860d155f866cc15a725e7ce03763280987f24901John Reck    /**
188860d155f866cc15a725e7ce03763280987f24901John Reck     * Whether or not the Texture is marked in use and thus not evictable for
189860d155f866cc15a725e7ce03763280987f24901John Reck     * the current frame. This is reset at the start of a new frame.
190860d155f866cc15a725e7ce03763280987f24901John Reck     */
19100e79c9947b741194ff6c0d08ede9b3befbf9c9dJohn Reck    void* isInUse = nullptr;
192713e1bb9df6bdfc21bd5c40d1a6ecf6c822a4be5Romain Guyprivate:
1938cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel    // TODO: Temporarily grant private access to GlLayer, remove once
1948cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel    // GlLayer can be de-tangled from being a dual-purpose render target
19538e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    // and external texture wrapper
1968cd3edfa15cc9cdbffa935d19ab894426b08d174Greg Daniel    friend class GlLayer;
19738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
198caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    // Returns true if the texture layout (size, format, etc.) changed, false if it was the same
199caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    bool updateLayout(uint32_t width, uint32_t height, GLint internalFormat,
2002a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv            GLint format, GLenum target);
201694d499662838123f474f41b31dea84ec5d563f0sergeyv    void uploadHardwareBitmapToTexture(GraphicBuffer* buffer);
20248247a2956f34d5d709660869273e0f7356e42b6John Reck    void resetCachedParams();
20338e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
20438e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    GLuint mId = 0;
20538e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    uint32_t mWidth = 0;
20638e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    uint32_t mHeight = 0;
20738e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    GLint mFormat = 0;
208253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy    GLint mInternalFormat = 0;
2092a38c42e921451abebb4ee5f5ecd738f1b6b04edsergeyv    GLenum mTarget = GL_NONE;
210694d499662838123f474f41b31dea84ec5d563f0sergeyv    EGLImageKHR mEglImageHandle = EGL_NO_IMAGE_KHR;
21138e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck
21248247a2956f34d5d709660869273e0f7356e42b6John Reck    /* See GLES spec section 3.8.14
21348247a2956f34d5d709660869273e0f7356e42b6John Reck     * "In the initial state, the value assigned to TEXTURE_MIN_FILTER is
21448247a2956f34d5d709660869273e0f7356e42b6John Reck     * NEAREST_MIPMAP_LINEAR and the value for TEXTURE_MAG_FILTER is LINEAR.
21548247a2956f34d5d709660869273e0f7356e42b6John Reck     * s, t, and r wrap modes are all set to REPEAT."
2168164c2d338781c3a3c4a443941070dca5d88f2a7Romain Guy     */
21748247a2956f34d5d709660869273e0f7356e42b6John Reck    GLenum mWrapS = GL_REPEAT;
21848247a2956f34d5d709660869273e0f7356e42b6John Reck    GLenum mWrapT = GL_REPEAT;
21948247a2956f34d5d709660869273e0f7356e42b6John Reck    GLenum mMinFilter = GL_NEAREST_MIPMAP_LINEAR;
22048247a2956f34d5d709660869273e0f7356e42b6John Reck    GLenum mMagFilter = GL_LINEAR;
221e3c26851dc315b730ea0fe5ef35bb1db81f6d675Romain Guy
2228aa195d7081b889f3a7b1f426cbd8556377aae5eRomain Guy    Caches& mCaches;
223caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy
224caaaa66e57293e4a6f312649bf472eab84d5c7feRomain Guy    std::unique_ptr<ColorSpaceConnector> mConnector;
225ce0537b80087a6225273040a987414b1dd081aa0Romain Guy}; // struct Texture
226ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
22722158e139a3d6c6a9787ca0de224e9368f643284Romain Guyclass AutoTexture {
22822158e139a3d6c6a9787ca0de224e9368f643284Romain Guypublic:
22905160d70d14180fef3782a63dff2e822b51c3cf5Chih-Hung Hsieh    explicit AutoTexture(Texture* texture)
230386aa031793bb037ec43b6cdbd8908c343cc86cbChris Craik            : texture(texture) {}
23122158e139a3d6c6a9787ca0de224e9368f643284Romain Guy    ~AutoTexture() {
232386aa031793bb037ec43b6cdbd8908c343cc86cbChris Craik        if (texture && texture->cleanup) {
233386aa031793bb037ec43b6cdbd8908c343cc86cbChris Craik            texture->deleteTexture();
234386aa031793bb037ec43b6cdbd8908c343cc86cbChris Craik            delete texture;
23522158e139a3d6c6a9787ca0de224e9368f643284Romain Guy        }
23622158e139a3d6c6a9787ca0de224e9368f643284Romain Guy    }
23722158e139a3d6c6a9787ca0de224e9368f643284Romain Guy
23838e0c32852e3b9d8ca4a9d3791577f52536419cbJohn Reck    Texture* const texture;
23922158e139a3d6c6a9787ca0de224e9368f643284Romain Guy}; // class AutoTexture
24022158e139a3d6c6a9787ca0de224e9368f643284Romain Guy
241ce0537b80087a6225273040a987414b1dd081aa0Romain Guy}; // namespace uirenderer
242ce0537b80087a6225273040a987414b1dd081aa0Romain Guy}; // namespace android
243ce0537b80087a6225273040a987414b1dd081aa0Romain Guy
2445b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_TEXTURE_H
245