Debian Codegraph @

include/gpu/graphite/BackendTexture.h

raw
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_graphite_BackendTexture_DEFINED
9 #define skgpu_graphite_BackendTexture_DEFINED
10
11 #include "include/core/SkSize.h"
12 #include "include/gpu/graphite/TextureInfo.h"
13 #include "include/private/base/SkAPI.h"
14 #include "include/private/base/SkAnySubclass.h"
15
16 #include <cstddef>
17
18 namespace skgpu { enum class BackendApi : unsigned int; }
19
20 namespace skgpu::graphite {
21
22 class BackendTextureData;
23
24 class SK_API BackendTexture {
25 public:
26 BackendTexture();
27 BackendTexture(const BackendTexture&);
28
29 ~BackendTexture();
30
31 BackendTexture& operator=(const BackendTexture&);
32
33 bool operator==(const BackendTexture&) const;
34 bool operator!=(const BackendTexture& that) const { return !(*this == that); }
35
36 bool isValid() const { return fInfo.isValid(); }
37 BackendApi backend() const { return fInfo.backend(); }
38
39 SkISize dimensions() const { return fDimensions; }
40
41 const TextureInfo& info() const { return fInfo; }
42
43 private:
44 friend class BackendTextureData;
45 friend class BackendTexturePriv;
46
47 // Size determined by looking at the BackendTextureData subclasses, then guessing-and-checking.
48 // Compiler will complain if this is too small - in that case, just increase the number.
49 inline constexpr static size_t kMaxSubclassSize = 72;
50 using AnyBackendTextureData = SkAnySubclass<BackendTextureData, kMaxSubclassSize>;
51
52 template <typename SomeBackendTextureData>
53 BackendTexture(SkISize dimensions, TextureInfo info, const SomeBackendTextureData& textureData)
54 : fDimensions(dimensions), fInfo(info) {
55 fTextureData.emplace<SomeBackendTextureData>(textureData);
56 }
57
58 SkISize fDimensions;
59 TextureInfo fInfo;
60 AnyBackendTextureData fTextureData;
61 };
62
63 } // namespace skgpu::graphite
64
65 #endif // skgpu_graphite_BackendTexture_DEFINED