• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, texDesc.fIsProtected, label)
24         , GrGLTexture(gpu, texDesc, nullptr, mipmapStatus, label)
25         , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, rtIDs,
26                            texDesc.fIsProtected, label) {
27     this->registerWithCache(budgeted);
28 }
29 
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)30 GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
31                                                  int sampleCount,
32                                                  const GrGLTexture::Desc& texDesc,
33                                                  sk_sp<GrGLTextureParameters> parameters,
34                                                  const GrGLRenderTarget::IDs& rtIDs,
35                                                  GrWrapCacheable cacheable,
36                                                  GrMipmapStatus mipmapStatus,
37                                                  std::string_view label)
38         : GrSurface(gpu, texDesc.fSize, texDesc.fIsProtected, label)
39         , GrGLTexture(gpu, texDesc, std::move(parameters), mipmapStatus, label)
40         , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, rtIDs,
41                            texDesc.fIsProtected, label) {
42     this->registerWithCacheWrapped(cacheable);
43 }
44 
dumpMemoryStatistics(SkTraceMemoryDump * traceMemoryDump) const45 void GrGLTextureRenderTarget::dumpMemoryStatistics(
46     SkTraceMemoryDump* traceMemoryDump) const {
47 #ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
48     // Delegate to the base classes
49     GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
50     GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
51 #else
52     SkString resourceName = this->getResourceName();
53     resourceName.append("/texture_renderbuffer");
54     this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
55                                    this->gpuMemorySize());
56 #endif
57 }
58 
canAttemptStencilAttachment(bool useMultisampleFBO) const59 bool GrGLTextureRenderTarget::canAttemptStencilAttachment(bool useMultisampleFBO) const {
60     // This cap should have been handled at a higher level.
61     SkASSERT(!this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers());
62     // The RT FBO of GrGLTextureRenderTarget is never created from a wrapped FBO.
63     return true;
64 }
65 
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)66 sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
67         GrGLGpu* gpu,
68         int sampleCount,
69         const GrGLTexture::Desc& texDesc,
70         sk_sp<GrGLTextureParameters> parameters,
71         const GrGLRenderTarget::IDs& rtIDs,
72         GrWrapCacheable cacheable,
73         GrMipmapStatus mipmapStatus,
74         std::string_view label) {
75     return sk_sp<GrGLTextureRenderTarget>(
76             new GrGLTextureRenderTarget(gpu,
77                                         sampleCount,
78                                         texDesc,
79                                         std::move(parameters),
80                                         rtIDs,
81                                         cacheable,
82                                         mipmapStatus,
83                                         label));
84 }
85 
onGpuMemorySize() const86 size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
87     return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
88                                   this->totalMemorySamplesPerPixel(), this->mipmapped());
89 }
90 
onSetLabel()91 void GrGLTextureRenderTarget::onSetLabel() {
92     GrGLTexture::onSetLabel();
93 }
94