blob: b60d3c94ef1d69ce1fe5deb182c253b382f1ee77 [file] [log] [blame]
ericrk0a5fa482015-09-15 14:16:10 -07001/*
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 "GrGLTextureRenderTarget.h"
9
Eric Karl5c779752017-05-08 12:02:07 -070010#include "GrContext.h"
Greg Daniel6ecc9112017-06-16 16:17:03 +000011#include "GrGLGpu.h"
Robert Phillips646e4292017-06-13 12:44:56 -040012#include "GrTexturePriv.h"
ericrk0a5fa482015-09-15 14:16:10 -070013#include "SkTraceMemoryDump.h"
14
Greg Daniel6ecc9112017-06-16 16:17:03 +000015GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
16 SkBudgeted budgeted,
17 const GrSurfaceDesc& desc,
18 const GrGLTexture::IDDesc& texIDDesc,
19 const GrGLRenderTarget::IDDesc& rtIDDesc,
Greg Daniel834f1202017-10-09 15:06:20 -040020 bool mipsAllocated,
21 bool wasFullMipMapDataProvided)
Greg Daniel6ecc9112017-06-16 16:17:03 +000022 : GrSurface(gpu, desc)
Greg Daniel834f1202017-10-09 15:06:20 -040023 , GrGLTexture(gpu, desc, texIDDesc, mipsAllocated, wasFullMipMapDataProvided)
Greg Daniel6ecc9112017-06-16 16:17:03 +000024 , GrGLRenderTarget(gpu, desc, rtIDDesc) {
25 this->registerWithCache(budgeted);
26}
27
28GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
29 const GrSurfaceDesc& desc,
30 const GrGLTexture::IDDesc& texIDDesc,
Greg Daniel834f1202017-10-09 15:06:20 -040031 const GrGLRenderTarget::IDDesc& rtIDDesc)
Greg Daniel6ecc9112017-06-16 16:17:03 +000032 : GrSurface(gpu, desc)
Greg Daniel834f1202017-10-09 15:06:20 -040033 , GrGLTexture(gpu, desc, texIDDesc, false, false)
Greg Daniel6ecc9112017-06-16 16:17:03 +000034 , GrGLRenderTarget(gpu, desc, rtIDDesc) {
35 this->registerWithCacheWrapped();
36}
37
ericrk0a5fa482015-09-15 14:16:10 -070038// GrGLTextureRenderTarget must dump both of its superclasses.
39void GrGLTextureRenderTarget::dumpMemoryStatistics(
40 SkTraceMemoryDump* traceMemoryDump) const {
41 GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
42
43 // Also dump the GrGLTexture's memory. Due to this resource having both a
44 // texture and a
45 // renderbuffer component, dump as skia/gpu_resources/resource_#/texture
46 SkString dumpName("skia/gpu_resources/resource_");
Robert Phillips294870f2016-11-11 12:38:40 -050047 dumpName.appendU32(this->uniqueID().asUInt());
ericrk0a5fa482015-09-15 14:16:10 -070048 dumpName.append("/texture");
49
50 // Use the texture's gpuMemorySize, not our own, which includes the
51 // renderbuffer as well.
52 size_t size = GrGLTexture::gpuMemorySize();
53
54 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size);
55
56 if (this->isPurgeable()) {
57 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size",
58 "bytes", size);
59 }
60
61 SkString texture_id;
62 texture_id.appendU32(this->textureID());
63 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
64 texture_id.c_str());
65}
kkinnunen2e6055b2016-04-22 01:48:29 -070066
67bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
68 // The RT FBO of GrGLTextureRenderTarget is never created from a
Eric Karl5c779752017-05-08 12:02:07 -070069 // wrapped FBO, so we only care about the flag.
70 return !this->getGpu()->getContext()->caps()->avoidStencilBuffers();
kkinnunen2e6055b2016-04-22 01:48:29 -070071}
72
bungeman6bd52842016-10-27 09:30:08 -070073sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
74 GrGLGpu* gpu, const GrSurfaceDesc& desc,
75 const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc)
76{
77 return sk_sp<GrGLTextureRenderTarget>(
Greg Daniel834f1202017-10-09 15:06:20 -040078 new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc));
kkinnunen2e6055b2016-04-22 01:48:29 -070079}
Robert Phillips646e4292017-06-13 12:44:56 -040080
81size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
82 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
83 this->numSamplesOwnedPerPixel(),
84 this->texturePriv().hasMipMaps());
85}