• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 class GrGLGpu;
17 
18 class GrGLTexture : public GrTexture {
19 public:
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;
invalidateTexParams28         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 
~GrGLTexture()39     ~GrGLTexture() override {
40         // check that invokeReleaseProc has been called (if needed)
41         SkASSERT(!fReleaseProc);
42     }
43 
44     GrBackendObject getTextureHandle() const override;
45 
textureParamsModified()46     void textureParamsModified() override { fTexParams.invalidate(); }
47 
setRelease(ReleaseProc proc,ReleaseCtx ctx)48     void setRelease(ReleaseProc proc, ReleaseCtx ctx) override {
49         fReleaseProc = proc;
50         fReleaseCtx = ctx;
51     }
52 
53     // These functions are used to track the texture parameters associated with the texture.
getCachedTexParams(GrGpu::ResetTimestamp * timestamp)54     const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const {
55         *timestamp = fTexParamsTimestamp;
56         return fTexParams;
57     }
58 
setCachedTexParams(const TexParams & texParams,GrGpu::ResetTimestamp timestamp)59     void setCachedTexParams(const TexParams& texParams,
60                             GrGpu::ResetTimestamp timestamp) {
61         fTexParams = texParams;
62         fTexParamsTimestamp = timestamp;
63     }
64 
textureID()65     GrGLuint textureID() const { return fInfo.fID; }
66 
target()67     GrGLenum target() const { return fInfo.fTarget; }
68 
hasBaseLevelBeenBoundToFBO()69     bool hasBaseLevelBeenBoundToFBO() const { return fBaseLevelHasBeenBoundToFBO; }
baseLevelWasBoundToFBO()70     void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; }
71 
72     static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&);
73 
74 protected:
75     // Constructor for subclasses.
76     GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided);
77 
78     enum Wrapped { kWrapped };
79     // Constructor for instances wrapping backend objects.
80     GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&);
81 
82     void init(const GrSurfaceDesc&, const IDDesc&);
83 
84     void onAbandon() override;
85     void onRelease() override;
86     void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
87                           const SkString& dumpName) const override;
88 
89 private:
invokeReleaseProc()90     void invokeReleaseProc() {
91         if (fReleaseProc) {
92             fReleaseProc(fReleaseCtx);
93             fReleaseProc = nullptr;
94         }
95     }
96 
97     TexParams                       fTexParams;
98     GrGpu::ResetTimestamp           fTexParamsTimestamp;
99     // Holds the texture target and ID. A pointer to this may be shared to external clients for
100     // direct interaction with the GL object.
101     GrGLTextureInfo                 fInfo;
102     GrBackendObjectOwnership        fTextureIDOwnership;
103     bool                            fBaseLevelHasBeenBoundToFBO = false;
104 
105     ReleaseProc                     fReleaseProc = nullptr;
106     ReleaseCtx                      fReleaseCtx = nullptr;
107 
108     typedef GrTexture INHERITED;
109 };
110 
111 #endif
112