ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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/GrTexturePriv.h" |
| 12 | #include "src/gpu/gl/GrGLGpu.h" |
| 13 | #include "src/gpu/gl/GrGLTextureRenderTarget.h" |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 14 | |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 15 | GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, |
| 16 | SkBudgeted budgeted, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 17 | int sampleCount, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 18 | const GrGLTexture::Desc& texDesc, |
| 19 | const GrGLRenderTarget::IDs& rtIDs, |
Greg Daniel | 0fc4d2d | 2017-10-12 11:23:36 -0400 | [diff] [blame] | 20 | GrMipMapsStatus mipMapsStatus) |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 21 | : GrSurface(gpu, texDesc.fSize, texDesc.fConfig, GrProtected::kNo) |
| 22 | , GrGLTexture(gpu, texDesc, nullptr, mipMapsStatus) |
| 23 | , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, texDesc.fConfig, sampleCount, |
| 24 | rtIDs) { |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 25 | this->registerWithCache(budgeted); |
| 26 | } |
| 27 | |
| 28 | GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 29 | int sampleCount, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 30 | const GrGLTexture::Desc& texDesc, |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 31 | sk_sp<GrGLTextureParameters> parameters, |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 32 | const GrGLRenderTarget::IDs& rtIDs, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 33 | GrWrapCacheable cacheable, |
Greg Daniel | 177e695 | 2017-10-12 12:27:11 -0400 | [diff] [blame] | 34 | GrMipMapsStatus mipMapsStatus) |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 35 | : GrSurface(gpu, texDesc.fSize, texDesc.fConfig, GrProtected::kNo) |
| 36 | , GrGLTexture(gpu, texDesc, std::move(parameters), mipMapsStatus) |
| 37 | , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, texDesc.fConfig, sampleCount, |
| 38 | rtIDs) { |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 39 | this->registerWithCacheWrapped(cacheable); |
Greg Daniel | 6ecc911 | 2017-06-16 16:17:03 +0000 | [diff] [blame] | 40 | } |
| 41 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 42 | void GrGLTextureRenderTarget::dumpMemoryStatistics( |
| 43 | SkTraceMemoryDump* traceMemoryDump) const { |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 44 | #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Eric Karl | af77002 | 2018-03-19 13:04:03 -0700 | [diff] [blame] | 45 | // Delegate to the base classes |
| 46 | GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump); |
| 47 | GrGLTexture::dumpMemoryStatistics(traceMemoryDump); |
Derek Sollenberger | cf6da8c | 2018-03-29 13:40:02 -0400 | [diff] [blame] | 48 | #else |
| 49 | SkString resourceName = this->getResourceName(); |
| 50 | resourceName.append("/texture_renderbuffer"); |
| 51 | this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget", |
| 52 | this->gpuMemorySize()); |
| 53 | #endif |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 54 | } |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 55 | |
| 56 | bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const { |
| 57 | // The RT FBO of GrGLTextureRenderTarget is never created from a |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 58 | // wrapped FBO, so we only care about the flag. |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 59 | return !this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers(); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 60 | } |
| 61 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 62 | sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped( |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 63 | GrGLGpu* gpu, |
| 64 | int sampleCount, |
| 65 | const GrGLTexture::Desc& texDesc, |
| 66 | sk_sp<GrGLTextureParameters> parameters, |
| 67 | const GrGLRenderTarget::IDs& rtIDs, |
| 68 | GrWrapCacheable cacheable, |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 69 | GrMipMapsStatus mipMapsStatus) { |
Brian Salomon | ea4ad30 | 2019-08-07 13:04:55 -0400 | [diff] [blame] | 70 | return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget( |
| 71 | gpu, sampleCount, texDesc, std::move(parameters), rtIDs, cacheable, mipMapsStatus)); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 72 | } |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 73 | |
| 74 | size_t GrGLTextureRenderTarget::onGpuMemorySize() const { |
| 75 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
Brian Salomon | e2826ab | 2019-06-04 15:58:31 -0400 | [diff] [blame] | 76 | this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped()); |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 77 | } |