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