OLD | NEW |
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" | 10 #include "GrRenderTargetPriv.h" |
11 #include "GrGLGpu.h" | 11 #include "GrGLGpu.h" |
12 #include "GrGLUtil.h" | 12 #include "GrGLUtil.h" |
| 13 #include "SkTraceMemoryDump.h" |
13 | 14 |
14 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) | 15 #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
15 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) | 16 #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
16 | 17 |
17 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. | 18 // Because this class is virtually derived from GrSurface we must explicitly cal
l its constructor. |
18 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, | 19 GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, |
19 const GrSurfaceDesc& desc, | 20 const GrSurfaceDesc& desc, |
20 const IDDesc& idDesc, | 21 const IDDesc& idDesc, |
21 GrGLStencilAttachment* stencil) | 22 GrGLStencilAttachment* stencil) |
22 : GrSurface(gpu, idDesc.fLifeCycle, desc) | 23 : GrSurface(gpu, idDesc.fLifeCycle, desc) |
(...skipping 13 matching lines...) Expand all Loading... |
36 fRTFBOID = idDesc.fRTFBOID; | 37 fRTFBOID = idDesc.fRTFBOID; |
37 fTexFBOID = idDesc.fTexFBOID; | 38 fTexFBOID = idDesc.fTexFBOID; |
38 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; | 39 fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; |
39 fRTLifecycle = idDesc.fLifeCycle; | 40 fRTLifecycle = idDesc.fLifeCycle; |
40 | 41 |
41 fViewport.fLeft = 0; | 42 fViewport.fLeft = 0; |
42 fViewport.fBottom = 0; | 43 fViewport.fBottom = 0; |
43 fViewport.fWidth = desc.fWidth; | 44 fViewport.fWidth = desc.fWidth; |
44 fViewport.fHeight = desc.fHeight; | 45 fViewport.fHeight = desc.fHeight; |
45 | 46 |
46 // We own one color value for each MSAA sample. | 47 fGpuMemorySize = this->totalSamples() * this->totalBytesPerSample(); |
47 int colorValuesPerPixel = SkTMax(1, fDesc.fSampleCnt); | |
48 if (fTexFBOID != kUnresolvableFBOID && fTexFBOID != fRTFBOID) { | |
49 // If we own the resolve buffer then that is one more sample per pixel. | |
50 colorValuesPerPixel += 1; | |
51 } else if (fTexFBOID != 0) { | |
52 // For auto-resolving FBOs, the MSAA buffer is free. | |
53 colorValuesPerPixel = 1; | |
54 } | |
55 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); | |
56 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); | |
57 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); | |
58 SkASSERT(colorBytes > 0); | |
59 fGpuMemorySize = colorValuesPerPixel * fDesc.fWidth * fDesc.fHeight * colorB
ytes; | |
60 | 48 |
61 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); | 49 SkASSERT(fGpuMemorySize <= WorseCaseSize(desc)); |
62 } | 50 } |
63 | 51 |
64 GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu, | 52 GrGLRenderTarget* GrGLRenderTarget::CreateWrapped(GrGLGpu* gpu, |
65 const GrSurfaceDesc& desc, | 53 const GrSurfaceDesc& desc, |
66 const IDDesc& idDesc, | 54 const IDDesc& idDesc, |
67 int stencilBits) { | 55 int stencilBits) { |
68 GrGLStencilAttachment* sb = nullptr; | 56 GrGLStencilAttachment* sb = nullptr; |
69 if (stencilBits) { | 57 if (stencilBits) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 fTexFBOID = 0; | 143 fTexFBOID = 0; |
156 fMSColorRenderbufferID = 0; | 144 fMSColorRenderbufferID = 0; |
157 INHERITED::onAbandon(); | 145 INHERITED::onAbandon(); |
158 } | 146 } |
159 | 147 |
160 GrGLGpu* GrGLRenderTarget::getGLGpu() const { | 148 GrGLGpu* GrGLRenderTarget::getGLGpu() const { |
161 SkASSERT(!this->wasDestroyed()); | 149 SkASSERT(!this->wasDestroyed()); |
162 return static_cast<GrGLGpu*>(this->getGpu()); | 150 return static_cast<GrGLGpu*>(this->getGpu()); |
163 } | 151 } |
164 | 152 |
| 153 void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump)
const { |
| 154 // Don't log the backing texture's contribution to the memory size. This wil
l be handled by the |
| 155 // texture object. |
| 156 |
| 157 // Log any renderbuffer's contribution to memory. We only do this if we own
the renderbuffer |
| 158 // (have a fMSColorRenderbufferID). |
| 159 if (fMSColorRenderbufferID) { |
| 160 size_t size = this->msaaSamples() * this->totalBytesPerSample(); |
| 161 |
| 162 // Due to this resource having both a texture and a renderbuffer compone
nt, dump as |
| 163 // skia/gpu_resources/resource_#/renderbuffer |
| 164 SkString dumpName("skia/gpu_resources/resource_"); |
| 165 dumpName.appendS32(this->getUniqueID()); |
| 166 dumpName.append("/renderbuffer"); |
| 167 |
| 168 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", siz
e); |
| 169 |
| 170 if (this->isPurgeable()) { |
| 171 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size"
, "bytes", size); |
| 172 } |
| 173 |
| 174 SkString renderbuffer_id; |
| 175 renderbuffer_id.appendU32(fMSColorRenderbufferID); |
| 176 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer", |
| 177 renderbuffer_id.c_str()); |
| 178 } |
| 179 } |
| 180 |
| 181 size_t GrGLRenderTarget::totalBytesPerSample() const { |
| 182 SkASSERT(kUnknown_GrPixelConfig != fDesc.fConfig); |
| 183 SkASSERT(!GrPixelConfigIsCompressed(fDesc.fConfig)); |
| 184 size_t colorBytes = GrBytesPerPixel(fDesc.fConfig); |
| 185 SkASSERT(colorBytes > 0); |
| 186 |
| 187 return fDesc.fWidth * fDesc.fHeight * colorBytes; |
| 188 } |
| 189 |
| 190 int GrGLRenderTarget::msaaSamples() const { |
| 191 if (fTexFBOID == kUnresolvableFBOID || fTexFBOID != fRTFBOID) { |
| 192 // If the render target's FBO is external (fTexFBOID == kUnresolvableFBO
ID), or if we own |
| 193 // the render target's FBO (fTexFBOID == fRTFBOID) then we use the provi
ded sample count. |
| 194 return SkTMax(1, fDesc.fSampleCnt); |
| 195 } |
| 196 |
| 197 // When fTexFBOID == fRTFBOID, we either are not using MSAA, or MSAA is auto
resolving, so use |
| 198 // 0 for the sample count. |
| 199 return 0; |
| 200 } |
| 201 |
| 202 int GrGLRenderTarget::totalSamples() const { |
| 203 int total_samples = this->msaaSamples(); |
| 204 |
| 205 if (fTexFBOID != kUnresolvableFBOID) { |
| 206 // If we own the resolve buffer then that is one more sample per pixel. |
| 207 total_samples += 1; |
| 208 } |
| 209 |
| 210 return total_samples; |
| 211 } |
OLD | NEW |