1 /*
2 * Copyright 2022 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 #include "src/gpu/ganesh/GrSurfaceProxyView.h"
9
10 #include "include/core/SkRect.h"
11 #include "include/gpu/GpuTypes.h"
12 #include "src/gpu/ganesh/GrRenderTargetProxy.h"
13 #include "src/gpu/ganesh/GrTextureProxy.h"
14
operator ==(const GrSurfaceProxyView & view) const15 bool GrSurfaceProxyView::operator==(const GrSurfaceProxyView& view) const {
16 return fProxy->uniqueID() == view.fProxy->uniqueID() && fOrigin == view.fOrigin &&
17 fSwizzle == view.fSwizzle;
18 }
19
mipmapped() const20 skgpu::Mipmapped GrSurfaceProxyView::mipmapped() const {
21 if (const GrTextureProxy* proxy = this->asTextureProxy()) {
22 return proxy->mipmapped();
23 }
24 return skgpu::Mipmapped::kNo;
25 }
26
asTextureProxy() const27 GrTextureProxy* GrSurfaceProxyView::asTextureProxy() const {
28 if (!fProxy) {
29 return nullptr;
30 }
31 return fProxy->asTextureProxy();
32 }
33
asTextureProxyRef() const34 sk_sp<GrTextureProxy> GrSurfaceProxyView::asTextureProxyRef() const {
35 return sk_ref_sp<GrTextureProxy>(this->asTextureProxy());
36 }
37
asRenderTargetProxy() const38 GrRenderTargetProxy* GrSurfaceProxyView::asRenderTargetProxy() const {
39 if (!fProxy) {
40 return nullptr;
41 }
42 return fProxy->asRenderTargetProxy();
43 }
44
asRenderTargetProxyRef() const45 sk_sp<GrRenderTargetProxy> GrSurfaceProxyView::asRenderTargetProxyRef() const {
46 return sk_ref_sp<GrRenderTargetProxy>(this->asRenderTargetProxy());
47 }
48
concatSwizzle(skgpu::Swizzle swizzle)49 void GrSurfaceProxyView::concatSwizzle(skgpu::Swizzle swizzle) {
50 fSwizzle = skgpu::Swizzle::Concat(fSwizzle, swizzle);
51 }
52
makeSwizzle(skgpu::Swizzle swizzle) const53 GrSurfaceProxyView GrSurfaceProxyView::makeSwizzle(skgpu::Swizzle swizzle) const& {
54 return {fProxy, fOrigin, skgpu::Swizzle::Concat(fSwizzle, swizzle)};
55 }
56
makeSwizzle(skgpu::Swizzle swizzle)57 GrSurfaceProxyView GrSurfaceProxyView::makeSwizzle(skgpu::Swizzle swizzle) && {
58 return {std::move(fProxy), fOrigin, skgpu::Swizzle::Concat(fSwizzle, swizzle)};
59 }
60
reset()61 void GrSurfaceProxyView::reset() { *this = {}; }
62
Copy(GrRecordingContext * context,GrSurfaceProxyView src,skgpu::Mipmapped mipmapped,SkIRect srcRect,SkBackingFit fit,skgpu::Budgeted budgeted,std::string_view label)63 GrSurfaceProxyView GrSurfaceProxyView::Copy(GrRecordingContext* context,
64 GrSurfaceProxyView src,
65 skgpu::Mipmapped mipmapped,
66 SkIRect srcRect,
67 SkBackingFit fit,
68 skgpu::Budgeted budgeted,
69 std::string_view label) {
70 auto copy = GrSurfaceProxy::Copy(
71 context, src.refProxy(), src.origin(), mipmapped, srcRect, fit, budgeted, label);
72 return {std::move(copy), src.origin(), src.swizzle()};
73 }
74
Copy(GrRecordingContext * rContext,GrSurfaceProxyView src,skgpu::Mipmapped mipmapped,SkBackingFit fit,skgpu::Budgeted budgeted,std::string_view label)75 GrSurfaceProxyView GrSurfaceProxyView::Copy(GrRecordingContext* rContext,
76 GrSurfaceProxyView src,
77 skgpu::Mipmapped mipmapped,
78 SkBackingFit fit,
79 skgpu::Budgeted budgeted,
80 std::string_view label) {
81 auto copy = GrSurfaceProxy::Copy(
82 rContext, src.refProxy(), src.origin(), mipmapped, fit, budgeted, label);
83 return {std::move(copy), src.origin(), src.swizzle()};
84 }
85