| 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 "include/gpu/graphite/BackendTexture.h" |
| 9 |
|
| 10 |
#include "include/gpu/GpuTypes.h" |
| 11 |
#include "include/private/base/SkAssert.h" |
| 12 |
#include "src/gpu/graphite/BackendTexturePriv.h" |
| 13 |
|
| 14 |
namespace skgpu::graphite { |
| 15 |
|
| 16 |
BackendTexture::BackendTexture() = default; |
| 17 |
|
| 18 |
BackendTexture::~BackendTexture() = default; |
| 19 |
|
| 20 |
BackendTexture::BackendTexture(const BackendTexture& that) { |
| 21 |
*this = that; |
| 22 |
} |
| 23 |
|
| 24 |
static inline void assert_is_supported_backend(const BackendApi& backend) { |
| 25 |
SkASSERT(backend == BackendApi::kDawn || |
| 26 |
backend == BackendApi::kMetal || |
| 27 |
backend == BackendApi::kVulkan); |
| 28 |
} |
| 29 |
|
| 30 |
BackendTexture& BackendTexture::operator=(const BackendTexture& that) { |
| 31 |
if (!that.isValid()) { |
| 32 |
fInfo = {}; |
| 33 |
return *this; |
| 34 |
} |
| 35 |
// We shouldn't be mixing backends. |
| 36 |
SkASSERT(!this->isValid() || this->backend() == that.backend()); |
| 37 |
// If that was valid, it should have a supported backend. |
| 38 |
assert_is_supported_backend(that.backend()); |
| 39 |
fDimensions = that.fDimensions; |
| 40 |
fInfo = that.fInfo; |
| 41 |
|
| 42 |
fTextureData.reset(); |
| 43 |
that.fTextureData->copyTo(fTextureData); |
| 44 |
return *this; |
| 45 |
} |
| 46 |
|
| 47 |
bool BackendTexture::operator==(const BackendTexture& that) const { |
| 48 |
if (!this->isValid() || !that.isValid()) { |
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
if (fDimensions != that.fDimensions || fInfo != that.fInfo) { |
| 53 |
return false; |
| 54 |
} |
| 55 |
assert_is_supported_backend(this->backend()); |
| 56 |
return fTextureData->equal(that.fTextureData.get()); |
| 57 |
} |
| 58 |
|
| 59 |
BackendTextureData::~BackendTextureData() {} |
| 60 |
|
| 61 |
} // namespace skgpu::graphite |
| 62 |
|