xref: /aosp_15_r20/external/skia/src/gpu/graphite/BackendTexturePriv.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2024 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 #ifndef skgpu_graphite_BackendTexturePriv_DEFINED
8 #define skgpu_graphite_BackendTexturePriv_DEFINED
9 
10 #include "include/core/SkString.h"
11 #include "include/gpu/graphite/BackendTexture.h"
12 #include "include/private/base/SkAssert.h"
13 
14 #include <cstdint>
15 
16 namespace skgpu::graphite {
17 
18 class BackendTextureData {
19 public:
20     virtual ~BackendTextureData();
21 
22 #if defined(SK_DEBUG)
23     virtual skgpu::BackendApi type() const = 0;
24 #endif
25 protected:
26     BackendTextureData() = default;
27     BackendTextureData(const BackendTextureData&) = default;
28 
29     using AnyBackendTextureData = BackendTexture::AnyBackendTextureData;
30 
31 private:
32     friend class BackendTexture;
33 
34     virtual void copyTo(AnyBackendTextureData& dstData) const = 0;
35     virtual bool equal(const BackendTextureData* that) const = 0;
36 };
37 
38 class BackendTexturePriv {
39 public:
40     template <typename SomeBackendTextureData>
Make(SkISize dimensions,TextureInfo info,const SomeBackendTextureData & textureData)41     static BackendTexture Make(SkISize dimensions,
42                                TextureInfo info,
43                                const SomeBackendTextureData& textureData) {
44         return BackendTexture(dimensions, info, textureData);
45     }
46 
GetData(const BackendTexture & info)47     static const BackendTextureData* GetData(const BackendTexture& info) {
48         return info.fTextureData.get();
49     }
50 
GetData(BackendTexture * info)51     static BackendTextureData* GetData(BackendTexture* info) {
52         SkASSERT(info);
53         return info->fTextureData.get();
54     }
55 };
56 
57 }  // namespace skgpu::graphite
58 
59 #endif
60