GrGLTexture.h revision 9ad1f92e2fceea33215c0f13cee42a679fb88d44
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 {
19public:
20    struct TexParams {
21        GrGLenum fMinFilter;
22        GrGLenum fMagFilter;
23        GrGLenum fWrapS;
24        GrGLenum fWrapT;
25        GrGLenum fMaxMipMapLevel;
26        GrGLenum fSwizzleRGBA[4];
27        GrGLenum fSRGBDecode;
28        void invalidate() { memset(this, 0xff, sizeof(TexParams)); }
29    };
30
31    struct IDDesc {
32        GrGLTextureInfo             fInfo;
33        GrBackendObjectOwnership    fOwnership;
34    };
35    GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&);
36    GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&,
37                bool wasMipMapDataProvided);
38
39    GrBackendObject getTextureHandle() const override;
40
41    void textureParamsModified() override { fTexParams.invalidate(); }
42
43    // These functions are used to track the texture parameters associated with the texture.
44    const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
45        *timestamp = fTexParamsTimestamp;
46        return fTexParams;
47    }
48
49    void setCachedTexParams(const TexParams& texParams,
50                            GrGpu::ResetTimestamp timestamp) {
51        fTexParams = texParams;
52        fTexParamsTimestamp = timestamp;
53    }
54
55    GrGLuint textureID() const { return fInfo.fID; }
56
57    GrGLenum target() const { return fInfo.fTarget; }
58
59    static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
60protected:
61    // Constructor for subclasses.
62    GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided);
63
64    enum Wrapped { kWrapped };
65    // Constructor for instances wrapping backend objects.
66    GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&);
67
68    void init(const GrSurfaceDesc&, const IDDesc&);
69
70    void onAbandon() override;
71    void onRelease() override;
72    void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
73                          const SkString& dumpName) const override;
74    std::unique_ptr<GrExternalTextureData> detachBackendTexture() override;
75
76private:
77    TexParams                       fTexParams;
78    GrGpu::ResetTimestamp           fTexParamsTimestamp;
79    // Holds the texture target and ID. A pointer to this may be shared to external clients for
80    // direct interaction with the GL object.
81    GrGLTextureInfo                 fInfo;
82    GrBackendObjectOwnership        fTextureIDOwnership;
83
84    typedef GrTexture INHERITED;
85};
86
87#endif
88