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