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