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