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