blob: 78ea8e99b8d9f3c49ab1f5f933496e0954c6542e [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"
13#include "src/gpu/GrSurfaceProxy.h"
14#include "src/gpu/GrSwizzle.h"
15
16class GrSurfaceProxyView {
17public:
Greg Daniel16f5c652019-10-29 11:26:01 -040018 GrSurfaceProxyView() = default;
19
Greg Daniela83de582019-10-22 09:33:25 -040020 GrSurfaceProxyView(sk_sp<GrSurfaceProxy> proxy, GrSurfaceOrigin origin, GrSwizzle swizzle)
21 : fProxy(proxy), fOrigin(origin), fSwizzle(swizzle) {}
22
Greg Daniel16f5c652019-10-29 11:26:01 -040023 // 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 Daniela83de582019-10-22 09:33:25 -040026
Greg Daniel16f5c652019-10-29 11:26:01 -040027 GrSurfaceProxyView(GrSurfaceProxyView&& view) = default;
Greg Daniel549325c2019-10-30 16:19:20 -040028 GrSurfaceProxyView(const GrSurfaceProxyView&) = default;
Greg Daniel16f5c652019-10-29 11:26:01 -040029
Greg Daniel549325c2019-10-30 16:19:20 -040030 GrSurfaceProxyView& operator=(const GrSurfaceProxyView&) = default;
Greg Daniel16f5c652019-10-29 11:26:01 -040031
Greg Daniel549325c2019-10-30 16:19:20 -040032 bool operator==(const GrSurfaceProxyView& view) const {
33 return fProxy->uniqueID() == view.fProxy->uniqueID() &&
Greg Daniel16f5c652019-10-29 11:26:01 -040034 fOrigin == view.fOrigin &&
35 fSwizzle == view.fSwizzle;
36 }
Greg Daniel549325c2019-10-30 16:19:20 -040037 bool operator!=(const GrSurfaceProxyView& other) const { return !(*this == other); }
Greg Daniel16f5c652019-10-29 11:26:01 -040038
39 GrSurfaceProxy* proxy() const { return fProxy.get(); }
Greg Daniel524e28b2019-11-01 11:48:53 -040040 GrTextureProxy* asTextureProxy() const {
41 if (!fProxy) {
42 return nullptr;
43 }
44 return fProxy->asTextureProxy();
45 }
Greg Daniel9715b6c2019-12-10 15:03:10 -050046 sk_sp<GrTextureProxy> asTextureProxyRef() const {
47 if (!fProxy) {
48 return nullptr;
49 }
50 return sk_ref_sp<GrTextureProxy>(fProxy->asTextureProxy());
51 }
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
60 GrSurfaceOrigin origin() const { return fOrigin; }
61 const GrSwizzle& swizzle() const { return fSwizzle; }
62
Greg Daniel16f5c652019-10-29 11:26:01 -040063 void reset() {
64 *this = {};
65 }
66
Michael Ludwigadb12e72019-12-04 16:19:18 -050067 // 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 Daniela83de582019-10-22 09:33:25 -040073private:
74 sk_sp<GrSurfaceProxy> fProxy;
Greg Daniel16f5c652019-10-29 11:26:01 -040075 GrSurfaceOrigin fOrigin = kTopLeft_GrSurfaceOrigin;
Greg Daniela83de582019-10-22 09:33:25 -040076 GrSwizzle fSwizzle;
77};
78
79#endif
80