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