OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrRenderTargetProxy_DEFINED | 8 #ifndef GrRenderTargetProxy_DEFINED |
9 #define GrRenderTargetProxy_DEFINED | 9 #define GrRenderTargetProxy_DEFINED |
10 | 10 |
11 #include "GrRenderTarget.h" | 11 #include "GrRenderTarget.h" |
| 12 #include "GrRenderTargetPriv.h" |
12 #include "GrSurfaceProxy.h" | 13 #include "GrSurfaceProxy.h" |
13 #include "GrTypes.h" | 14 #include "GrTypes.h" |
14 | 15 |
15 class GrTextureProvider; | 16 class GrTextureProvider; |
16 | 17 |
17 // This class delays the acquisition of RenderTargets until they are actually | 18 // This class delays the acquisition of RenderTargets until they are actually |
18 // required | 19 // required |
19 // Beware: the uniqueID of the RenderTargetProxy will usually be different than | 20 // Beware: the uniqueID of the RenderTargetProxy will usually be different than |
20 // the uniqueID of the RenderTarget it represents! | 21 // the uniqueID of the RenderTarget it represents! |
21 class GrRenderTargetProxy : public GrSurfaceProxy { | 22 class GrRenderTargetProxy : public GrSurfaceProxy { |
22 public: | 23 public: |
23 /** | 24 /** |
24 * The caller gets the creation ref. | 25 * The caller gets the creation ref. |
25 */ | 26 */ |
26 static sk_sp<GrRenderTargetProxy> Make(const GrCaps&, const GrSurfaceDesc&, | 27 static sk_sp<GrRenderTargetProxy> Make(const GrCaps&, const GrSurfaceDesc&, |
27 SkBackingFit, SkBudgeted); | 28 SkBackingFit, SkBudgeted); |
28 static sk_sp<GrRenderTargetProxy> Make(sk_sp<GrRenderTarget> rt); | 29 static sk_sp<GrRenderTargetProxy> Make(const GrCaps&, sk_sp<GrRenderTarget>)
; |
29 | 30 |
30 ~GrRenderTargetProxy() override; | 31 ~GrRenderTargetProxy() override; |
31 | 32 |
32 // TODO: add asTextureProxy variants | 33 // TODO: add asTextureProxy variants |
33 GrRenderTargetProxy* asRenderTargetProxy() override { return this; } | 34 GrRenderTargetProxy* asRenderTargetProxy() override { return this; } |
34 const GrRenderTargetProxy* asRenderTargetProxy() const override { return thi
s; } | 35 const GrRenderTargetProxy* asRenderTargetProxy() const override { return thi
s; } |
35 | 36 |
36 // Actually instantiate the backing rendertarget, if necessary. | 37 // Actually instantiate the backing rendertarget, if necessary. |
37 GrRenderTarget* instantiate(GrTextureProvider* texProvider); | 38 GrRenderTarget* instantiate(GrTextureProvider* texProvider); |
38 | 39 |
39 /** | 40 bool isStencilBufferMultisampled() const { return fDesc.fSampleCnt > 0; } |
40 * @return true if the surface is multisampled in all buffers, | |
41 * false otherwise | |
42 */ | |
43 bool isUnifiedMultisampled() const { | |
44 if (fSampleConfig != GrRenderTarget::kUnified_SampleConfig) { | |
45 return false; | |
46 } | |
47 return 0 != fDesc.fSampleCnt; | |
48 } | |
49 | 41 |
50 /** | 42 /** |
51 * @return true if the surface is multisampled in the stencil buffer, | 43 * For our purposes, "Mixed Sampled" means the stencil buffer is multisample
d but the color |
52 * false otherwise | 44 * buffer is not. |
53 */ | 45 */ |
54 bool isStencilBufferMultisampled() const { | 46 bool isMixedSampled() const { return fFlags & GrRenderTargetPriv::Flags::kMi
xedSampled; } |
55 return 0 != fDesc.fSampleCnt; | |
56 } | |
57 | 47 |
58 /** | 48 /** |
59 * @return the number of color samples-per-pixel, or zero if non-MSAA or | 49 * "Unified Sampled" means the stencil and color buffers are both multisampl
ed. |
60 * multisampled in the stencil buffer only. | |
61 */ | 50 */ |
62 int numColorSamples() const { | 51 bool isUnifiedMultisampled() const { return fDesc.fSampleCnt > 0 && !this->i
sMixedSampled(); } |
63 if (fSampleConfig == GrRenderTarget::kUnified_SampleConfig) { | |
64 return fDesc.fSampleCnt; | |
65 } | |
66 return 0; | |
67 } | |
68 | 52 |
69 /** | 53 /** |
70 * @return the number of stencil samples-per-pixel, or zero if non-MSAA. | 54 * Returns the number of samples/pixel in the stencil buffer (Zero if non-MS
AA). |
71 */ | 55 */ |
72 int numStencilSamples() const { | 56 int numStencilSamples() const { return fDesc.fSampleCnt; } |
73 return fDesc.fSampleCnt; | |
74 } | |
75 | 57 |
76 /** | 58 /** |
77 * @return true if the surface is mixed sampled, false otherwise. | 59 * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA
or mixed sampled). |
78 */ | 60 */ |
79 bool hasMixedSamples() const { | 61 int numColorSamples() const { return this->isMixedSampled() ? 0 : fDesc.fSam
pleCnt; } |
80 SkASSERT(GrRenderTarget::kStencil_SampleConfig != fSampleConfig || | |
81 this->isStencilBufferMultisampled()); | |
82 return GrRenderTarget::kStencil_SampleConfig == fSampleConfig; | |
83 } | |
84 | 62 |
85 void setLastDrawTarget(GrDrawTarget* dt); | 63 void setLastDrawTarget(GrDrawTarget* dt); |
86 GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; } | 64 GrDrawTarget* getLastDrawTarget() { return fLastDrawTarget; } |
87 | 65 |
| 66 GrRenderTargetPriv::Flags testingOnly_getFlags() const; |
| 67 |
88 private: | 68 private: |
89 // TODO: we can probably munge the 'desc' in both the wrapped and deferred | 69 // Deferred version |
90 // cases to make the sampleConfig/numSamples stuff more rational. | 70 GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&, SkBackingFit, SkBud
geted); |
91 GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc& desc, | |
92 SkBackingFit fit, SkBudgeted budgeted) | |
93 : INHERITED(desc, fit, budgeted) | |
94 , fTarget(nullptr) | |
95 , fSampleConfig(GrRenderTarget::ComputeSampleConfig(caps, desc.fSampleCn
t)) | |
96 , fLastDrawTarget(nullptr) { | |
97 } | |
98 | 71 |
99 // Wrapped version | 72 // Wrapped version |
100 GrRenderTargetProxy(sk_sp<GrRenderTarget> rt); | 73 GrRenderTargetProxy(const GrCaps&, sk_sp<GrRenderTarget> rt); |
101 | 74 |
102 // For wrapped render targets we store it here. | 75 // For wrapped render targets we store it here. |
103 // For deferred proxies we will fill this in when we need to instantiate the
deferred resource | 76 // For deferred proxies we will fill this in when we need to instantiate the
deferred resource |
104 sk_sp<GrRenderTarget> fTarget; | 77 sk_sp<GrRenderTarget> fTarget; |
105 | 78 |
106 // The sample config doesn't usually get computed until the render target is
instantiated but | 79 // These don't usually get computed until the render target is instantiated,
but the render |
107 // the render target proxy may need to answer queries about it before then.
For this reason | 80 // target proxy may need to answer queries about it before then. And since i
n the deferred case |
108 // we precompute it in the deferred case. In the wrapped case we just copy t
he wrapped | 81 // we know the newly created render target will be internal, we are able to
precompute what the |
| 82 // flags will ultimately end up being. In the wrapped case we just copy the
wrapped |
109 // rendertarget's info here. | 83 // rendertarget's info here. |
110 GrRenderTarget::SampleConfig fSampleConfig; | 84 GrRenderTargetPriv::Flags fFlags; |
111 | 85 |
112 // The last drawTarget that wrote to or is currently going to write to this
renderTarget | 86 // The last drawTarget that wrote to or is currently going to write to this
renderTarget |
113 // The drawTarget can be closed (e.g., no draw context is currently bound | 87 // The drawTarget can be closed (e.g., no draw context is currently bound |
114 // to this renderTarget). | 88 // to this renderTarget). |
115 // This back-pointer is required so that we can add a dependancy between | 89 // This back-pointer is required so that we can add a dependancy between |
116 // the drawTarget used to create the current contents of this renderTarget | 90 // the drawTarget used to create the current contents of this renderTarget |
117 // and the drawTarget of a destination renderTarget to which this one is bei
ng drawn. | 91 // and the drawTarget of a destination renderTarget to which this one is bei
ng drawn. |
118 GrDrawTarget* fLastDrawTarget; | 92 GrDrawTarget* fLastDrawTarget; |
119 | 93 |
120 typedef GrSurfaceProxy INHERITED; | 94 typedef GrSurfaceProxy INHERITED; |
121 }; | 95 }; |
122 | 96 |
123 #endif | 97 #endif |
OLD | NEW |