• 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 #include "src/gpu/gl/GrGLIRect.h"
16 
17 class GrGLCaps;
18 class GrGLGpu;
19 class GrGLStencilAttachment;
20 
21 class GrGLRenderTarget : public GrRenderTarget {
22 public:
alwaysClearStencil()23     bool alwaysClearStencil() const override { return 0 == fRTFBOID; }
24 
25     // set fTexFBOID 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                   fRTFBOID;
31         GrBackendObjectOwnership   fRTFBOOwnership;
32         GrGLuint                   fTexFBOID;
33         GrGLuint                   fMSColorRenderbufferID;
34     };
35 
36     static sk_sp<GrGLRenderTarget> MakeWrapped(GrGLGpu*,
37                                                const SkISize&,
38                                                GrGLFormat,
39                                                GrPixelConfig,
40                                                int sampleCount,
41                                                const IDs&,
42                                                int stencilBits);
43 
44     // The following two functions return the same ID when a texture/render target is not
45     // multisampled, and different IDs when it is multisampled.
46     // FBO ID used to render into
renderFBOID()47     GrGLuint renderFBOID() const { return fRTFBOID; }
48     // FBO ID that has texture ID attached.
textureFBOID()49     GrGLuint textureFBOID() const { return fTexFBOID; }
50 
51     // override of GrRenderTarget
getResolveType()52     ResolveType getResolveType() const override {
53         if (this->numSamples() <= 1 || fRTFBOID == fTexFBOID) {  // Also catches FBO 0.
54             return kAutoResolves_ResolveType;
55         } else if (kUnresolvableFBOID == fTexFBOID) {
56             return kCantResolve_ResolveType;
57         } else {
58             return kCanResolve_ResolveType;
59         }
60     }
61 
62     GrBackendRenderTarget getBackendRenderTarget() const override;
63 
64     GrBackendFormat backendFormat() const override;
65 
66     bool canAttemptStencilAttachment() const override;
67 
68     // GrGLRenderTarget overrides dumpMemoryStatistics so it can log its texture and renderbuffer
69     // components seperately.
70     void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override;
71 
format()72     GrGLFormat format() const { return fRTFormat; }
73 
74 protected:
75     // Constructor for subclasses.
76     GrGLRenderTarget(GrGLGpu*,
77                      const SkISize&,
78                      GrGLFormat,
79                      GrPixelConfig,
80                      int sampleCount,
81                      const IDs&);
82 
83     void init(GrGLFormat, const IDs&);
84 
85     void onAbandon() override;
86     void onRelease() override;
87 
numSamplesOwnedPerPixel()88     int numSamplesOwnedPerPixel() const { return fNumSamplesOwnedPerPixel; }
89 
90 private:
91     // Constructor for instances wrapping backend objects.
92     GrGLRenderTarget(GrGLGpu*,
93                      const SkISize&,
94                      GrGLFormat,
95                      GrPixelConfig,
96                      int sampleCount,
97                      const IDs&,
98                      GrGLStencilAttachment*);
99 
100     void setFlags(const GrGLCaps&, const IDs&);
101 
102     GrGLGpu* getGLGpu() const;
103     bool completeStencilAttachment() override;
104 
105     size_t onGpuMemorySize() const override;
106 
107     int msaaSamples() const;
108     // The number total number of samples, including both MSAA and resolve texture samples.
109     int totalSamples() const;
110 
111     GrGLuint    fRTFBOID;
112     GrGLuint    fTexFBOID;
113     GrGLuint    fMSColorRenderbufferID;
114     GrGLFormat  fRTFormat;
115 
116     GrBackendObjectOwnership fRTFBOOwnership;
117 
118     // The RenderTarget needs to be able to report its VRAM footprint even after abandon and
119     // release have potentially zeroed out the IDs (e.g., so the cache can reset itself). Since
120     // the IDs are just required for the computation in totalSamples we cache that result here.
121     int         fNumSamplesOwnedPerPixel;
122 
123     typedef GrRenderTarget INHERITED;
124 };
125 
126 #endif
127