1 2 /* 3 * Copyright 2011 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 #ifndef GrTexture_DEFINED 10 #define GrTexture_DEFINED 11 12 #include "GrSurface.h" 13 #include "GrSamplerParams.h" 14 #include "SkPoint.h" 15 #include "SkRefCnt.h" 16 17 class GrExternalTextureData; 18 class GrTexturePriv; 19 20 class GrTexture : virtual public GrSurface { 21 public: asTexture()22 GrTexture* asTexture() override { return this; } asTexture()23 const GrTexture* asTexture() const override { return this; } 24 25 /** 26 * Return the native ID or handle to the texture, depending on the 27 * platform. e.g. on OpenGL, return the texture ID. 28 */ 29 virtual GrBackendObject getTextureHandle() const = 0; 30 31 /** 32 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been 33 * changed externally to Skia. 34 */ 35 virtual void textureParamsModified() = 0; 36 37 #ifdef SK_DEBUG validate()38 void validate() const { 39 this->INHERITED::validate(); 40 this->validateDesc(); 41 } 42 #endif 43 44 /** Access methods that are only to be used within Skia code. */ 45 inline GrTexturePriv texturePriv(); 46 inline const GrTexturePriv texturePriv() const; 47 48 protected: 49 GrTexture(GrGpu*, const GrSurfaceDesc&, GrSLType samplerType, 50 GrSamplerParams::FilterMode highestFilterMode, bool wasMipMapDataProvided); 51 52 void validateDesc() const; 53 virtual std::unique_ptr<GrExternalTextureData> detachBackendTexture() = 0; 54 55 private: 56 void computeScratchKey(GrScratchKey*) const override; 57 size_t onGpuMemorySize() const override; 58 void dirtyMipMaps(bool mipMapsDirty); 59 60 enum MipMapsStatus { 61 kNotAllocated_MipMapsStatus, 62 kAllocated_MipMapsStatus, 63 kValid_MipMapsStatus 64 }; 65 66 GrSLType fSamplerType; 67 GrSamplerParams::FilterMode fHighestFilterMode; 68 MipMapsStatus fMipMapsStatus; 69 int fMaxMipMapLevel; 70 SkDestinationSurfaceColorMode fMipColorMode; 71 friend class GrTexturePriv; 72 73 typedef GrSurface INHERITED; 74 }; 75 76 #endif 77