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/GrDirectContextPriv.h"
13 #include "src/gpu/GrTexture.h"
14 #include "src/gpu/gl/GrGLGpu.h"
15
GrGLTextureRenderTarget(GrGLGpu * gpu,SkBudgeted budgeted,int sampleCount,const GrGLTexture::Desc & texDesc,const GrGLRenderTarget::IDs & rtIDs,GrMipmapStatus mipmapStatus)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
GrGLTextureRenderTarget(GrGLGpu * gpu,int sampleCount,const GrGLTexture::Desc & texDesc,sk_sp<GrGLTextureParameters> parameters,const GrGLRenderTarget::IDs & rtIDs,GrWrapCacheable cacheable,GrMipmapStatus mipmapStatus)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
dumpMemoryStatistics(SkTraceMemoryDump * traceMemoryDump) const42 void GrGLTextureRenderTarget::dumpMemoryStatistics(
43 SkTraceMemoryDump* traceMemoryDump) const {
44 #ifdef 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
canAttemptStencilAttachment(bool useMultisampleFBO) const56 bool GrGLTextureRenderTarget::canAttemptStencilAttachment(bool useMultisampleFBO) const {
57 // This cap should have been handled at a higher level.
58 SkASSERT(!this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers());
59 // The RT FBO of GrGLTextureRenderTarget is never created from a wrapped FBO.
60 return true;
61 }
62
MakeWrapped(GrGLGpu * gpu,int sampleCount,const GrGLTexture::Desc & texDesc,sk_sp<GrGLTextureParameters> parameters,const GrGLRenderTarget::IDs & rtIDs,GrWrapCacheable cacheable,GrMipmapStatus mipmapStatus)63 sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
64 GrGLGpu* gpu,
65 int sampleCount,
66 const GrGLTexture::Desc& texDesc,
67 sk_sp<GrGLTextureParameters> parameters,
68 const GrGLRenderTarget::IDs& rtIDs,
69 GrWrapCacheable cacheable,
70 GrMipmapStatus mipmapStatus) {
71 return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget(
72 gpu, sampleCount, texDesc, std::move(parameters), rtIDs, cacheable, mipmapStatus));
73 }
74
onGpuMemorySize() const75 size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
76 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
77 this->totalMemorySamplesPerPixel(), this->mipmapped());
78 }
79