• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 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 
9 #ifndef GrGLRenderTarget_DEFINED
10 #define GrGLRenderTarget_DEFINED
11 
12 #include "include/core/SkScalar.h"
13 #include "include/gpu/GrBackendSurface.h"
14 #include "src/gpu/GrRenderTarget.h"
15 
16 class GrGLCaps;
17 class GrGLGpu;
18 class GrGLAttachment;
19 
20 class GrGLRenderTarget : public GrRenderTarget {
21 public:
22     using GrSurface::glRTFBOIDis0;
alwaysClearStencil()23     bool alwaysClearStencil() const override { return this->glRTFBOIDis0(); }
24 
25     // set fSingleSampleFBOID to this value to indicate that it is multisampled but
26     // Gr doesn't know how to resolve it.
27     enum { kUnresolvableFBOID = 0 };
28 
29     struct IDs {
30         GrGLuint                   fMultisampleFBOID;
31         GrBackendObjectOwnership   fRTFBOOwnership;
32         GrGLuint                   fSingleSampleFBOID;
33         GrGLuint                   fMSColorRenderbufferID;
34         int                        fTotalMemorySamplesPerPixel;
35     };
36 
37     static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*,
38                                                const SkISize&,
39                                                GrGLFormat,
40                                                int sampleCount,
41                                                const IDs&,
42                                                int stencilBits);
43 
singleSampleFBOID()44     GrGLuint singleSampleFBOID() const { return fSingleSampleFBOID; }
multisampleFBOID()45     GrGLuint multisampleFBOID() const { return fMultisampleFBOID; }
46 
47     GrBackendRenderTarget getBackendRenderTarget() const override;
48 
49     GrBackendFormat backendFormat() const override;
50 
51     bool canAttemptStencilAttachment(bool useMultisampleFBO) const override;
52 
53     // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
54     // components separately.
55     void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
56 
format()57     GrGLFormat format() const { return fRTFormat; }
58 
hasDynamicMSAAAttachment()59     bool hasDynamicMSAAAttachment() const { return SkToBool(fDynamicMSAAAttachment); }
60     bool ensureDynamicMSAAAttachment();
61 
62 protected:
63     // Constructor for subclasses.
64     GrGLRenderTarget(GrGLGpu*,
65                      const SkISize&,
66                      GrGLFormat,
67                      int sampleCount,
68                      const IDs&);
69 
70     void init(GrGLFormat, const IDs&);
71 
72     void onAbandon() override;
73     void onRelease() override;
74 
totalMemorySamplesPerPixel()75     int totalMemorySamplesPerPixel() const { return fTotalMemorySamplesPerPixel; }
76 
77 private:
78     // Constructor for instances wrapping backend objects.
79     GrGLRenderTarget(
80             GrGLGpu*, const SkISize&, GrGLFormat, int sampleCount, const IDs&, GrGLAttachment*);
81 
82     void setFlags(const GrGLCaps&, const IDs&);
83 
84     GrGLGpu* getGLGpu() const;
85     bool completeStencilAttachment(GrAttachment* stencil, bool useMultisampleFBO) override;
86 
87     size_t onGpuMemorySize() const override;
88 
89     sk_sp<GrGLAttachment> fDynamicMSAAAttachment;
90 
91     GrGLuint    fMultisampleFBOID;
92     GrGLuint    fSingleSampleFBOID;
93     GrGLuint    fMSColorRenderbufferID;
94     GrGLFormat  fRTFormat;
95 
96     GrBackendObjectOwnership fRTFBOOwnership;
97 
98     // The RenderTarget needs to be able to report its VRAM footprint even after abandon and
99     // release have potentially zeroed out the IDs (e.g., so the cache can reset itself). Since
100     // the IDs are just required for the computation in totalSamples we cache that result here.
101     int fTotalMemorySamplesPerPixel;
102 
103     using INHERITED = GrRenderTarget;
104 };
105 
106 #endif
107