blob: 1649e12c792016f5fce90d9f2bde5265afcc4c93 [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;
28 GrSurfaceProxyView(const GrSurfaceProxyView&) = delete;
29
30 GrSurfaceProxyView& operator=(const GrSurfaceProxyView& that) = default;
31
32 bool operator==(const GrSurfaceProxyView& view) {
33 return fProxy.get() == view.fProxy.get() &&
34 fOrigin == view.fOrigin &&
35 fSwizzle == view.fSwizzle;
36 }
37 bool operator!=(const GrSurfaceProxyView& other) { return !(*this == other); }
38
39 GrSurfaceProxy* proxy() const { return fProxy.get(); }
Greg Daniela83de582019-10-22 09:33:25 -040040 GrTextureProxy* asTextureProxy() const { return fProxy->asTextureProxy(); }
41 GrRenderTargetProxy* asRenderTargetProxy() const { return fProxy->asRenderTargetProxy(); }
42
43 GrSurfaceOrigin origin() const { return fOrigin; }
44 const GrSwizzle& swizzle() const { return fSwizzle; }
45
Greg Daniel16f5c652019-10-29 11:26:01 -040046 void reset() {
47 *this = {};
48 }
49
Greg Daniela83de582019-10-22 09:33:25 -040050private:
51 sk_sp<GrSurfaceProxy> fProxy;
Greg Daniel16f5c652019-10-29 11:26:01 -040052 GrSurfaceOrigin fOrigin = kTopLeft_GrSurfaceOrigin;
Greg Daniela83de582019-10-22 09:33:25 -040053 GrSwizzle fSwizzle;
54};
55
56#endif
57