blob: ab861627c50a574d8d1b317f6d4aa6d16ed88748 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#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"
ericrk0a5fa482015-09-15 14:16:10 -070014
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 Daniel4065d452018-11-16 15:43:41 -050023 , GrGLRenderTarget(gpu, desc, texIDDesc.fInfo.fFormat, rtIDDesc) {
Greg Daniel6ecc9112017-06-16 16:17:03 +000024 this->registerWithCache(budgeted);
25}
26
27GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
28 const GrSurfaceDesc& desc,
29 const GrGLTexture::IDDesc& texIDDesc,
Greg Daniel177e6952017-10-12 12:27:11 -040030 const GrGLRenderTarget::IDDesc& rtIDDesc,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050031 GrWrapCacheable cacheable,
Greg Daniel177e6952017-10-12 12:27:11 -040032 GrMipMapsStatus mipMapsStatus)
Greg Daniel6ecc9112017-06-16 16:17:03 +000033 : GrSurface(gpu, desc)
Greg Daniel177e6952017-10-12 12:27:11 -040034 , GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus)
Greg Daniel4065d452018-11-16 15:43:41 -050035 , GrGLRenderTarget(gpu, desc, texIDDesc.fInfo.fFormat, rtIDDesc) {
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050036 this->registerWithCacheWrapped(cacheable);
Greg Daniel6ecc9112017-06-16 16:17:03 +000037}
38
ericrk0a5fa482015-09-15 14:16:10 -070039void GrGLTextureRenderTarget::dumpMemoryStatistics(
40 SkTraceMemoryDump* traceMemoryDump) const {
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040041#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
Eric Karlaf770022018-03-19 13:04:03 -070042 // Delegate to the base classes
43 GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
44 GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040045#else
46 SkString resourceName = this->getResourceName();
47 resourceName.append("/texture_renderbuffer");
48 this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
49 this->gpuMemorySize());
50#endif
ericrk0a5fa482015-09-15 14:16:10 -070051}
kkinnunen2e6055b2016-04-22 01:48:29 -070052
53bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
54 // The RT FBO of GrGLTextureRenderTarget is never created from a
Eric Karl5c779752017-05-08 12:02:07 -070055 // wrapped FBO, so we only care about the flag.
Robert Phillips9da87e02019-02-04 13:26:26 -050056 return !this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers();
kkinnunen2e6055b2016-04-22 01:48:29 -070057}
58
bungeman6bd52842016-10-27 09:30:08 -070059sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050060 GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc,
61 const GrGLRenderTarget::IDDesc& rtIDDesc, GrWrapCacheable cacheable,
62 GrMipMapsStatus mipMapsStatus) {
bungeman6bd52842016-10-27 09:30:08 -070063 return sk_sp<GrGLTextureRenderTarget>(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050064 new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, cacheable, mipMapsStatus));
kkinnunen2e6055b2016-04-22 01:48:29 -070065}
Robert Phillips646e4292017-06-13 12:44:56 -040066
67size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
68 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
69 this->numSamplesOwnedPerPixel(),
Greg Daniele252f082017-10-23 16:05:23 -040070 this->texturePriv().mipMapped());
Robert Phillips646e4292017-06-13 12:44:56 -040071}