blob: 96c233d2c6f8d9eb9d365dae9add2cff61338f7b [file] [log] [blame]
Greg Daniela83de582019-10-22 09:33:25 -04001/*
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 Daniel3912a4b2020-01-14 09:56:04 -050013#include "src/gpu/GrRenderTargetProxy.h"
Greg Daniela83de582019-10-22 09:33:25 -040014#include "src/gpu/GrSurfaceProxy.h"
15#include "src/gpu/GrSwizzle.h"
Greg Danielc52db712020-01-28 17:03:46 -050016#include "src/gpu/GrTextureProxy.h"
Greg Daniela83de582019-10-22 09:33:25 -040017
18class GrSurfaceProxyView {
19public:
Greg Daniel16f5c652019-10-29 11:26:01 -040020 GrSurfaceProxyView() = default;
21
Greg Daniela83de582019-10-22 09:33:25 -040022 GrSurfaceProxyView(sk_sp<GrSurfaceProxy> proxy, GrSurfaceOrigin origin, GrSwizzle swizzle)
23 : fProxy(proxy), fOrigin(origin), fSwizzle(swizzle) {}
24
Greg Daniel16f5c652019-10-29 11:26:01 -040025 // This entry point is used when we don't care about the origin or the swizzle.
26 GrSurfaceProxyView(sk_sp<GrSurfaceProxy> proxy)
27 : fProxy(proxy), fOrigin(kTopLeft_GrSurfaceOrigin) {}
Greg Daniela83de582019-10-22 09:33:25 -040028
Greg Daniel16f5c652019-10-29 11:26:01 -040029 GrSurfaceProxyView(GrSurfaceProxyView&& view) = default;
Greg Daniel549325c2019-10-30 16:19:20 -040030 GrSurfaceProxyView(const GrSurfaceProxyView&) = default;
Greg Daniel16f5c652019-10-29 11:26:01 -040031
Greg Daniel549325c2019-10-30 16:19:20 -040032 GrSurfaceProxyView& operator=(const GrSurfaceProxyView&) = default;
Greg Daniel16f5c652019-10-29 11:26:01 -040033
Greg Daniel549325c2019-10-30 16:19:20 -040034 bool operator==(const GrSurfaceProxyView& view) const {
35 return fProxy->uniqueID() == view.fProxy->uniqueID() &&
Greg Daniel16f5c652019-10-29 11:26:01 -040036 fOrigin == view.fOrigin &&
37 fSwizzle == view.fSwizzle;
38 }
Greg Daniel549325c2019-10-30 16:19:20 -040039 bool operator!=(const GrSurfaceProxyView& other) const { return !(*this == other); }
Greg Daniel16f5c652019-10-29 11:26:01 -040040
41 GrSurfaceProxy* proxy() const { return fProxy.get(); }
Greg Daniel3912a4b2020-01-14 09:56:04 -050042 sk_sp<GrSurfaceProxy> proxyRef() const { return fProxy; }
43
Greg Daniel524e28b2019-11-01 11:48:53 -040044 GrTextureProxy* asTextureProxy() const {
45 if (!fProxy) {
46 return nullptr;
47 }
48 return fProxy->asTextureProxy();
49 }
Greg Daniel9715b6c2019-12-10 15:03:10 -050050 sk_sp<GrTextureProxy> asTextureProxyRef() const {
Greg Daniel3912a4b2020-01-14 09:56:04 -050051 return sk_ref_sp<GrTextureProxy>(this->asTextureProxy());
Greg Daniel9715b6c2019-12-10 15:03:10 -050052 }
53
Greg Daniel524e28b2019-11-01 11:48:53 -040054 GrRenderTargetProxy* asRenderTargetProxy() const {
55 if (!fProxy) {
56 return nullptr;
57 }
58 return fProxy->asRenderTargetProxy();
59 }
Greg Daniela83de582019-10-22 09:33:25 -040060
Greg Daniel3912a4b2020-01-14 09:56:04 -050061 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() const {
62 return sk_ref_sp<GrRenderTargetProxy>(this->asRenderTargetProxy());
63 }
64
Greg Daniela83de582019-10-22 09:33:25 -040065 GrSurfaceOrigin origin() const { return fOrigin; }
Greg Daniel3912a4b2020-01-14 09:56:04 -050066 GrSwizzle swizzle() const { return fSwizzle; }
Greg Daniela83de582019-10-22 09:33:25 -040067
Greg Daniel16f5c652019-10-29 11:26:01 -040068 void reset() {
69 *this = {};
70 }
71
Greg Danielc52db712020-01-28 17:03:46 -050072 // This does not reset the origin or swizzle, so the View can still be used to access those
Michael Ludwigadb12e72019-12-04 16:19:18 -050073 // properties associated with the detached proxy.
74 sk_sp<GrSurfaceProxy> detachProxy() {
75 return std::move(fProxy);
76 }
77
Greg Daniela83de582019-10-22 09:33:25 -040078private:
79 sk_sp<GrSurfaceProxy> fProxy;
Greg Daniel16f5c652019-10-29 11:26:01 -040080 GrSurfaceOrigin fOrigin = kTopLeft_GrSurfaceOrigin;
Greg Daniela83de582019-10-22 09:33:25 -040081 GrSwizzle fSwizzle;
82};
83
84#endif
85