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 #include "experimental/graphite/include/BackendTexture.h" 9 10 namespace skgpu { 11 ~BackendTexture()12BackendTexture::~BackendTexture() {} 13 BackendTexture(const BackendTexture & that)14BackendTexture::BackendTexture(const BackendTexture& that) { 15 *this = that; 16 } 17 operator =(const BackendTexture & that)18BackendTexture& BackendTexture::operator=(const BackendTexture& that) { 19 bool valid = this->isValid(); 20 if (!that.isValid()) { 21 fInfo = {}; 22 return *this; 23 } else if (valid && this->backend() != that.backend()) { 24 valid = false; 25 } 26 fDimensions = that.fDimensions; 27 fInfo = that.fInfo; 28 29 switch (that.backend()) { 30 #ifdef SK_METAL 31 case BackendApi::kMetal: 32 fMtlTexture = that.fMtlTexture; 33 break; 34 #endif 35 default: 36 SK_ABORT("Unsupport Backend"); 37 } 38 return *this; 39 } 40 operator ==(const BackendTexture & that) const41bool BackendTexture::operator==(const BackendTexture& that) const { 42 if (!this->isValid() || !that.isValid()) { 43 return false; 44 } 45 46 if (fDimensions != that.fDimensions || fInfo != that.fInfo) { 47 return false; 48 } 49 50 switch (that.backend()) { 51 #ifdef SK_METAL 52 case BackendApi::kMetal: 53 if (fMtlTexture != that.fMtlTexture) { 54 return false; 55 } 56 break; 57 #endif 58 default: 59 SK_ABORT("Unsupport Backend"); 60 } 61 return true; 62 } 63 64 #ifdef SK_METAL BackendTexture(SkISize dimensions,mtl::Handle mtlTexture)65BackendTexture::BackendTexture(SkISize dimensions, mtl::Handle mtlTexture) 66 : fDimensions(dimensions) 67 , fInfo(mtl::TextureInfo(mtlTexture)) 68 , fMtlTexture(mtlTexture) {} 69 getMtlTexture() const70mtl::Handle BackendTexture::getMtlTexture() const { 71 if (this->isValid() && this->backend() == BackendApi::kMetal) { 72 return fMtlTexture; 73 } 74 return nullptr; 75 } 76 77 #endif 78 79 } // namespace skgpu 80 81