• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TextureProxyView(sk_sp<TextureProxy> proxy,Swizzle swizzle)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.
TextureProxyView(sk_sp<TextureProxy> proxy)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 
width()46     int width() const { return this->proxy()->dimensions().width(); }
height()47     int height() const { return this->proxy()->dimensions().height(); }
dimensions()48     SkISize dimensions() const { return this->proxy()->dimensions(); }
49 
mipmapped()50     skgpu::Mipmapped mipmapped() const {
51         if (const TextureProxy* proxy = this->proxy()) {
52             return proxy->mipmapped();
53         }
54         return skgpu::Mipmapped::kNo;
55     }
56 
proxy()57     TextureProxy* proxy() const { return fProxy.get(); }
refProxy()58     sk_sp<TextureProxy> refProxy() const { return fProxy; }
59 
swizzle()60     Swizzle swizzle() const { return fSwizzle; }
61 
concatSwizzle(Swizzle swizzle)62     void concatSwizzle(Swizzle swizzle) {
63         fSwizzle = skgpu::Swizzle::Concat(fSwizzle, swizzle);
64     }
65 
makeSwizzle(Swizzle swizzle)66     TextureProxyView makeSwizzle(Swizzle swizzle) const & {
67         return {fProxy, Swizzle::Concat(fSwizzle, swizzle)};
68     }
69 
makeSwizzle(Swizzle swizzle)70     TextureProxyView makeSwizzle(Swizzle swizzle) && {
71         return {std::move(fProxy), Swizzle::Concat(fSwizzle, swizzle)};
72     }
73 
reset()74     void reset() {
75         *this = {};
76     }
77 
78     // This does not reset the swizzle, so the View can still be used to access those
79     // properties associated with the detached proxy.
detachProxy()80     sk_sp<TextureProxy> detachProxy() {
81         return std::move(fProxy);
82     }
83 
84     static TextureProxyView Copy(Recorder*,
85                                  const SkColorInfo& srcColorInfo,
86                                  const TextureProxyView& srcView,
87                                  SkIRect srcRect,
88                                  Mipmapped);
89 
90 private:
91     sk_sp<TextureProxy> fProxy;
92     Swizzle fSwizzle;
93 };
94 
95 } // namespace skgpu::graphite
96 
97 #endif // skgpu_graphite_TextureProxyView_DEFINED
98