• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef GrRenderTargetProxy_DEFINED
9 #define GrRenderTargetProxy_DEFINED
10 
11 #include "GrSurfaceProxy.h"
12 #include "GrTypesPriv.h"
13 
14 class GrResourceProvider;
15 
16 // This class delays the acquisition of RenderTargets until they are actually
17 // required
18 // Beware: the uniqueID of the RenderTargetProxy will usually be different than
19 // the uniqueID of the RenderTarget it represents!
20 class GrRenderTargetProxy : virtual public GrSurfaceProxy {
21 public:
asRenderTargetProxy()22     GrRenderTargetProxy* asRenderTargetProxy() override { return this; }
asRenderTargetProxy()23     const GrRenderTargetProxy* asRenderTargetProxy() const override { return this; }
24 
25     // Actually instantiate the backing rendertarget, if necessary.
26     bool instantiate(GrResourceProvider*) override;
27 
fsaaType()28     GrFSAAType fsaaType() const {
29         if (fSampleCnt <= 1) {
30             SkASSERT(!(fRenderTargetFlags & GrRenderTargetFlags::kMixedSampled));
31             return GrFSAAType::kNone;
32         }
33         return (fRenderTargetFlags & GrRenderTargetFlags::kMixedSampled)
34                                                              ? GrFSAAType::kMixedSamples
35                                                              : GrFSAAType::kUnifiedMSAA;
36     }
37 
38     /*
39      * When instantiated does this proxy require a stencil buffer?
40      */
setNeedsStencil()41     void setNeedsStencil() { fNeedsStencil = true; }
needsStencil()42     bool needsStencil() const { return fNeedsStencil; }
43 
44     /**
45      * Returns the number of samples/pixel in the stencil buffer (Zero if non-MSAA).
46      */
numStencilSamples()47     int numStencilSamples() const { return fSampleCnt; }
48 
49     /**
50      * Returns the number of samples/pixel in the color buffer (Zero if non-MSAA or mixed sampled).
51      */
numColorSamples()52     int numColorSamples() const {
53         return GrFSAAType::kMixedSamples == this->fsaaType() ? 1 : fSampleCnt;
54     }
55 
56     int maxWindowRectangles(const GrCaps& caps) const;
57 
58     GrRenderTargetFlags testingOnly_getFlags() const;
59 
60     // TODO: move this to a priv class!
61     bool refsWrappedObjects() const;
62 
63 protected:
64     friend class GrProxyProvider;  // for ctors
65 
66     // Deferred version
67     GrRenderTargetProxy(const GrCaps&, const GrSurfaceDesc&,
68                         SkBackingFit, SkBudgeted, uint32_t flags);
69 
70     // Lazy-callback version
71     // There are two main use cases for lazily-instantiated proxies:
72     //   basic knowledge - width, height, config, samples, origin are known
73     //   minimal knowledge - only config is known.
74     //
75     // The basic knowledge version is used for DDL where we know the type of proxy we are going to
76     // use, but we don't have access to the GPU yet to instantiate it.
77     //
78     // The minimal knowledge version is used for CCPR where we are generating an atlas but we do not
79     // know the final size until flush time.
80     GrRenderTargetProxy(LazyInstantiateCallback&&, const GrSurfaceDesc&, SkBackingFit, SkBudgeted,
81                         uint32_t flags);
82 
83     // Wrapped version
84     GrRenderTargetProxy(sk_sp<GrSurface>, GrSurfaceOrigin);
85 
86     sk_sp<GrSurface> createSurface(GrResourceProvider*) const override;
87 
88 private:
89     size_t onUninstantiatedGpuMemorySize() const override;
90     SkDEBUGCODE(void validateLazyTexture(const GrTexture*) override { SkASSERT(0); })
91 
92     int                 fSampleCnt;
93     bool                fNeedsStencil;
94 
95     // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
96     // For deferred proxies that pointer is filled in when we need to instantiate the
97     // deferred resource.
98 
99     // These don't usually get computed until the render target is instantiated, but the render
100     // target proxy may need to answer queries about it before then. And since in the deferred case
101     // we know the newly created render target will be internal, we are able to precompute what the
102     // flags will ultimately end up being. In the wrapped case we just copy the wrapped
103     // rendertarget's info here.
104     GrRenderTargetFlags fRenderTargetFlags;
105 
106     typedef GrSurfaceProxy INHERITED;
107 };
108 
109 #endif
110