Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: src/gpu/gl/GrGLRenderTarget.cpp

Issue 1862043002: Refactor to separate backend object lifecycle and GpuResource budget decision (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix unrelated GrBuffer::onGpuMemorySize() lack of override keyword compile error Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/gl/GrGLRenderTarget.h ('k') | src/gpu/gl/GrGLStencilAttachment.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 #include "GrGLRenderTarget.h" 8 #include "GrGLRenderTarget.h"
9 9
10 #include "GrRenderTargetPriv.h"
11 #include "GrGLGpu.h" 10 #include "GrGLGpu.h"
12 #include "GrGLUtil.h" 11 #include "GrGLUtil.h"
12 #include "GrGpuResourcePriv.h"
13 #include "GrRenderTargetPriv.h"
13 #include "SkTraceMemoryDump.h" 14 #include "SkTraceMemoryDump.h"
14 15
15 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) 16 #define GPUGL static_cast<GrGLGpu*>(this->getGpu())
16 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) 17 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X)
17 18
18 // Because this class is virtually derived from GrSurface we must explicitly cal l its constructor. 19 // Because this class is virtually derived from GrSurface we must explicitly cal l its constructor.
20 // Constructor for wrapped render targets.
19 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, 21 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu,
20 const GrSurfaceDesc& desc, 22 const GrSurfaceDesc& desc,
21 const IDDesc& idDesc, 23 const IDDesc& idDesc,
22 GrGLStencilAttachment* stencil) 24 GrGLStencilAttachment* stencil)
23 : GrSurface(gpu, idDesc.fLifeCycle, desc) 25 : GrSurface(gpu, desc)
24 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig, stencil) { 26 , INHERITED(gpu, desc, idDesc.fSampleConfig, stencil) {
25 this->init(desc, idDesc); 27 this->init(desc, idDesc);
26 this->registerWithCache(); 28 this->registerWithCacheWrapped();
27 } 29 }
28 30
29 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, cons t IDDesc& idDesc, 31 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc,
30 Derived) 32 const IDDesc& idDesc)
31 : GrSurface(gpu, idDesc.fLifeCycle, desc) 33 : GrSurface(gpu, desc)
32 , INHERITED(gpu, idDesc.fLifeCycle, desc, idDesc.fSampleConfig) { 34 , INHERITED(gpu, desc, idDesc.fSampleConfig) {
33 this->init(desc, idDesc); 35 this->init(desc, idDesc);
34 } 36 }
35 37
36 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) { 38 void GrGLRenderTarget::init(const GrSurfaceDesc& desc, const IDDesc& idDesc) {
37 fRTFBOID = idDesc.fRTFBOID; 39 fRTFBOID = idDesc.fRTFBOID;
38 fTexFBOID = idDesc.fTexFBOID; 40 fTexFBOID = idDesc.fTexFBOID;
39 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; 41 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID;
40 fRTLifecycle = idDesc.fLifeCycle; 42 fRTFBOOwnership = idDesc.fRTFBOOwnership;
41 43
42 fViewport.fLeft = 0; 44 fViewport.fLeft = 0;
43 fViewport.fBottom = 0; 45 fViewport.fBottom = 0;
44 fViewport.fWidth = desc.fWidth; 46 fViewport.fWidth = desc.fWidth;
45 fViewport.fHeight = desc.fHeight; 47 fViewport.fHeight = desc.fHeight;
46 48
47 fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample(); 49 fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample();
48 50
49 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); 51 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc));
50 } 52 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 GrGLenum status; 122 GrGLenum status;
121 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAME BUFFER)); 123 GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAME BUFFER));
122 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); 124 SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status);
123 } 125 }
124 #endif 126 #endif
125 return true; 127 return true;
126 } 128 }
127 } 129 }
128 130
129 void GrGLRenderTarget::onRelease() { 131 void GrGLRenderTarget::onRelease() {
130 if (kBorrowed_LifeCycle != fRTLifecycle) { 132 if (GrBackendObjectOwnership::kBorrowed != fRTFBOOwnership) {
131 if (fTexFBOID) { 133 if (fTexFBOID) {
132 GL_CALL(DeleteFramebuffers(1, &fTexFBOID)); 134 GL_CALL(DeleteFramebuffers(1, &fTexFBOID));
133 } 135 }
134 if (fRTFBOID && fRTFBOID != fTexFBOID) { 136 if (fRTFBOID && fRTFBOID != fTexFBOID) {
135 GL_CALL(DeleteFramebuffers(1, &fRTFBOID)); 137 GL_CALL(DeleteFramebuffers(1, &fRTFBOID));
136 } 138 }
137 if (fMSColorRenderbufferID) { 139 if (fMSColorRenderbufferID) {
138 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); 140 GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID));
139 } 141 }
140 } 142 }
141 fRTFBOID = 0; 143 fRTFBOID = 0;
142 fTexFBOID = 0; 144 fTexFBOID = 0;
143 fMSColorRenderbufferID = 0; 145 fMSColorRenderbufferID = 0;
144 INHERITED::onRelease(); 146 INHERITED::onRelease();
145 } 147 }
146 148
147 void GrGLRenderTarget::onAbandon() { 149 void GrGLRenderTarget::onAbandon() {
148 fRTFBOID = 0; 150 fRTFBOID = 0;
149 fTexFBOID = 0; 151 fTexFBOID = 0;
150 fMSColorRenderbufferID = 0; 152 fMSColorRenderbufferID = 0;
151 INHERITED::onAbandon(); 153 INHERITED::onAbandon();
152 } 154 }
153 155
154 GrGLGpu* GrGLRenderTarget::getGLGpu() const { 156 GrGLGpu* GrGLRenderTarget::getGLGpu() const {
155 SkASSERT(!this->wasDestroyed()); 157 SkASSERT(!this->wasDestroyed());
156 return static_cast<GrGLGpu*>(this->getGpu()); 158 return static_cast<GrGLGpu*>(this->getGpu());
157 } 159 }
158 160
161 bool GrGLRenderTarget::canAttemptStencilAttachment() const {
162 // When we have not created the FBO ID we do not attempt to modify its attac hments.
163 // Direct GrGLRenderTarget instances are always created with CreateWrapped.
164 SkASSERT(this->resourcePriv().refsWrappedObjects());
165 return false;
166 }
167
159 void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { 168 void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
160 // Don't log the backing texture's contribution to the memory size. This wil l be handled by the 169 // Don't log the backing texture's contribution to the memory size. This wil l be handled by the
161 // texture object. 170 // texture object.
162 171
163 // Log any renderbuffer's contribution to memory. We only do this if we own the renderbuffer 172 // Log any renderbuffer's contribution to memory. We only do this if we own the renderbuffer
164 // (have a fMSColorRenderbufferID). 173 // (have a fMSColorRenderbufferID).
165 if (fMSColorRenderbufferID) { 174 if (fMSColorRenderbufferID) {
166 size_t size = this->msaaSamples() * this->totalBytesPerSample(); 175 size_t size = this->msaaSamples() * this->totalBytesPerSample();
167 176
168 // Due to this resource having both a texture and a renderbuffer compone nt, dump as 177 // Due to this resource having both a texture and a renderbuffer compone nt, dump as
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 int GrGLRenderTarget::totalSamples() const { 217 int GrGLRenderTarget::totalSamples() const {
209 int total_samples = this->msaaSamples(); 218 int total_samples = this->msaaSamples();
210 219
211 if (fTexFBOID != kUnresolvableFBOID) { 220 if (fTexFBOID != kUnresolvableFBOID) {
212 // If we own the resolve buffer then that is one more sample per pixel. 221 // If we own the resolve buffer then that is one more sample per pixel.
213 total_samples += 1; 222 total_samples += 1;
214 } 223 }
215 224
216 return total_samples; 225 return total_samples;
217 } 226 }
OLDNEW
« no previous file with comments | « src/gpu/gl/GrGLRenderTarget.h ('k') | src/gpu/gl/GrGLStencilAttachment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698