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