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