1 /* 2 * Copyright 2021 Google LLC 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 #ifndef skgpu_graphite_BackendTexture_DEFINED 9 #define skgpu_graphite_BackendTexture_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/core/SkSize.h" 13 #include "include/gpu/graphite/GraphiteTypes.h" 14 #include "include/gpu/graphite/TextureInfo.h" 15 #include "include/private/base/SkAnySubclass.h" 16 17 namespace skgpu::graphite { 18 19 class BackendTextureData; 20 21 class SK_API BackendTexture { 22 public: 23 BackendTexture(); 24 BackendTexture(const BackendTexture&); 25 26 ~BackendTexture(); 27 28 BackendTexture& operator=(const BackendTexture&); 29 30 bool operator==(const BackendTexture&) const; 31 bool operator!=(const BackendTexture& that) const { return !(*this == that); } 32 isValid()33 bool isValid() const { return fInfo.isValid(); } backend()34 BackendApi backend() const { return fInfo.backend(); } 35 dimensions()36 SkISize dimensions() const { return fDimensions; } 37 info()38 const TextureInfo& info() const { return fInfo; } 39 40 private: 41 friend class BackendTextureData; 42 friend class BackendTexturePriv; 43 44 // Size determined by looking at the BackendTextureData subclasses, then guessing-and-checking. 45 // Compiler will complain if this is too small - in that case, just increase the number. 46 inline constexpr static size_t kMaxSubclassSize = 72; 47 using AnyBackendTextureData = SkAnySubclass<BackendTextureData, kMaxSubclassSize>; 48 49 template <typename SomeBackendTextureData> BackendTexture(SkISize dimensions,TextureInfo info,const SomeBackendTextureData & textureData)50 BackendTexture(SkISize dimensions, TextureInfo info, const SomeBackendTextureData& textureData) 51 : fDimensions(dimensions), fInfo(info) { 52 fTextureData.emplace<SomeBackendTextureData>(textureData); 53 } 54 55 SkISize fDimensions; 56 TextureInfo fInfo; 57 AnyBackendTextureData fTextureData; 58 }; 59 60 } // namespace skgpu::graphite 61 62 #endif // skgpu_graphite_BackendTexture_DEFINED 63