• 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 "include/core/SkTraceMemoryDump.h"
9 #include "include/gpu/GrContext.h"
10 #include "src/gpu/GrContextPriv.h"
11 #include "src/gpu/GrTexturePriv.h"
12 #include "src/gpu/gl/GrGLGpu.h"
13 #include "src/gpu/gl/GrGLTextureRenderTarget.h"
14 
GrGLTextureRenderTarget(GrGLGpu * gpu,SkBudgeted budgeted,int sampleCount,const GrGLTexture::Desc & texDesc,const GrGLRenderTarget::IDs & rtIDs,GrMipMapsStatus mipMapsStatus)15 GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
16                                                  SkBudgeted budgeted,
17                                                  int sampleCount,
18                                                  const GrGLTexture::Desc& texDesc,
19                                                  const GrGLRenderTarget::IDs& rtIDs,
20                                                  GrMipMapsStatus mipMapsStatus)
21         : GrSurface(gpu, texDesc.fSize, texDesc.fConfig, GrProtected::kNo)
22         , GrGLTexture(gpu, texDesc, nullptr, mipMapsStatus)
23         , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, texDesc.fConfig, sampleCount,
24                            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,GrMipMapsStatus mipMapsStatus)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                                                  GrMipMapsStatus mipMapsStatus)
35         : GrSurface(gpu, texDesc.fSize, texDesc.fConfig, GrProtected::kNo)
36         , GrGLTexture(gpu, texDesc, std::move(parameters), mipMapsStatus)
37         , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, texDesc.fConfig, 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() const56 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 
MakeWrapped(GrGLGpu * gpu,int sampleCount,const GrGLTexture::Desc & texDesc,sk_sp<GrGLTextureParameters> parameters,const GrGLRenderTarget::IDs & rtIDs,GrWrapCacheable cacheable,GrMipMapsStatus mipMapsStatus)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         GrMipMapsStatus mipMapsStatus) {
70     return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget(
71             gpu, sampleCount, texDesc, std::move(parameters), rtIDs, cacheable, mipMapsStatus));
72 }
73 
onGpuMemorySize() const74 size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
75     return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
76                                   this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
77 }
78