| 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 "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" |
| 14 | |
| 15 | GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, |
| 16 | SkBudgeted budgeted, |
| 17 | int sampleCount, |
| 18 | const GrGLTexture::Desc& texDesc, |
| 19 | const GrGLRenderTarget::IDs& rtIDs, |
| 20 | GrMipMapsStatus mipMapsStatus) |
| 21 | : GrSurface(gpu, texDesc.fSize, GrProtected::kNo) |
| 22 | , GrGLTexture(gpu, texDesc, nullptr, mipMapsStatus) |
| 23 | , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, rtIDs) { |
| 24 | this->registerWithCache(budgeted); |
| 25 | } |
| 26 | |
| 27 | GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, |
| 28 | int sampleCount, |
| 29 | const GrGLTexture::Desc& texDesc, |
| 30 | sk_sp<GrGLTextureParameters> parameters, |
| 31 | const GrGLRenderTarget::IDs& rtIDs, |
| 32 | GrWrapCacheable cacheable, |
| 33 | GrMipMapsStatus mipMapsStatus) |
| 34 | : GrSurface(gpu, texDesc.fSize, GrProtected::kNo) |
| 35 | , GrGLTexture(gpu, texDesc, std::move(parameters), mipMapsStatus) |
| 36 | , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, |
| 37 | rtIDs) { |
| 38 | this->registerWithCacheWrapped(cacheable); |
| 39 | } |
| 40 | |
| 41 | void GrGLTextureRenderTarget::dumpMemoryStatistics( |
| 42 | SkTraceMemoryDump* traceMemoryDump) const { |
| 43 | #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 44 | // Delegate to the base classes |
| 45 | GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump); |
| 46 | GrGLTexture::dumpMemoryStatistics(traceMemoryDump); |
| 47 | #else |
| 48 | SkString resourceName = this->getResourceName(); |
| 49 | resourceName.append("/texture_renderbuffer" ); |
| 50 | this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget" , |
| 51 | this->gpuMemorySize()); |
| 52 | #endif |
| 53 | } |
| 54 | |
| 55 | bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const { |
| 56 | // The RT FBO of GrGLTextureRenderTarget is never created from a |
| 57 | // wrapped FBO, so we only care about the flag. |
| 58 | return !this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers(); |
| 59 | } |
| 60 | |
| 61 | sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped( |
| 62 | GrGLGpu* gpu, |
| 63 | int sampleCount, |
| 64 | const GrGLTexture::Desc& texDesc, |
| 65 | sk_sp<GrGLTextureParameters> parameters, |
| 66 | const GrGLRenderTarget::IDs& rtIDs, |
| 67 | GrWrapCacheable cacheable, |
| 68 | GrMipMapsStatus mipMapsStatus) { |
| 69 | return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget( |
| 70 | gpu, sampleCount, texDesc, std::move(parameters), rtIDs, cacheable, mipMapsStatus)); |
| 71 | } |
| 72 | |
| 73 | size_t GrGLTextureRenderTarget::onGpuMemorySize() const { |
| 74 | const GrCaps& caps = *this->getGpu()->caps(); |
| 75 | return GrSurface::ComputeSize(caps, this->backendFormat(), this->dimensions(), |
| 76 | this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped()); |
| 77 | } |
| 78 | |