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_BackendTexture_DEFINED 9 #define skgpu_BackendTexture_DEFINED 10 11 #include "experimental/graphite/include/GraphiteTypes.h" 12 #include "experimental/graphite/include/TextureInfo.h" 13 #include "include/core/SkSize.h" 14 15 #ifdef SK_METAL 16 #include "experimental/graphite/include/mtl/MtlTypes.h" 17 #endif 18 19 namespace skgpu { 20 21 class BackendTexture { 22 public: BackendTexture()23 BackendTexture() {} 24 #ifdef SK_METAL 25 // The BackendTexture will not call retain or release on the passed in mtl::Handle. Thus the 26 // client must keep the mtl::Handle valid until they are no longer using the BackendTexture. 27 BackendTexture(SkISize dimensions, mtl::Handle mtlTexture); 28 #endif 29 30 BackendTexture(const BackendTexture&); 31 32 ~BackendTexture(); 33 34 BackendTexture& operator=(const BackendTexture&); 35 36 bool operator==(const BackendTexture&) const; 37 bool operator!=(const BackendTexture& that) const { return !(*this == that); } 38 isValid()39 bool isValid() const { return fInfo.isValid(); } backend()40 BackendApi backend() const { return fInfo.backend(); } 41 dimensions()42 SkISize dimensions() const { return fDimensions; } 43 info()44 const TextureInfo& info() const { return fInfo; } 45 46 #ifdef SK_METAL 47 mtl::Handle getMtlTexture() const; 48 #endif 49 50 private: 51 SkISize fDimensions; 52 TextureInfo fInfo; 53 54 union { 55 #ifdef SK_METAL 56 mtl::Handle fMtlTexture; 57 #endif 58 }; 59 }; 60 61 } // namespace skgpu 62 63 #endif // skgpu_BackendTexture_DEFINED 64 65