blob: 7608736c97f05a48917bb2c979dda660095e68e9 [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"
16
17class GrSurfaceProxyView {
18public:
Greg Daniel16f5c652019-10-29 11:26:01 -040019 GrSurfaceProxyView() = default;
20
Greg Daniela83de582019-10-22 09:33:25 -040021 GrSurfaceProxyView(sk_sp<GrSurfaceProxy> proxy, GrSurfaceOrigin origin, GrSwizzle swizzle)
22 : fProxy(proxy), fOrigin(origin), fSwizzle(swizzle) {}
23
Greg Daniel16f5c652019-10-29 11:26:01 -040024 // 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 Daniela83de582019-10-22 09:33:25 -040027
Greg Daniel16f5c652019-10-29 11:26:01 -040028 GrSurfaceProxyView(GrSurfaceProxyView&& view) = default;
Greg Daniel549325c2019-10-30 16:19:20 -040029 GrSurfaceProxyView(const GrSurfaceProxyView&) = default;
Greg Daniel16f5c652019-10-29 11:26:01 -040030
Greg Daniel549325c2019-10-30 16:19:20 -040031 GrSurfaceProxyView& operator=(const GrSurfaceProxyView&) = default;
Greg Daniel16f5c652019-10-29 11:26:01 -040032
Greg Daniel549325c2019-10-30 16:19:20 -040033 bool operator==(const GrSurfaceProxyView& view) const {
34 return fProxy->uniqueID() == view.fProxy->uniqueID() &&
Greg Daniel16f5c652019-10-29 11:26:01 -040035 fOrigin == view.fOrigin &&
36 fSwizzle == view.fSwizzle;
37 }
Greg Daniel549325c2019-10-30 16:19:20 -040038 bool operator!=(const GrSurfaceProxyView& other) const { return !(*this == other); }
Greg Daniel16f5c652019-10-29 11:26:01 -040039
40 GrSurfaceProxy* proxy() const { return fProxy.get(); }
Greg Daniel3912a4b2020-01-14 09:56:04 -050041 sk_sp<GrSurfaceProxy> proxyRef() const { return fProxy; }
42
Greg Daniel524e28b2019-11-01 11:48:53 -040043 GrTextureProxy* asTextureProxy() const {
44 if (!fProxy) {
45 return nullptr;
46 }
47 return fProxy->asTextureProxy();
48 }
Greg Daniel9715b6c2019-12-10 15:03:10 -050049 sk_sp<GrTextureProxy> asTextureProxyRef() const {
Greg Daniel3912a4b2020-01-14 09:56:04 -050050 return sk_ref_sp<GrTextureProxy>(this->asTextureProxy());
Greg Daniel9715b6c2019-12-10 15:03:10 -050051 }
52
Greg Daniel524e28b2019-11-01 11:48:53 -040053 GrRenderTargetProxy* asRenderTargetProxy() const {
54 if (!fProxy) {
55 return nullptr;
56 }
57 return fProxy->asRenderTargetProxy();
58 }
Greg Daniela83de582019-10-22 09:33:25 -040059
Greg Daniel3912a4b2020-01-14 09:56:04 -050060 sk_sp<GrRenderTargetProxy> asRenderTargetProxyRef() const {
61 return sk_ref_sp<GrRenderTargetProxy>(this->asRenderTargetProxy());
62 }
63
Greg Daniela83de582019-10-22 09:33:25 -040064 GrSurfaceOrigin origin() const { return fOrigin; }
Greg Daniel3912a4b2020-01-14 09:56:04 -050065 GrSwizzle swizzle() const { return fSwizzle; }
Greg Daniela83de582019-10-22 09:33:25 -040066
Greg Daniel16f5c652019-10-29 11:26:01 -040067 void reset() {
68 *this = {};
69 }
70
Michael Ludwigadb12e72019-12-04 16:19:18 -050071 // 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 Daniela83de582019-10-22 09:33:25 -040077private:
78 sk_sp<GrSurfaceProxy> fProxy;
Greg Daniel16f5c652019-10-29 11:26:01 -040079 GrSurfaceOrigin fOrigin = kTopLeft_GrSurfaceOrigin;
Greg Daniela83de582019-10-22 09:33:25 -040080 GrSwizzle fSwizzle;
81};
82
83#endif
84