Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
TextureProxyView.h
Go to the documentation of this file.
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"
14#include "src/gpu/Swizzle.h"
16
17enum class SkBackingFit;
18
19namespace skgpu::graphite {
20
21class Recorder;
22
24public:
25 TextureProxyView() = default;
26
29
32
33 // This entry point is used when we don't care about the swizzle and assume TopLeft origin.
35 : fProxy(std::move(proxy)) {}
36
39
40 explicit operator bool() const { return SkToBool(fProxy.get()); }
41
44
45 bool operator==(const TextureProxyView& view) const {
46 return fProxy == view.fProxy &&
47 fSwizzle == view.fSwizzle &&
48 fOrigin == view.fOrigin;
49 }
50 bool operator!=(const TextureProxyView& other) const { return !(*this == other); }
51
52 int width() const { return this->proxy()->dimensions().width(); }
53 int height() const { return this->proxy()->dimensions().height(); }
54 SkISize dimensions() const { return this->proxy()->dimensions(); }
55
57 if (const TextureProxy* proxy = this->proxy()) {
58 return proxy->mipmapped();
59 }
60 return skgpu::Mipmapped::kNo;
61 }
62
63 TextureProxy* proxy() const { return fProxy.get(); }
64 sk_sp<TextureProxy> refProxy() const { return fProxy; }
65
66 Swizzle swizzle() const { return fSwizzle; }
67 Origin origin() const { return fOrigin; }
68
70 fSwizzle = skgpu::Swizzle::Concat(fSwizzle, swizzle);
71 }
72
73 // makeSwizzle returns a new view with 'swizzle' composed on to this view's existing swizzle
75 return {fProxy, Swizzle::Concat(fSwizzle, swizzle), fOrigin};
76 }
77
79 return {std::move(fProxy), Swizzle::Concat(fSwizzle, swizzle), fOrigin};
80 }
81
82 // resetSwizzle returns a new view that uses 'swizzle' and disregards this view's prior swizzle.
84 return {fProxy, swizzle, fOrigin};
85 }
86
87 void reset() {
88 *this = {};
89 }
90
91 // This does not reset the swizzle, so the View can still be used to access those
92 // properties associated with the detached proxy.
94 return std::move(fProxy);
95 }
96
97private:
99 Swizzle fSwizzle;
100 Origin fOrigin = Origin::kTopLeft;
101};
102
103} // namespace skgpu::graphite
104
105#endif // skgpu_graphite_TextureProxyView_DEFINED
SkBackingFit
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
static constexpr Swizzle Concat(const Swizzle &a, const Swizzle &b)
Definition Swizzle.h:156
TextureProxyView & operator=(const TextureProxyView &)=default
bool operator==(const TextureProxyView &view) const
TextureProxyView replaceSwizzle(Swizzle swizzle) const
bool operator!=(const TextureProxyView &other) const
TextureProxyView(sk_sp< TextureProxy > proxy, Swizzle swizzle)
TextureProxyView(const TextureProxyView &)=default
void concatSwizzle(Swizzle swizzle)
TextureProxyView(sk_sp< TextureProxy > proxy, Swizzle swizzle, Origin origin)
sk_sp< TextureProxy > refProxy() const
skgpu::Mipmapped mipmapped() const
sk_sp< TextureProxy > detachProxy()
TextureProxyView makeSwizzle(Swizzle swizzle) &&
TextureProxyView makeSwizzle(Swizzle swizzle) const &
TextureProxyView(TextureProxyView &&view)=default
TextureProxyView & operator=(TextureProxyView &&view)=default
TextureProxyView(sk_sp< TextureProxy > proxy)
Mipmapped mipmapped() const
Mipmapped
Definition GpuTypes.h:53
Definition ref_ptr.h:256
constexpr int32_t width() const
Definition SkSize.h:36
constexpr int32_t height() const
Definition SkSize.h:37