GrGLTexture.h revision 9e3f1bf4e5cd8fc59554f986f36d6b034e99f9eb
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 fMaxMipMapLevel;
27        GrGLenum fSwizzleRGBA[4];
28        GrGLenum fSRGBDecode;
29        void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
30    };
31
32    struct IDDesc {
33        GrGLTextureInfo             fInfo;
34        GrGpuResource::LifeCycle    fLifeCycle;
35    };
36
37    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
38    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided);
39
40    GrBackendObject getTextureHandle() const override;
41
42    void textureParamsModified() override { fTexParams.invalidate(); }
43
44    // These functions are used to track the texture parameters associated with the texture.
45    const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
46        *timestamp = fTexParamsTimestamp;
47        return fTexParams;
48    }
49
50    void setCachedTexParams(const TexParams& texParams,
51                            GrGpu::ResetTimestamp timestamp) {
52        fTexParams = texParams;
53        fTexParamsTimestamp = timestamp;
54    }
55
56    GrGLuint textureID() const { return fInfo.fID; }
57
58    GrGLenum target() const { return fInfo.fTarget; }
59
60protected:
61    // The public constructor registers this object with the cache. However, only the most derived
62    // class should register with the cache. This constructor does not do the registration and
63    // rather moves that burden onto the derived class.
64    enum Derived { kDerived };
65    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived);
66
67    void init(const GrSurfaceDesc&, const IDDesc&);
68
69    void onAbandon() override;
70    void onRelease() override;
71    void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
72                          const SkString& dumpName) const override;
73
74private:
75    TexParams                       fTexParams;
76    GrGpu::ResetTimestamp           fTexParamsTimestamp;
77    // Holds the texture target and ID. A pointer to this may be shared to external clients for
78    // direct interaction with the GL object.
79    GrGLTextureInfo                 fInfo;
80
81    // We track this separately from GrGpuResource because this may be both a texture and a render
82    // target, and the texture may be wrapped while the render target is not.
83    LifeCycle                       fTextureIDLifecycle;
84
85    typedef GrTexture INHERITED;
86};
87
88#endif
89