| 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 "GrGLRenderTarget.h" | 13 #include "GrTexture.h" |
| 14 #include "GrGLUtil.h" |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * A ref counted tex id that deletes the texture in its destructor. | 17 * A ref counted tex id that deletes the texture in its destructor. |
| 17 */ | 18 */ |
| 18 class GrGLTexID : public SkRefCnt { | 19 class GrGLTexID : public SkRefCnt { |
| 19 public: | 20 public: |
| 20 SK_DECLARE_INST_COUNT(GrGLTexID) | 21 SK_DECLARE_INST_COUNT(GrGLTexID) |
| 21 | 22 |
| 22 GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped) | 23 GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped) |
| 23 : fGL(gl) | 24 : fGL(gl) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 GrGLenum fWrapT; | 56 GrGLenum fWrapT; |
| 56 GrGLenum fSwizzleRGBA[4]; | 57 GrGLenum fSwizzleRGBA[4]; |
| 57 void invalidate() { memset(this, 0xff, sizeof(TexParams)); } | 58 void invalidate() { memset(this, 0xff, sizeof(TexParams)); } |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 struct IDDesc { | 61 struct IDDesc { |
| 61 GrGLuint fTextureID; | 62 GrGLuint fTextureID; |
| 62 bool fIsWrapped; | 63 bool fIsWrapped; |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 // creates a texture that is also an RT | 66 GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&); |
| 66 GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&, const GrGLRen
derTarget::IDDesc&); | |
| 67 | |
| 68 // creates a non-RT texture | |
| 69 GrGLTexture(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&); | |
| 70 | 67 |
| 71 virtual ~GrGLTexture() { this->release(); } | 68 virtual ~GrGLTexture() { this->release(); } |
| 72 | 69 |
| 73 virtual GrBackendObject getTextureHandle() const SK_OVERRIDE; | 70 virtual GrBackendObject getTextureHandle() const SK_OVERRIDE; |
| 74 | 71 |
| 75 virtual void textureParamsModified() SK_OVERRIDE { fTexParams.invalidate();
} | 72 virtual void textureParamsModified() SK_OVERRIDE { fTexParams.invalidate();
} |
| 76 | 73 |
| 77 // These functions are used to track the texture parameters associated with
the texture. | 74 // These functions are used to track the texture parameters associated with
the texture. |
| 78 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const
{ | 75 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const
{ |
| 79 *timestamp = fTexParamsTimestamp; | 76 *timestamp = fTexParamsTimestamp; |
| 80 return fTexParams; | 77 return fTexParams; |
| 81 } | 78 } |
| 82 | 79 |
| 83 void setCachedTexParams(const TexParams& texParams, | 80 void setCachedTexParams(const TexParams& texParams, |
| 84 GrGpu::ResetTimestamp timestamp) { | 81 GrGpu::ResetTimestamp timestamp) { |
| 85 fTexParams = texParams; | 82 fTexParams = texParams; |
| 86 fTexParamsTimestamp = timestamp; | 83 fTexParamsTimestamp = timestamp; |
| 87 } | 84 } |
| 88 | 85 |
| 89 GrGLuint textureID() const { return (fTexIDObj.get()) ? fTexIDObj->id() : 0;
} | 86 GrGLuint textureID() const { return (fTexIDObj.get()) ? fTexIDObj->id() : 0;
} |
| 90 | 87 |
| 91 protected: | 88 protected: |
| 92 // overrides of GrTexture | 89 // The public constructor registers this object with the cache. However, onl
y the most derived |
| 90 // class should register with the cache. This constructor does not do the re
gistration and |
| 91 // rather moves that burden onto the derived class. |
| 92 enum Derived { kDerived }; |
| 93 GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&, Derived); |
| 94 |
| 95 void init(const GrSurfaceDesc&, const IDDesc&); |
| 96 |
| 93 virtual void onAbandon() SK_OVERRIDE; | 97 virtual void onAbandon() SK_OVERRIDE; |
| 94 virtual void onRelease() SK_OVERRIDE; | 98 virtual void onRelease() SK_OVERRIDE; |
| 95 | 99 |
| 96 private: | 100 private: |
| 97 TexParams fTexParams; | 101 TexParams fTexParams; |
| 98 GrGpu::ResetTimestamp fTexParamsTimestamp; | 102 GrGpu::ResetTimestamp fTexParamsTimestamp; |
| 99 SkAutoTUnref<GrGLTexID> fTexIDObj; | 103 SkAutoTUnref<GrGLTexID> fTexIDObj; |
| 100 | 104 |
| 101 void init(GrGpuGL* gpu, const GrSurfaceDesc&, const IDDesc&, const GrGLRende
rTarget::IDDesc*); | |
| 102 | |
| 103 typedef GrTexture INHERITED; | 105 typedef GrTexture INHERITED; |
| 104 }; | 106 }; |
| 105 | 107 |
| 106 #endif | 108 #endif |
| OLD | NEW |