blob: 419c11760b96163a43f8d4735d116f43b765b9e1 [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 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