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/ganesh/gl/GrGLTextureRenderTarget.h"
9
10 #include "include/core/SkTraceMemoryDump.h"
11 #include "include/gpu/GrDirectContext.h"
12 #include "src/gpu/ganesh/GrDirectContextPriv.h"
13 #include "src/gpu/ganesh/GrTexture.h"
14 #include "src/gpu/ganesh/gl/GrGLGpu.h"
15
GrGLTextureRenderTarget(GrGLGpu * gpu,skgpu::Budgeted budgeted,int sampleCount,const GrGLTexture::Desc & texDesc,const GrGLRenderTarget::IDs & rtIDs,GrMipmapStatus mipmapStatus,std::string_view label)16 GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
17 skgpu::Budgeted budgeted,
18 int sampleCount,
19 const GrGLTexture::Desc& texDesc,
20 const GrGLRenderTarget::IDs& rtIDs,
21 GrMipmapStatus mipmapStatus,
22 std::string_view label)
23 : GrSurface(gpu, texDesc.fSize, GrProtected::kNo, label)
24 , GrGLTexture(gpu, texDesc, nullptr, mipmapStatus, label)
25 , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, rtIDs, label) {
26 this->registerWithCache(budgeted);
27 }
28
GrGLTextureRenderTarget(GrGLGpu * gpu,int sampleCount,const GrGLTexture::Desc & texDesc,sk_sp<GrGLTextureParameters> parameters,const GrGLRenderTarget::IDs & rtIDs,GrWrapCacheable cacheable,GrMipmapStatus mipmapStatus,std::string_view label)29 GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
30 int sampleCount,
31 const GrGLTexture::Desc& texDesc,
32 sk_sp<GrGLTextureParameters> parameters,
33 const GrGLRenderTarget::IDs& rtIDs,
34 GrWrapCacheable cacheable,
35 GrMipmapStatus mipmapStatus,
36 std::string_view label)
37 : GrSurface(gpu, texDesc.fSize, GrProtected::kNo, label)
38 , GrGLTexture(gpu, texDesc, std::move(parameters), mipmapStatus, label)
39 , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, rtIDs, label) {
40 this->registerWithCacheWrapped(cacheable);
41 }
42
dumpMemoryStatistics(SkTraceMemoryDump * traceMemoryDump) const43 void GrGLTextureRenderTarget::dumpMemoryStatistics(
44 SkTraceMemoryDump* traceMemoryDump) const {
45 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
46 // Delegate to the base classes
47 GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
48 GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
49 #else
50 SkString resourceName = this->getResourceName();
51 resourceName.append("/texture_renderbuffer");
52 this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
53 this->gpuMemorySize());
54 #endif
55 }
56
canAttemptStencilAttachment(bool useMultisampleFBO) const57 bool GrGLTextureRenderTarget::canAttemptStencilAttachment(bool useMultisampleFBO) const {
58 // This cap should have been handled at a higher level.
59 SkASSERT(!this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers());
60 // The RT FBO of GrGLTextureRenderTarget is never created from a wrapped FBO.
61 return true;
62 }
63
MakeWrapped(GrGLGpu * gpu,int sampleCount,const GrGLTexture::Desc & texDesc,sk_sp<GrGLTextureParameters> parameters,const GrGLRenderTarget::IDs & rtIDs,GrWrapCacheable cacheable,GrMipmapStatus mipmapStatus,std::string_view label)64 sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
65 GrGLGpu* gpu,
66 int sampleCount,
67 const GrGLTexture::Desc& texDesc,
68 sk_sp<GrGLTextureParameters> parameters,
69 const GrGLRenderTarget::IDs& rtIDs,
70 GrWrapCacheable cacheable,
71 GrMipmapStatus mipmapStatus,
72 std::string_view label) {
73 return sk_sp<GrGLTextureRenderTarget>(
74 new GrGLTextureRenderTarget(gpu,
75 sampleCount,
76 texDesc,
77 std::move(parameters),
78 rtIDs,
79 cacheable,
80 mipmapStatus,
81 label));
82 }
83
onGpuMemorySize() const84 size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
85 return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
86 this->totalMemorySamplesPerPixel(), this->mipmapped());
87 }
88
onSetLabel()89 void GrGLTextureRenderTarget::onSetLabel() {
90 GrGLTexture::onSetLabel();
91 }
92