OLD | NEW |
| (Empty) |
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 "GrDrawTarget.h" | |
11 #include "GrGpuResourcePriv.h" | |
12 #include "GrRenderTargetPriv.h" | |
13 | |
14 GrRenderTargetProxy::GrRenderTargetProxy(sk_sp<GrRenderTarget> rt) | |
15 : INHERITED(rt->desc(), SkBackingFit::kExact, rt->resourcePriv().isBudgeted(
)) | |
16 , fTarget(std::move(rt)) | |
17 , fSampleConfig(fTarget->renderTargetPriv().sampleConfig()) | |
18 , fLastDrawTarget(nullptr) { | |
19 } | |
20 | |
21 GrRenderTargetProxy::~GrRenderTargetProxy() { | |
22 if (fLastDrawTarget) { | |
23 fLastDrawTarget->clearRT(); | |
24 } | |
25 SkSafeUnref(fLastDrawTarget); | |
26 } | |
27 | |
28 GrRenderTarget* GrRenderTargetProxy::instantiate(GrTextureProvider* texProvider)
{ | |
29 if (fTarget) { | |
30 return fTarget.get(); | |
31 } | |
32 | |
33 // TODO: it would be nice to not have to copy the desc here | |
34 GrSurfaceDesc desc = fDesc; | |
35 desc.fFlags |= GrSurfaceFlags::kRenderTarget_GrSurfaceFlag; | |
36 | |
37 sk_sp<GrTexture> tex; | |
38 if (SkBackingFit::kApprox == fFit) { | |
39 tex.reset(texProvider->createApproxTexture(desc)); | |
40 } else { | |
41 tex.reset(texProvider->createTexture(desc, fBudgeted)); | |
42 } | |
43 if (!tex || !tex->asRenderTarget()) { | |
44 return nullptr; | |
45 } | |
46 | |
47 fTarget.reset(tex->asRenderTarget()); | |
48 | |
49 // Check that our a priori computation matched the ultimate reality | |
50 SkASSERT(fSampleConfig == fTarget->renderTargetPriv().sampleConfig()); | |
51 | |
52 return fTarget.get(); | |
53 } | |
54 | |
55 void GrRenderTargetProxy::setLastDrawTarget(GrDrawTarget* dt) { | |
56 if (fLastDrawTarget) { | |
57 // The non-MDB world never closes so we can't check this condition | |
58 #ifdef ENABLE_MDB | |
59 SkASSERT(fLastDrawTarget->isClosed()); | |
60 #endif | |
61 fLastDrawTarget->clearRT(); | |
62 } | |
63 | |
64 SkRefCnt_SafeAssign(fLastDrawTarget, dt); | |
65 } | |
66 | |
67 sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(const GrCaps& caps, | |
68 const GrSurfaceDesc& desc, | |
69 SkBackingFit fit, | |
70 SkBudgeted budgeted) { | |
71 return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(caps, desc, fit, b
udgeted)); | |
72 } | |
73 | |
74 sk_sp<GrRenderTargetProxy> GrRenderTargetProxy::Make(sk_sp<GrRenderTarget> rt) { | |
75 return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(rt)); | |
76 } | |
77 | |
OLD | NEW |