Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / src / gpu / graphite / TextureProxyView.h
1 /*
2  * Copyright 2022 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_TextureProxyView_DEFINED
9 #define skgpu_graphite_TextureProxyView_DEFINED
10
11 #include "include/core/SkRect.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/gpu/graphite/GraphiteTypes.h"
14 #include "src/gpu/Swizzle.h"
15 #include "src/gpu/graphite/TextureProxy.h"
16
17 namespace skgpu::graphite {
18
19 class Recorder;
20
21 class TextureProxyView {
22 public:
23     TextureProxyView() = default;
24
25     TextureProxyView(sk_sp<TextureProxy> proxy, Swizzle swizzle)
26             : fProxy(std::move(proxy)), fSwizzle(swizzle) {}
27
28     // This entry point is used when we don't care about the swizzle.
29     explicit TextureProxyView(sk_sp<TextureProxy> proxy)
30             : fProxy(std::move(proxy)) {}
31
32     TextureProxyView(TextureProxyView&& view) = default;
33     TextureProxyView(const TextureProxyView&) = default;
34
35     explicit operator bool() const { return SkToBool(fProxy.get()); }
36
37     TextureProxyView& operator=(const TextureProxyView&) = default;
38     TextureProxyView& operator=(TextureProxyView&& view) = default;
39
40     bool operator==(const TextureProxyView& view) const {
41         return fProxy == view.fProxy &&
42                fSwizzle == view.fSwizzle;
43     }
44     bool operator!=(const TextureProxyView& other) const { return !(*this == other); }
45
46     int width() const { return this->proxy()->dimensions().width(); }
47     int height() const { return this->proxy()->dimensions().height(); }
48     SkISize dimensions() const { return this->proxy()->dimensions(); }
49
50     Mipmapped mipmapped() const {
51         if (const TextureProxy* proxy = this->proxy()) {
52             return proxy->mipmapped();
53         }
54         return Mipmapped::kNo;
55     }
56
57     TextureProxy* proxy() const { return fProxy.get(); }
58     sk_sp<TextureProxy> refProxy() const { return fProxy; }
59
60     Swizzle swizzle() const { return fSwizzle; }
61
62     void concatSwizzle(Swizzle swizzle) {
63         fSwizzle = skgpu::Swizzle::Concat(fSwizzle, swizzle);
64     }
65
66     TextureProxyView makeSwizzle(Swizzle swizzle) const & {
67         return {fProxy, Swizzle::Concat(fSwizzle, swizzle)};
68     }
69
70     TextureProxyView makeSwizzle(Swizzle swizzle) && {
71         return {std::move(fProxy), Swizzle::Concat(fSwizzle, swizzle)};
72     }
73
74     void reset() {
75         *this = {};
76     }
77
78     // Helper that copies a rect of a src view's proxy and then creates a view for the copy with
79     // the same swizzle as the src view.
80     static TextureProxyView Copy(Recorder* recorder,
81                                  TextureProxyView src,
82                                  Mipmapped mipmapped,
83                                  SkIRect srcRect,
84                                  SkBackingFit fit,
85                                  SkBudgeted budgeted) {
86         // TODO
87         return {};
88     }
89
90     static TextureProxyView Copy(Recorder* recorder,
91                                  TextureProxyView src,
92                                  Mipmapped mipmapped,
93                                  SkBackingFit fit,
94                                  SkBudgeted budgeted) {
95         return TextureProxyView::Copy(recorder, src, mipmapped,
96                                       SkIRect::MakeSize(src.proxy()->dimensions()),
97                                       fit, budgeted);
98     }
99
100     // This does not reset the swizzle, so the View can still be used to access those
101     // properties associated with the detached proxy.
102     sk_sp<TextureProxy> detachProxy() {
103         return std::move(fProxy);
104     }
105
106 private:
107     sk_sp<TextureProxy> fProxy;
108     Swizzle fSwizzle;
109 };
110
111 } // namespace skgpu::graphite
112
113 #endif // skgpu_graphite_TextureProxyView_DEFINED
114