OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 | 8 |
9 #ifndef GrGLTexture_DEFINED | 9 #ifndef GrGLTexture_DEFINED |
10 #define GrGLTexture_DEFINED | 10 #define GrGLTexture_DEFINED |
11 | 11 |
12 #include "GrGpu.h" | 12 #include "GrGpu.h" |
13 #include "GrTexture.h" | 13 #include "GrTexture.h" |
14 #include "GrGLUtil.h" | 14 #include "GrGLUtil.h" |
15 | 15 |
16 class GrGLGpu; | 16 class GrGLGpu; |
17 | 17 |
18 class GrGLTexture : public GrTexture { | 18 class GrGLTexture : public GrTexture { |
19 | |
20 public: | 19 public: |
21 struct TexParams { | 20 struct TexParams { |
22 GrGLenum fMinFilter; | 21 GrGLenum fMinFilter; |
23 GrGLenum fMagFilter; | 22 GrGLenum fMagFilter; |
24 GrGLenum fWrapS; | 23 GrGLenum fWrapS; |
25 GrGLenum fWrapT; | 24 GrGLenum fWrapT; |
26 GrGLenum fMaxMipMapLevel; | 25 GrGLenum fMaxMipMapLevel; |
27 GrGLenum fSwizzleRGBA[4]; | 26 GrGLenum fSwizzleRGBA[4]; |
28 GrGLenum fSRGBDecode; | 27 GrGLenum fSRGBDecode; |
29 void invalidate() { memset(this, 0xff, sizeof(TexParams)); } | 28 void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
30 }; | 29 }; |
31 | 30 |
32 struct IDDesc { | 31 struct IDDesc { |
33 GrGLTextureInfo fInfo; | 32 GrGLTextureInfo fInfo; |
34 GrGpuResource::LifeCycle fLifeCycle; | 33 GrBackendObjectOwnership fOwnership; |
35 }; | 34 }; |
36 | 35 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&); |
37 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); | 36 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, |
38 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDat
aProvided); | 37 bool wasMipMapDataProvided); |
39 | 38 |
40 GrBackendObject getTextureHandle() const override; | 39 GrBackendObject getTextureHandle() const override; |
41 | 40 |
42 void textureParamsModified() override { fTexParams.invalidate(); } | 41 void textureParamsModified() override { fTexParams.invalidate(); } |
43 | 42 |
44 // These functions are used to track the texture parameters associated with
the texture. | 43 // These functions are used to track the texture parameters associated with
the texture. |
45 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const
{ | 44 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const
{ |
46 *timestamp = fTexParamsTimestamp; | 45 *timestamp = fTexParamsTimestamp; |
47 return fTexParams; | 46 return fTexParams; |
48 } | 47 } |
49 | 48 |
50 void setCachedTexParams(const TexParams& texParams, | 49 void setCachedTexParams(const TexParams& texParams, |
51 GrGpu::ResetTimestamp timestamp) { | 50 GrGpu::ResetTimestamp timestamp) { |
52 fTexParams = texParams; | 51 fTexParams = texParams; |
53 fTexParamsTimestamp = timestamp; | 52 fTexParamsTimestamp = timestamp; |
54 } | 53 } |
55 | 54 |
56 GrGLuint textureID() const { return fInfo.fID; } | 55 GrGLuint textureID() const { return fInfo.fID; } |
57 | 56 |
58 GrGLenum target() const { return fInfo.fTarget; } | 57 GrGLenum target() const { return fInfo.fTarget; } |
59 | 58 |
| 59 static GrGLTexture* CreateWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDe
sc&); |
60 protected: | 60 protected: |
61 // The public constructor registers this object with the cache. However, onl
y the most derived | 61 // Constructor for subclasses. |
62 // class should register with the cache. This constructor does not do the re
gistration and | 62 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); |
63 // rather moves that burden onto the derived class. | 63 |
64 enum Derived { kDerived }; | 64 enum Wrapped { kWrapped }; |
65 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived); | 65 // Constructor for instances wrapping backend objects. |
| 66 GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&); |
66 | 67 |
67 void init(const GrSurfaceDesc&, const IDDesc&); | 68 void init(const GrSurfaceDesc&, const IDDesc&); |
68 | 69 |
69 void onAbandon() override; | 70 void onAbandon() override; |
70 void onRelease() override; | 71 void onRelease() override; |
71 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, | 72 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
72 const SkString& dumpName) const override; | 73 const SkString& dumpName) const override; |
73 | 74 |
74 private: | 75 private: |
75 TexParams fTexParams; | 76 TexParams fTexParams; |
76 GrGpu::ResetTimestamp fTexParamsTimestamp; | 77 GrGpu::ResetTimestamp fTexParamsTimestamp; |
77 // Holds the texture target and ID. A pointer to this may be shared to exter
nal clients for | 78 // Holds the texture target and ID. A pointer to this may be shared to exter
nal clients for |
78 // direct interaction with the GL object. | 79 // direct interaction with the GL object. |
79 GrGLTextureInfo fInfo; | 80 GrGLTextureInfo fInfo; |
80 | 81 GrBackendObjectOwnership fTextureIDOwnership; |
81 // We track this separately from GrGpuResource because this may be both a te
xture and a render | |
82 // target, and the texture may be wrapped while the render target is not. | |
83 LifeCycle fTextureIDLifecycle; | |
84 | 82 |
85 typedef GrTexture INHERITED; | 83 typedef GrTexture INHERITED; |
86 }; | 84 }; |
87 | 85 |
88 #endif | 86 #endif |
OLD | NEW |