GrGLTexture.h revision aa1ab8905e74096f0460af467f126fdb1998a5f9
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 { 19public: 20 struct TexParams { 21 GrGLenum fMinFilter; 22 GrGLenum fMagFilter; 23 GrGLenum fWrapS; 24 GrGLenum fWrapT; 25 GrGLenum fMaxMipMapLevel; 26 GrGLenum fSwizzleRGBA[4]; 27 GrGLenum fSRGBDecode; 28 void invalidate() { memset(this, 0xff, sizeof(TexParams)); } 29 }; 30 31 struct IDDesc { 32 GrGLTextureInfo fInfo; 33 GrBackendObjectOwnership fOwnership; 34 }; 35 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&); 36 GrGLTexture(GrGLGpu*, SkBudgeted, const GrSurfaceDesc&, const IDDesc&, 37 bool wasMipMapDataProvided); 38 39 GrBackendObject getTextureHandle() const override; 40 41 void textureParamsModified() override { fTexParams.invalidate(); } 42 43 // These functions are used to track the texture parameters associated with the texture. 44 const TexParams& getCachedTexParams(GrGpu::ResetTimestamp* timestamp) const { 45 *timestamp = fTexParamsTimestamp; 46 return fTexParams; 47 } 48 49 void setCachedTexParams(const TexParams& texParams, 50 GrGpu::ResetTimestamp timestamp) { 51 fTexParams = texParams; 52 fTexParamsTimestamp = timestamp; 53 } 54 55 GrGLuint textureID() const { return fInfo.fID; } 56 57 GrGLenum target() const { return fInfo.fTarget; } 58 59 static sk_sp<GrGLTexture> MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&); 60protected: 61 // Constructor for subclasses. 62 GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, bool wasMipMapDataProvided); 63 64 enum Wrapped { kWrapped }; 65 // Constructor for instances wrapping backend objects. 66 GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, const IDDesc&); 67 68 void init(const GrSurfaceDesc&, const IDDesc&); 69 70 void onAbandon() override; 71 void onRelease() override; 72 void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, 73 const SkString& dumpName) const override; 74 75private: 76 TexParams fTexParams; 77 GrGpu::ResetTimestamp fTexParamsTimestamp; 78 // Holds the texture target and ID. A pointer to this may be shared to external clients for 79 // direct interaction with the GL object. 80 GrGLTextureInfo fInfo; 81 GrBackendObjectOwnership fTextureIDOwnership; 82 83 typedef GrTexture INHERITED; 84}; 85 86#endif 87