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