1 /*
2 * Copyright 2016 Google Inc.
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 "GrRenderTargetProxy.h"
9
10 #include "GrCaps.h"
11 #include "GrGpuResourcePriv.h"
12 #include "GrRenderTargetOpList.h"
13 #include "GrRenderTargetPriv.h"
14 #include "GrResourceProvider.h"
15 #include "GrTextureRenderTargetProxy.h"
16
17 // Deferred version
18 // TODO: we can probably munge the 'desc' in both the wrapped and deferred
19 // cases to make the sampleConfig/numSamples stuff more rational.
GrRenderTargetProxy(const GrCaps & caps,const GrSurfaceDesc & desc,SkBackingFit fit,SkBudgeted budgeted,uint32_t flags)20 GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc,
21 SkBackingFit fit, SkBudgeted budgeted, uint32_t flags)
22 : INHERITED(desc, fit, budgeted, flags)
23 , fRenderTargetFlags(GrRenderTarget::Flags::kNone) {
24 // Since we know the newly created render target will be internal, we are able to precompute
25 // what the flags will ultimately end up being.
26 if (caps.usesMixedSamples() && fDesc.fSampleCnt > 0) {
27 fRenderTargetFlags |= GrRenderTarget::Flags::kMixedSampled;
28 }
29 if (caps.maxWindowRectangles() > 0) {
30 fRenderTargetFlags |= GrRenderTarget::Flags::kWindowRectsSupport;
31 }
32 }
33
34 // Wrapped version
GrRenderTargetProxy(sk_sp<GrSurface> surf)35 GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrSurface> surf)
36 : INHERITED(std::move(surf), SkBackingFit::kExact)
37 , fRenderTargetFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) {
38 }
39
maxWindowRectangles(const GrCaps & caps) const40 int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const {
41 return (fRenderTargetFlags & GrRenderTarget::Flags::kWindowRectsSupport)
42 ? caps.maxWindowRectangles()
43 : 0;
44 }
45
instantiate(GrResourceProvider * resourceProvider)46 GrRenderTarget* GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) {
47 SkASSERT(fDesc.fFlags & GrSurfaceFlags::kRenderTarget_GrSurfaceFlag);
48
49 GrSurface* surf = INHERITED::instantiate(resourceProvider);
50 if (!surf || !surf->asRenderTarget()) {
51 return nullptr;
52 }
53
54 // Check that our a priori computation matched the ultimate reality
55 SkASSERT(fRenderTargetFlags == surf->asRenderTarget()->renderTargetPriv().flags());
56
57 return surf->asRenderTarget();
58 }
59
onGpuMemorySize() const60 size_t GrRenderTargetProxy::onGpuMemorySize() const {
61 if (fTarget) {
62 return fTarget->gpuMemorySize();
63 }
64
65 // TODO: do we have enough information to improve this worst case estimate?
66 return GrSurface::ComputeSize(fDesc, fDesc.fSampleCnt+1, false, SkBackingFit::kApprox == fFit);
67 }
68
refsWrappedObjects() const69 bool GrRenderTargetProxy::refsWrappedObjects() const {
70 if (!fTarget) {
71 return false;
72 }
73
74 return fTarget->resourcePriv().refsWrappedObjects();
75 }
76