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 "include/core/SkImage.h" 13 #include "include/core/SkPoint.h" 14 #include "include/core/SkRefCnt.h" 15 #include "include/gpu/GrBackendSurface.h" 16 #include "include/private/GrTypesPriv.h" 17 #include "src/gpu/GrSurface.h" 18 19 class GrTexture : virtual public GrSurface { 20 public: asTexture()21 GrTexture* asTexture() override { return this; } asTexture()22 const GrTexture* asTexture() const override { return this; } 23 24 virtual GrBackendTexture getBackendTexture() const = 0; 25 26 /** 27 * This function indicates that the texture parameters (wrap mode, filtering, ...) have been 28 * changed externally to Skia. 29 */ 30 virtual void textureParamsModified() = 0; 31 32 /** 33 * This function steals the backend texture from a uniquely owned GrTexture with no pending 34 * IO, passing it out to the caller. The GrTexture is deleted in the process. 35 * 36 * Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this 37 * function will fail. 38 */ 39 static bool StealBackendTexture(sk_sp<GrTexture>, 40 GrBackendTexture*, 41 SkImage::BackendTextureReleaseProc*); 42 textureType()43 GrTextureType textureType() const { return fTextureType; } hasRestrictedSampling()44 bool hasRestrictedSampling() const { 45 return GrTextureTypeHasRestrictedSampling(this->textureType()); 46 } 47 48 void markMipmapsDirty(); 49 void markMipmapsClean(); mipmapped()50 GrMipmapped mipmapped() const { 51 return GrMipmapped(fMipmapStatus != GrMipmapStatus::kNotAllocated); 52 } mipmapsAreDirty()53 bool mipmapsAreDirty() const { return fMipmapStatus != GrMipmapStatus::kValid; } mipmapStatus()54 GrMipmapStatus mipmapStatus() const { return fMipmapStatus; } maxMipmapLevel()55 int maxMipmapLevel() const { return fMaxMipmapLevel; } 56 57 static void ComputeScratchKey(const GrCaps& caps, 58 const GrBackendFormat& format, 59 SkISize dimensions, 60 GrRenderable, 61 int sampleCnt, 62 GrMipmapped, 63 GrProtected, 64 GrScratchKey* key); 65 66 protected: 67 GrTexture(GrGpu*, const SkISize&, GrProtected, GrTextureType, GrMipmapStatus); 68 69 virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0; 70 71 void computeScratchKey(GrScratchKey*) const override; 72 73 private: 74 size_t onGpuMemorySize() const override; 75 76 GrTextureType fTextureType; 77 GrMipmapStatus fMipmapStatus; 78 int fMaxMipmapLevel; 79 friend class GrTextureResource; 80 81 using INHERITED = GrSurface; 82 }; 83 84 #endif 85