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 20 public: 21 struct TexParams { 22 GrGLenum fMinFilter; 23 GrGLenum fMagFilter; 24 GrGLenum fWrapS; 25 GrGLenum fWrapT; 26 GrGLenum fSwizzleRGBA[4]; invalidateTexParams27 void invalidate() { memset(this, 0xff, sizeof(TexParams)); } 28 }; 29 30 struct IDDesc { 31 GrGLTextureInfo fInfo; 32 GrGpuResource::LifeCycle fLifeCycle; 33 }; 34 35 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); 36 37 GrBackendObject getTextureHandle() const override; 38 textureParamsModified()39 void textureParamsModified() override { fTexParams.invalidate(); } 40 41 // These functions are used to track the texture parameters associated with the texture. getCachedTexParams(GrGpu::ResetTimestamp * timestamp)42 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { 43 *timestamp = fTexParamsTimestamp; 44 return fTexParams; 45 } 46 setCachedTexParams(const TexParams & texParams,GrGpu::ResetTimestamp timestamp)47 void setCachedTexParams(const TexParams& texParams, 48 GrGpu::ResetTimestamp timestamp) { 49 fTexParams = texParams; 50 fTexParamsTimestamp = timestamp; 51 } 52 textureID()53 GrGLuint textureID() const { return fInfo.fID; } 54 target()55 GrGLenum target() const { return fInfo.fTarget; } 56 57 protected: 58 // The public constructor registers this object with the cache. However, only the most derived 59 // class should register with the cache. This constructor does not do the registration and 60 // rather moves that burden onto the derived class. 61 enum Derived { kDerived }; 62 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived); 63 64 void init(const GrSurfaceDesc&, const IDDesc&); 65 66 void onAbandon() override; 67 void onRelease() override; 68 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, 69 const SkString& dumpName) const override; 70 71 private: 72 TexParams fTexParams; 73 GrGpu::ResetTimestamp fTexParamsTimestamp; 74 // Holds the texture target and ID. A pointer to this may be shared to external clients for 75 // direct interaction with the GL object. 76 GrGLTextureInfo fInfo; 77 78 // We track this separately from GrGpuResource because this may be both a texture and a render 79 // target, and the texture may be wrapped while the render target is not. 80 LifeCycle fTextureIDLifecycle; 81 82 typedef GrTexture INHERITED; 83 }; 84 85 #endif 86