| 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 |
enum class SkBackingFit; |
| 18 |
|
| 19 |
namespace skgpu::graphite { |
| 20 |
|
| 21 |
class Recorder; |
| 22 |
|
| 23 |
class TextureProxyView { |
| 24 |
public: |
| 25 |
TextureProxyView() = default; |
| 26 |
|
| 27 |
TextureProxyView(sk_sp<TextureProxy> proxy, Swizzle swizzle) |
| 28 |
: fProxy(std::move(proxy)), fSwizzle(swizzle) {} |
| 29 |
|
| 30 |
TextureProxyView(sk_sp<TextureProxy> proxy, Swizzle swizzle, Origin origin) |
| 31 |
: fProxy(std::move(proxy)), fSwizzle(swizzle), fOrigin(origin) {} |
| 32 |
|
| 33 |
// This entry point is used when we don't care about the swizzle and assume TopLeft origin. |
| 34 |
explicit TextureProxyView(sk_sp<TextureProxy> proxy) |
| 35 |
: fProxy(std::move(proxy)) {} |
| 36 |
|
| 37 |
TextureProxyView(TextureProxyView&& view) = default; |
| 38 |
TextureProxyView(const TextureProxyView&) = default; |
| 39 |
|
| 40 |
explicit operator bool() const { return SkToBool(fProxy.get()); } |
| 41 |
|
| 42 |
TextureProxyView& operator=(const TextureProxyView&) = default; |
| 43 |
TextureProxyView& operator=(TextureProxyView&& view) = default; |
| 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 |
|
| 56 |
skgpu::Mipmapped mipmapped() const { |
| 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 |
|
| 69 |
void concatSwizzle(Swizzle swizzle) { |
| 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 |
| 74 |
TextureProxyView makeSwizzle(Swizzle swizzle) const & { |
| 75 |
return {fProxy, Swizzle::Concat(fSwizzle, swizzle), fOrigin}; |
| 76 |
} |
| 77 |
|
| 78 |
TextureProxyView makeSwizzle(Swizzle swizzle) && { |
| 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. |
| 83 |
TextureProxyView replaceSwizzle(Swizzle swizzle) const { |
| 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. |
| 93 |
sk_sp<TextureProxy> detachProxy() { |
| 94 |
return std::move(fProxy); |
| 95 |
} |
| 96 |
|
| 97 |
private: |
| 98 |
sk_sp<TextureProxy> fProxy; |
| 99 |
Swizzle fSwizzle; |
| 100 |
Origin fOrigin = Origin::kTopLeft; |
| 101 |
}; |
| 102 |
|
| 103 |
} // namespace skgpu::graphite |
| 104 |
|
| 105 |
#endif // skgpu_graphite_TextureProxyView_DEFINED |