1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9#ifndef GrGLTexture_DEFINED
10#define GrGLTexture_DEFINED
11
12#include "GrGpu.h"
13#include "GrTexture.h"
14#include "GrGLUtil.h"
15
16class GrGLGpu;
17
18class GrGLTexture : public GrTexture {
19
20public:
21    struct TexParams {
22        GrGLenum fMinFilter;
23        GrGLenum fMagFilter;
24        GrGLenum fWrapS;
25        GrGLenum fWrapT;
26        GrGLenum fSwizzleRGBA[4];
27        void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
28    };
29
30    struct IDDesc {
31        GrGLuint                    fTextureID;
32        GrGpuResource::LifeCycle    fLifeCycle;
33    };
34
35    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
36
37    GrBackendObject getTextureHandle() const override;
38
39    void textureParamsModified() override { fTexParams.invalidate(); }
40
41    // These functions are used to track the texture parameters associated with the texture.
42    const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
43        *timestamp = fTexParamsTimestamp;
44        return fTexParams;
45    }
46
47    void setCachedTexParams(const TexParams& texParams,
48                            GrGpu::ResetTimestamp timestamp) {
49        fTexParams = texParams;
50        fTexParamsTimestamp = timestamp;
51    }
52
53    GrGLuint textureID() const { return fTextureID; }
54
55protected:
56    // The public constructor registers this object with the cache. However, only the most derived
57    // class should register with the cache. This constructor does not do the registration and
58    // rather moves that burden onto the derived class.
59    enum Derived { kDerived };
60    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
61
62    void init(const GrSurfaceDesc&, const IDDesc&);
63
64    void onAbandon() override;
65    void onRelease() override;
66
67private:
68    TexParams                       fTexParams;
69    GrGpu::ResetTimestamp           fTexParamsTimestamp;
70    GrGLuint                        fTextureID;
71
72    // We track this separately from GrGpuResource because this may be both a texture and a render
73    // target, and the texture may be wrapped while the render target is not.
74    bool fIsWrapped;
75
76    typedef GrTexture INHERITED;
77};
78
79#endif
80