2 * Copyright 2022 Google LLC
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef skgpu_graphite_TextureProxyView_DEFINED
9 #define skgpu_graphite_TextureProxyView_DEFINED
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"
17 namespace skgpu::graphite {
21 class TextureProxyView {
23 TextureProxyView() = default;
25 TextureProxyView(sk_sp<TextureProxy> proxy, Swizzle swizzle)
26 : fProxy(std::move(proxy)), fSwizzle(swizzle) {}
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)) {}
32 TextureProxyView(TextureProxyView&& view) = default;
33 TextureProxyView(const TextureProxyView&) = default;
35 explicit operator bool() const { return SkToBool(fProxy.get()); }
37 TextureProxyView& operator=(const TextureProxyView&) = default;
38 TextureProxyView& operator=(TextureProxyView&& view) = default;
40 bool operator==(const TextureProxyView& view) const {
41 return fProxy == view.fProxy &&
42 fSwizzle == view.fSwizzle;
44 bool operator!=(const TextureProxyView& other) const { return !(*this == other); }
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(); }
50 Mipmapped mipmapped() const {
51 if (const TextureProxy* proxy = this->proxy()) {
52 return proxy->mipmapped();
54 return Mipmapped::kNo;
57 TextureProxy* proxy() const { return fProxy.get(); }
58 sk_sp<TextureProxy> refProxy() const { return fProxy; }
60 Swizzle swizzle() const { return fSwizzle; }
62 void concatSwizzle(Swizzle swizzle) {
63 fSwizzle = skgpu::Swizzle::Concat(fSwizzle, swizzle);
66 TextureProxyView makeSwizzle(Swizzle swizzle) const & {
67 return {fProxy, Swizzle::Concat(fSwizzle, swizzle)};
70 TextureProxyView makeSwizzle(Swizzle swizzle) && {
71 return {std::move(fProxy), Swizzle::Concat(fSwizzle, swizzle)};
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,
85 SkBudgeted budgeted) {
90 static TextureProxyView Copy(Recorder* recorder,
94 SkBudgeted budgeted) {
95 return TextureProxyView::Copy(recorder, src, mipmapped,
96 SkIRect::MakeSize(src.proxy()->dimensions()),
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);
107 sk_sp<TextureProxy> fProxy;
111 } // namespace skgpu::graphite
113 #endif // skgpu_graphite_TextureProxyView_DEFINED