blob: c5a75be872162b02ab6b951a6ebd23ce4e5dbd43 [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 Daniel0fc4d2d2017-10-12 11:23:36 -040020 GrMipMapsStatus mipMapsStatus)
Greg Daniel6ecc9112017-06-16 16:17:03 +000021 : GrSurface(gpu, desc)
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040022 , GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus)
Greg Daniel6ecc9112017-06-16 16:17:03 +000023 , GrGLRenderTarget(gpu, desc, rtIDDesc) {
24 this->registerWithCache(budgeted);
25}
26
27GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
28 const GrSurfaceDesc& desc,
29 const GrGLTexture::IDDesc& texIDDesc,
Greg Daniel834f1202017-10-09 15:06:20 -040030 const GrGLRenderTarget::IDDesc& rtIDDesc)
Greg Daniel6ecc9112017-06-16 16:17:03 +000031 : GrSurface(gpu, desc)
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040032 , GrGLTexture(gpu, desc, texIDDesc, GrMipMapsStatus::kNotAllocated)
Greg Daniel6ecc9112017-06-16 16:17:03 +000033 , GrGLRenderTarget(gpu, desc, rtIDDesc) {
34 this->registerWithCacheWrapped();
35}
36
ericrk0a5fa482015-09-15 14:16:10 -070037// GrGLTextureRenderTarget must dump both of its superclasses.
38void GrGLTextureRenderTarget::dumpMemoryStatistics(
39 SkTraceMemoryDump* traceMemoryDump) const {
40 GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
41
42 // Also dump the GrGLTexture's memory. Due to this resource having both a
43 // texture and a
44 // renderbuffer component, dump as skia/gpu_resources/resource_#/texture
45 SkString dumpName("skia/gpu_resources/resource_");
Robert Phillips294870f2016-11-11 12:38:40 -050046 dumpName.appendU32(this->uniqueID().asUInt());
ericrk0a5fa482015-09-15 14:16:10 -070047 dumpName.append("/texture");
48
49 // Use the texture's gpuMemorySize, not our own, which includes the
50 // renderbuffer as well.
51 size_t size = GrGLTexture::gpuMemorySize();
52
53 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "size", "bytes", size);
54
55 if (this->isPurgeable()) {
56 traceMemoryDump->dumpNumericValue(dumpName.c_str(), "purgeable_size",
57 "bytes", size);
58 }
59
60 SkString texture_id;
61 texture_id.appendU32(this->textureID());
62 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_texture",
63 texture_id.c_str());
64}
kkinnunen2e6055b2016-04-22 01:48:29 -070065
66bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
67 // The RT FBO of GrGLTextureRenderTarget is never created from a
Eric Karl5c779752017-05-08 12:02:07 -070068 // wrapped FBO, so we only care about the flag.
69 return !this->getGpu()->getContext()->caps()->avoidStencilBuffers();
kkinnunen2e6055b2016-04-22 01:48:29 -070070}
71
bungeman6bd52842016-10-27 09:30:08 -070072sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
73 GrGLGpu* gpu, const GrSurfaceDesc& desc,
74 const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc)
75{
76 return sk_sp<GrGLTextureRenderTarget>(
Greg Daniel834f1202017-10-09 15:06:20 -040077 new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc));
kkinnunen2e6055b2016-04-22 01:48:29 -070078}
Robert Phillips646e4292017-06-13 12:44:56 -040079
80size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
81 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
82 this->numSamplesOwnedPerPixel(),
83 this->texturePriv().hasMipMaps());
84}