Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 GrSurfaceProxyView_DEFINED |
| 9 | #define GrSurfaceProxyView_DEFINED |
| 10 | |
| 11 | #include "include/core/SkRefCnt.h" |
| 12 | #include "include/gpu/GrTypes.h" |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrRenderTargetProxy.h" |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 14 | #include "src/gpu/GrSurfaceProxy.h" |
| 15 | #include "src/gpu/GrSwizzle.h" |
| 16 | |
| 17 | class GrSurfaceProxyView { |
| 18 | public: |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 19 | GrSurfaceProxyView() = default; |
| 20 | |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 21 | GrSurfaceProxyView(sk_sp<GrSurfaceProxy> proxy, GrSurfaceOrigin origin, GrSwizzle swizzle) |
| 22 | : fProxy(proxy), fOrigin(origin), fSwizzle(swizzle) {} |
| 23 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 24 | // This entry point is used when we don't care about the origin or the swizzle. |
| 25 | GrSurfaceProxyView(sk_sp<GrSurfaceProxy> proxy) |
| 26 | : fProxy(proxy), fOrigin(kTopLeft_GrSurfaceOrigin) {} |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 27 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 28 | GrSurfaceProxyView(GrSurfaceProxyView&& view) = default; |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 29 | GrSurfaceProxyView(const GrSurfaceProxyView&) = default; |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 30 | |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 31 | GrSurfaceProxyView& operator=(const GrSurfaceProxyView&) = default; |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 32 | |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 33 | bool operator==(const GrSurfaceProxyView& view) const { |
| 34 | return fProxy->uniqueID() == view.fProxy->uniqueID() && |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 35 | fOrigin == view.fOrigin && |
| 36 | fSwizzle == view.fSwizzle; |
| 37 | } |
Greg Daniel | 549325c | 2019-10-30 16:19:20 -0400 | [diff] [blame] | 38 | bool operator!=(const GrSurfaceProxyView& other) const { return !(*this == other); } |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 39 | |
| 40 | GrSurfaceProxy* proxy() const { return fProxy.get(); } |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 41 | sk_sp<GrSurfaceProxy> proxyRef() const { return fProxy; } |
| 42 | |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 43 | GrTextureProxy* asTextureProxy() const { |
| 44 | if (!fProxy) { |
| 45 | return nullptr; |
| 46 | } |
| 47 | return fProxy->asTextureProxy(); |
| 48 | } |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 49 | sk_sp<GrTextureProxy> asTextureProxyRef() const { |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 50 | return sk_ref_sp<GrTextureProxy>(this->asTextureProxy()); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Greg Daniel | 524e28b | 2019-11-01 11:48:53 -0400 | [diff] [blame] | 53 | GrRenderTargetProxy* asRenderTargetProxy() const { |
| 54 | if (!fProxy) { |
| 55 | return nullptr; |
| 56 | } |
| 57 | return fProxy->asRenderTargetProxy(); |
| 58 | } |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 59 | |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 60 | sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() const { |
| 61 | return sk_ref_sp<GrRenderTargetProxy>(this->asRenderTargetProxy()); |
| 62 | } |
| 63 | |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 64 | GrSurfaceOrigin origin() const { return fOrigin; } |
Greg Daniel | 3912a4b | 2020-01-14 09:56:04 -0500 | [diff] [blame] | 65 | GrSwizzle swizzle() const { return fSwizzle; } |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 66 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 67 | void reset() { |
| 68 | *this = {}; |
| 69 | } |
| 70 | |
Michael Ludwig | adb12e7 | 2019-12-04 16:19:18 -0500 | [diff] [blame] | 71 | // This does not reset the origin or proxy, so the View can still be used to access those |
| 72 | // properties associated with the detached proxy. |
| 73 | sk_sp<GrSurfaceProxy> detachProxy() { |
| 74 | return std::move(fProxy); |
| 75 | } |
| 76 | |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 77 | private: |
| 78 | sk_sp<GrSurfaceProxy> fProxy; |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 79 | GrSurfaceOrigin fOrigin = kTopLeft_GrSurfaceOrigin; |
Greg Daniel | a83de58 | 2019-10-22 09:33:25 -0400 | [diff] [blame] | 80 | GrSwizzle fSwizzle; |
| 81 | }; |
| 82 | |
| 83 | #endif |
| 84 | |