| 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 /** | |
| 17 * A ref counted tex id that deletes the texture in its destructor. | |
| 18 */ | |
| 19 class GrGLTexID : public SkRefCnt { | |
| 20 public: | |
| 21 SK_DECLARE_INST_COUNT(GrGLTexID) | |
| 22 | |
| 23 GrGLTexID(const GrGLInterface* gl, GrGLuint texID, bool isWrapped) | |
| 24 : fGL(gl) | |
| 25 , fTexID(texID) | |
| 26 , fIsWrapped(isWrapped) { | |
| 27 } | |
| 28 | |
| 29 virtual ~GrGLTexID() { | |
| 30 if (0 != fTexID && !fIsWrapped) { | |
| 31 GR_GL_CALL(fGL, DeleteTextures(1, &fTexID)); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 void abandon() { fTexID = 0; } | |
| 36 GrGLuint id() const { return fTexID; } | |
| 37 | |
| 38 private: | |
| 39 const GrGLInterface* fGL; | |
| 40 GrGLuint fTexID; | |
| 41 bool fIsWrapped; | |
| 42 | |
| 43 typedef SkRefCnt INHERITED; | |
| 44 }; | |
| 45 | |
| 46 //////////////////////////////////////////////////////////////////////////////// | |
| 47 | |
| 48 | 16 |
| 49 class GrGLTexture : public GrTexture { | 17 class GrGLTexture : public GrTexture { |
| 50 | 18 |
| 51 public: | 19 public: |
| 52 struct TexParams { | 20 struct TexParams { |
| 53 GrGLenum fMinFilter; | 21 GrGLenum fMinFilter; |
| 54 GrGLenum fMagFilter; | 22 GrGLenum fMagFilter; |
| 55 GrGLenum fWrapS; | 23 GrGLenum fWrapS; |
| 56 GrGLenum fWrapT; | 24 GrGLenum fWrapT; |
| 57 GrGLenum fSwizzleRGBA[4]; | 25 GrGLenum fSwizzleRGBA[4]; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 76 *timestamp = fTexParamsTimestamp; | 44 *timestamp = fTexParamsTimestamp; |
| 77 return fTexParams; | 45 return fTexParams; |
| 78 } | 46 } |
| 79 | 47 |
| 80 void setCachedTexParams(const TexParams& texParams, | 48 void setCachedTexParams(const TexParams& texParams, |
| 81 GrGpu::ResetTimestamp timestamp) { | 49 GrGpu::ResetTimestamp timestamp) { |
| 82 fTexParams = texParams; | 50 fTexParams = texParams; |
| 83 fTexParamsTimestamp = timestamp; | 51 fTexParamsTimestamp = timestamp; |
| 84 } | 52 } |
| 85 | 53 |
| 86 GrGLuint textureID() const { return (fTexIDObj.get()) ? fTexIDObj->id() : 0;
} | 54 GrGLuint textureID() const { return fTextureID; } |
| 87 | 55 |
| 88 protected: | 56 protected: |
| 89 // The public constructor registers this object with the cache. However, onl
y the most derived | 57 // 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 | 58 // class should register with the cache. This constructor does not do the re
gistration and |
| 91 // rather moves that burden onto the derived class. | 59 // rather moves that burden onto the derived class. |
| 92 enum Derived { kDerived }; | 60 enum Derived { kDerived }; |
| 93 GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&, Derived); | 61 GrGLTexture(GrGpuGL*, const GrSurfaceDesc&, const IDDesc&, Derived); |
| 94 | 62 |
| 95 void init(const GrSurfaceDesc&, const IDDesc&); | 63 void init(const GrSurfaceDesc&, const IDDesc&); |
| 96 | 64 |
| 97 virtual void onAbandon() SK_OVERRIDE; | 65 virtual void onAbandon() SK_OVERRIDE; |
| 98 virtual void onRelease() SK_OVERRIDE; | 66 virtual void onRelease() SK_OVERRIDE; |
| 99 | 67 |
| 100 private: | 68 private: |
| 101 TexParams fTexParams; | 69 TexParams fTexParams; |
| 102 GrGpu::ResetTimestamp fTexParamsTimestamp; | 70 GrGpu::ResetTimestamp fTexParamsTimestamp; |
| 103 SkAutoTUnref<GrGLTexID> fTexIDObj; | 71 GrGLuint fTextureID; |
| 104 | 72 |
| 105 typedef GrTexture INHERITED; | 73 typedef GrTexture INHERITED; |
| 106 }; | 74 }; |
| 107 | 75 |
| 108 #endif | 76 #endif |
| OLD | NEW |