bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkTraceMemoryDump.h" |
| 9 | #include "include/gpu/GrContext.h" |
| 10 | #include "src/gpu/GrContextPriv.h" |
| 11 | #include "src/gpu/GrGpuResourcePriv.h" |
| 12 | #include "src/gpu/GrRenderTargetPriv.h" |
| 13 | #include "src/gpu/gl/GrGLGpu.h" |
| 14 | #include "src/gpu/gl/GrGLRenderTarget.h" |
| 15 | #include "src/gpu/gl/GrGLUtil.h" |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 16 | |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 17 | #define GPUGL static_cast<GrGLGpu*>(this->getGpu()) |
| 18 | #define GL_CALL(X) GR_GL_CALL(GPUGL->glInterface(), X) |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 19 | |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 20 | // Because this class is virtually derived from GrSurface we must explicitly call its constructor. |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 21 | // Constructor for wrapped render targets. |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 22 | GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 23 | const SkISize& dimensions, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 24 | GrGLFormat format, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 25 | int sampleCount, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 26 | const IDs& ids, |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 27 | GrGLStencilAttachment* stencil) |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 28 | : GrSurface(gpu, dimensions, GrProtected::kNo) |
| 29 | , INHERITED(gpu, dimensions, sampleCount, GrProtected::kNo, stencil) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 30 | this->setFlags(gpu->glCaps(), ids); |
| 31 | this->init(format, ids); |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 32 | this->registerWithCacheWrapped(GrWrapCacheable::kNo); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 35 | GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 36 | const SkISize& dimensions, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 37 | GrGLFormat format, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 38 | int sampleCount, |
| 39 | const IDs& ids) |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 40 | : GrSurface(gpu, dimensions, GrProtected::kNo) |
| 41 | , INHERITED(gpu, dimensions, sampleCount, GrProtected::kNo) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 42 | this->setFlags(gpu->glCaps(), ids); |
| 43 | this->init(format, ids); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 46 | inline void GrGLRenderTarget::setFlags(const GrGLCaps& glCaps, const IDs& idDesc) { |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 47 | if (!idDesc.fRTFBOID) { |
Jim Van Verth | 5fab909 | 2019-11-25 21:23:53 +0000 | [diff] [blame] | 48 | this->setGLRTFBOIDIs0(); |
Greg Daniel | a070ed7 | 2018-04-26 16:31:38 -0400 | [diff] [blame] | 49 | } |
csmartdalton | f963599 | 2016-08-10 11:09:07 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 52 | void GrGLRenderTarget::init(GrGLFormat format, const IDs& idDesc) { |
| 53 | fRTFBOID = idDesc.fRTFBOID; |
| 54 | fTexFBOID = idDesc.fTexFBOID; |
| 55 | fMSColorRenderbufferID = idDesc.fMSColorRenderbufferID; |
| 56 | fRTFBOOwnership = idDesc.fRTFBOOwnership; |
| 57 | fRTFormat = format; |
Robert Phillips | 29e52f1 | 2016-11-03 10:19:14 -0400 | [diff] [blame] | 58 | fNumSamplesOwnedPerPixel = this->totalSamples(); |
senorblanco | d298121 | 2015-04-30 12:06:10 -0700 | [diff] [blame] | 59 | } |
| 60 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 61 | sk_sp<GrGLRenderTarget> GrGLRenderTarget::MakeWrapped(GrGLGpu* gpu, |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 62 | const SkISize& dimensions, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 63 | GrGLFormat format, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 64 | int sampleCount, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 65 | const IDs& idDesc, |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 66 | int stencilBits) { |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 67 | GrGLStencilAttachment* sb = nullptr; |
| 68 | if (stencilBits) { |
| 69 | GrGLStencilAttachment::IDDesc sbDesc; |
| 70 | GrGLStencilAttachment::Format format; |
| 71 | format.fInternalFormat = GrGLStencilAttachment::kUnknownInternalFormat; |
| 72 | format.fPacked = false; |
| 73 | format.fStencilBits = stencilBits; |
| 74 | format.fTotalBits = stencilBits; |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 75 | // Ownership of sb is passed to the GrRenderTarget so doesn't need to be deleted |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 76 | sb = new GrGLStencilAttachment(gpu, sbDesc, dimensions.width(), dimensions.height(), |
| 77 | sampleCount, format); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 78 | } |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 79 | return sk_sp<GrGLRenderTarget>( |
Greg Daniel | d51fa2f | 2020-01-22 16:53:38 -0500 | [diff] [blame] | 80 | new GrGLRenderTarget(gpu, dimensions, format, sampleCount, idDesc, sb)); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 83 | GrBackendRenderTarget GrGLRenderTarget::getBackendRenderTarget() const { |
| 84 | GrGLFramebufferInfo fbi; |
| 85 | fbi.fFBOID = fRTFBOID; |
Brian Salomon | 1c53a9f | 2019-08-12 14:10:12 -0400 | [diff] [blame] | 86 | fbi.fFormat = GrGLFormatToEnum(this->format()); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 87 | int numStencilBits = 0; |
| 88 | if (GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment()) { |
| 89 | numStencilBits = stencil->bits(); |
| 90 | } |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 91 | |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 92 | return GrBackendRenderTarget( |
| 93 | this->width(), this->height(), this->numSamples(), numStencilBits, fbi); |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 96 | GrBackendFormat GrGLRenderTarget::backendFormat() const { |
| 97 | // We should never have a GrGLRenderTarget (even a textureable one with a target that is not |
| 98 | // texture 2D. |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 99 | return GrBackendFormat::MakeGL(GrGLFormatToEnum(fRTFormat), GR_GL_TEXTURE_2D); |
Greg Daniel | 4065d45 | 2018-11-16 15:43:41 -0500 | [diff] [blame] | 100 | } |
| 101 | |
senorblanco | d298121 | 2015-04-30 12:06:10 -0700 | [diff] [blame] | 102 | size_t GrGLRenderTarget::onGpuMemorySize() const { |
Greg Daniel | 7fd7a8a | 2019-10-10 16:10:31 -0400 | [diff] [blame] | 103 | const GrCaps& caps = *this->getGpu()->caps(); |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 104 | return GrSurface::ComputeSize(caps, this->backendFormat(), this->dimensions(), |
Greg Daniel | a00bcad | 2019-10-11 13:21:48 -0400 | [diff] [blame] | 105 | fNumSamplesOwnedPerPixel, GrMipMapped::kNo); |
bsalomon@google.com | 5bfc217 | 2011-07-29 20:29:05 +0000 | [diff] [blame] | 106 | } |
| 107 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 108 | bool GrGLRenderTarget::completeStencilAttachment() { |
| 109 | GrGLGpu* gpu = this->getGLGpu(); |
| 110 | const GrGLInterface* interface = gpu->glInterface(); |
| 111 | GrStencilAttachment* stencil = this->renderTargetPriv().getStencilAttachment(); |
| 112 | if (nullptr == stencil) { |
egdaniel | 79bd2ae | 2015-09-15 08:46:13 -0700 | [diff] [blame] | 113 | GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 114 | GR_GL_STENCIL_ATTACHMENT, |
| 115 | GR_GL_RENDERBUFFER, 0)); |
| 116 | GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 117 | GR_GL_DEPTH_ATTACHMENT, |
| 118 | GR_GL_RENDERBUFFER, 0)); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 119 | #ifdef SK_DEBUG |
Brian Salomon | d857545 | 2020-02-25 12:13:29 -0500 | [diff] [blame] | 120 | if (!gpu->glCaps().skipErrorChecks()) { |
robertphillips | fa7ff47 | 2016-04-21 11:27:43 -0700 | [diff] [blame] | 121 | // This check can cause problems in Chromium if the context has been asynchronously |
| 122 | // abandoned (see skbug.com/5200) |
| 123 | GrGLenum status; |
| 124 | GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 125 | SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 126 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 127 | #endif |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 128 | return true; |
| 129 | } else { |
| 130 | const GrGLStencilAttachment* glStencil = static_cast<const GrGLStencilAttachment*>(stencil); |
| 131 | GrGLuint rb = glStencil->renderbufferID(); |
| 132 | |
| 133 | gpu->invalidateBoundRenderTarget(); |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 134 | gpu->bindFramebuffer(GR_GL_FRAMEBUFFER, this->renderFBOID()); |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 135 | GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 136 | GR_GL_STENCIL_ATTACHMENT, |
| 137 | GR_GL_RENDERBUFFER, rb)); |
| 138 | if (glStencil->format().fPacked) { |
| 139 | GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 140 | GR_GL_DEPTH_ATTACHMENT, |
| 141 | GR_GL_RENDERBUFFER, rb)); |
| 142 | } else { |
| 143 | GR_GL_CALL(interface, FramebufferRenderbuffer(GR_GL_FRAMEBUFFER, |
| 144 | GR_GL_DEPTH_ATTACHMENT, |
| 145 | GR_GL_RENDERBUFFER, 0)); |
| 146 | } |
| 147 | |
Adrienne Walker | 3ed3399 | 2018-05-15 11:44:34 -0700 | [diff] [blame] | 148 | |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 149 | #ifdef SK_DEBUG |
Brian Salomon | d857545 | 2020-02-25 12:13:29 -0500 | [diff] [blame] | 150 | if (!gpu->glCaps().skipErrorChecks()) { |
robertphillips | fa7ff47 | 2016-04-21 11:27:43 -0700 | [diff] [blame] | 151 | // This check can cause problems in Chromium if the context has been asynchronously |
| 152 | // abandoned (see skbug.com/5200) |
| 153 | GrGLenum status; |
| 154 | GR_GL_CALL_RET(interface, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER)); |
| 155 | SkASSERT(GR_GL_FRAMEBUFFER_COMPLETE == status); |
| 156 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 157 | #endif |
| 158 | return true; |
| 159 | } |
| 160 | } |
| 161 | |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 162 | void GrGLRenderTarget::onRelease() { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 163 | if (GrBackendObjectOwnership::kBorrowed != fRTFBOOwnership) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 164 | GrGLGpu* gpu = this->getGLGpu(); |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 165 | if (fTexFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 166 | gpu->deleteFramebuffer(fTexFBOID); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 167 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 168 | if (fRTFBOID && fRTFBOID != fTexFBOID) { |
Adrienne Walker | 4ee8851 | 2018-05-17 11:37:14 -0700 | [diff] [blame] | 169 | gpu->deleteFramebuffer(fRTFBOID); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 170 | } |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 171 | if (fMSColorRenderbufferID) { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 172 | GL_CALL(DeleteRenderbuffers(1, &fMSColorRenderbufferID)); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 173 | } |
| 174 | } |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 175 | fRTFBOID = 0; |
| 176 | fTexFBOID = 0; |
| 177 | fMSColorRenderbufferID = 0; |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 178 | INHERITED::onRelease(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void GrGLRenderTarget::onAbandon() { |
egdaniel | d803f27 | 2015-03-18 13:01:52 -0700 | [diff] [blame] | 182 | fRTFBOID = 0; |
| 183 | fTexFBOID = 0; |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 184 | fMSColorRenderbufferID = 0; |
robertphillips@google.com | d6bbbf8 | 2012-09-05 15:46:34 +0000 | [diff] [blame] | 185 | INHERITED::onAbandon(); |
bsalomon@google.com | aa5b673 | 2011-07-29 15:13:20 +0000 | [diff] [blame] | 186 | } |
egdaniel | ec00d94 | 2015-09-14 12:56:10 -0700 | [diff] [blame] | 187 | |
| 188 | GrGLGpu* GrGLRenderTarget::getGLGpu() const { |
| 189 | SkASSERT(!this->wasDestroyed()); |
| 190 | return static_cast<GrGLGpu*>(this->getGpu()); |
| 191 | } |
| 192 | |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 193 | bool GrGLRenderTarget::canAttemptStencilAttachment() const { |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 194 | if (this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers()) { |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 195 | return false; |
| 196 | } |
| 197 | |
ericrk | c402518 | 2016-05-04 12:01:58 -0700 | [diff] [blame] | 198 | // Only modify the FBO's attachments if we have created the FBO. Public APIs do not currently |
| 199 | // allow for borrowed FBO ownership, so we can safely assume that if an object is owned, |
| 200 | // Skia created it. |
| 201 | return this->fRTFBOOwnership == GrBackendObjectOwnership::kOwned; |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 202 | } |
| 203 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 204 | void GrGLRenderTarget::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 205 | // Don't check this->fRefsWrappedObjects, as we might be the base of a GrGLTextureRenderTarget |
| 206 | // which is multiply inherited from both ourselves and a texture. In these cases, one part |
| 207 | // (texture, rt) may be wrapped, while the other is owned by Skia. |
| 208 | bool refsWrappedRenderTargetObjects = |
| 209 | this->fRTFBOOwnership == GrBackendObjectOwnership::kBorrowed; |
| 210 | if (refsWrappedRenderTargetObjects && !traceMemoryDump->shouldDumpWrappedObjects()) { |
| 211 | return; |
| 212 | } |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 213 | |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 214 | // Don't log the framebuffer, as the framebuffer itself doesn't contribute to meaningful |
| 215 | // memory usage. It is always a wrapper around either: |
| 216 | // - a texture, which is owned elsewhere, and will be dumped there |
| 217 | // - a renderbuffer, which will be dumped below. |
| 218 | |
| 219 | // Log any renderbuffer's contribution to memory. |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 220 | if (fMSColorRenderbufferID) { |
Greg Daniel | 7fd7a8a | 2019-10-10 16:10:31 -0400 | [diff] [blame] | 221 | const GrCaps& caps = *this->getGpu()->caps(); |
Brian Salomon | 9f2b86c | 2019-10-22 10:37:46 -0400 | [diff] [blame] | 222 | size_t size = GrSurface::ComputeSize(caps, this->backendFormat(), this->dimensions(), |
| 223 | this->msaaSamples(), GrMipMapped::kNo); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 224 | |
| 225 | // Due to this resource having both a texture and a renderbuffer component, dump as |
| 226 | // skia/gpu_resources/resource_#/renderbuffer |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 227 | SkString resourceName = this->getResourceName(); |
| 228 | resourceName.append("/renderbuffer"); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 229 | |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 230 | this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget", size); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 231 | |
| 232 | SkString renderbuffer_id; |
| 233 | renderbuffer_id.appendU32(fMSColorRenderbufferID); |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 234 | traceMemoryDump->setMemoryBacking(resourceName.c_str(), "gl_renderbuffer", |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 235 | renderbuffer_id.c_str()); |
| 236 | } |
| 237 | } |
| 238 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 239 | int GrGLRenderTarget::msaaSamples() const { |
| 240 | if (fTexFBOID == kUnresolvableFBOID || fTexFBOID != fRTFBOID) { |
| 241 | // If the render target's FBO is external (fTexFBOID == kUnresolvableFBOID), or if we own |
| 242 | // the render target's FBO (fTexFBOID == fRTFBOID) then we use the provided sample count. |
Chris Dalton | 6ce447a | 2019-06-23 18:07:38 -0600 | [diff] [blame] | 243 | return this->numSamples(); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | // When fTexFBOID == fRTFBOID, we either are not using MSAA, or MSAA is auto resolving, so use |
| 247 | // 0 for the sample count. |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | int GrGLRenderTarget::totalSamples() const { |
| 252 | int total_samples = this->msaaSamples(); |
| 253 | |
| 254 | if (fTexFBOID != kUnresolvableFBOID) { |
| 255 | // If we own the resolve buffer then that is one more sample per pixel. |
| 256 | total_samples += 1; |
| 257 | } |
| 258 | |
| 259 | return total_samples; |
| 260 | } |