GrGLTexture.h revision 10528f1d5838ae1cac015024c4e8731484f888d1
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 16class GrGLGpu; 17 18class GrGLTexture : public GrTexture { 19 20public: 21 struct TexParams { 22 GrGLenum fMinFilter; 23 GrGLenum fMagFilter; 24 GrGLenum fWrapS; 25 GrGLenum fWrapT; 26 GrGLenum fSwizzleRGBA[4]; 27 void invalidate() { memset(this, 0xff, sizeof(TexParams)); } 28 }; 29 30 struct IDDesc { 31 GrGLenum fTarget; 32 GrGLuint fTextureID; 33 GrGpuResource::LifeCycle fLifeCycle; 34 }; 35 36 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); 37 38 GrBackendObject getTextureHandle() const override; 39 40 void textureParamsModified() override { fTexParams.invalidate(); } 41 42 // These functions are used to track the texture parameters associated with the texture. 43 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { 44 *timestamp = fTexParamsTimestamp; 45 return fTexParams; 46 } 47 48 void setCachedTexParams(const TexParams& texParams, 49 GrGpu::ResetTimestamp timestamp) { 50 fTexParams = texParams; 51 fTexParamsTimestamp = timestamp; 52 } 53 54 GrGLuint textureID() const { return fTextureID; } 55 56 GrGLenum target() const { return fTarget; } 57 58protected: 59 // The public constructor registers this object with the cache. However, only the most derived 60 // class should register with the cache. This constructor does not do the registration and 61 // rather moves that burden onto the derived class. 62 enum Derived { kDerived }; 63 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, Derived); 64 65 void init(const GrSurfaceDesc&, const IDDesc&); 66 67 void onAbandon() override; 68 void onRelease() override; 69 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, 70 const SkString& dumpName) const override; 71 72private: 73 TexParams fTexParams; 74 GrGpu::ResetTimestamp fTexParamsTimestamp; 75 GrGLenum fTarget; 76 GrGLuint fTextureID; 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