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