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