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" |
| 9 | |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 10 | #include "GrContext.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, |
| 20 | bool wasMipMapDataProvided) |
| 21 | : GrSurface(gpu, desc) |
| 22 | , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided) |
| 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, |
| 30 | const GrGLRenderTarget::IDDesc& rtIDDesc, |
| 31 | bool wasMipMapDataProvided) |
| 32 | : GrSurface(gpu, desc) |
| 33 | , GrGLTexture(gpu, desc, texIDDesc, wasMipMapDataProvided) |
| 34 | , GrGLRenderTarget(gpu, desc, rtIDDesc) { |
| 35 | this->registerWithCacheWrapped(); |
| 36 | } |
| 37 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 38 | // GrGLTextureRenderTarget must dump both of its superclasses. |
| 39 | void GrGLTextureRenderTarget::dumpMemoryStatistics( |
| 40 | SkTraceMemoryDump* traceMemoryDump) const { |
| 41 | GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump); |
| 42 | |
| 43 | // Also dump the GrGLTexture's memory. Due to this resource having both a |
| 44 | // texture and a |
| 45 | // renderbuffer component, dump as skia/gpu_resources/resource_#/texture |
| 46 | SkString dumpName("skia/gpu_resources/resource_"); |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 47 | dumpName.appendU32(this->uniqueID().asUInt()); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 48 | dumpName.append("/texture"); |
| 49 | |
| 50 | // Use the texture's gpuMemorySize, not our own, which includes the |
| 51 | // renderbuffer as well. |
| 52 | size_t size = GrGLTexture::gpuMemorySize(); |
| 53 | |
| 54 | traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size); |
| 55 | |
| 56 | if (this->isPurgeable()) { |
| 57 | traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size", |
| 58 | "bytes", size); |
| 59 | } |
| 60 | |
| 61 | SkString texture_id; |
| 62 | texture_id.appendU32(this->textureID()); |
| 63 | traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture", |
| 64 | texture_id.c_str()); |
| 65 | } |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 66 | |
| 67 | bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const { |
| 68 | // The RT FBO of GrGLTextureRenderTarget is never created from a |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 69 | // wrapped FBO, so we only care about the flag. |
| 70 | return !this->getGpu()->getContext()->caps()->avoidStencilBuffers(); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 71 | } |
| 72 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 73 | sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped( |
| 74 | GrGLGpu* gpu, const GrSurfaceDesc& desc, |
| 75 | const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc) |
| 76 | { |
| 77 | return sk_sp<GrGLTextureRenderTarget>( |
Robert Phillips | d6214d4 | 2016-11-07 08:23:48 -0500 | [diff] [blame] | 78 | new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, false)); |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 79 | } |
Robert Phillips | 646e429 | 2017-06-13 12:44:56 -0400 | [diff] [blame] | 80 | |
| 81 | size_t GrGLTextureRenderTarget::onGpuMemorySize() const { |
| 82 | return GrSurface::ComputeSize(this->config(), this->width(), this->height(), |
| 83 | this->numSamplesOwnedPerPixel(), |
| 84 | this->texturePriv().hasMipMaps()); |
| 85 | } |