blob: 6739b793b9c9dd68df3aebde575d27abd4dad3ef [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)
Brian Salomone2826ab2019-06-04 15:58:31 -040022 , GrGLTexture(gpu, desc, texIDDesc, nullptr, 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,
Brian Salomone2826ab2019-06-04 15:58:31 -040030 sk_sp<GrGLTextureParameters> parameters,
Greg Daniel177e6952017-10-12 12:27:11 -040031 const GrGLRenderTarget::IDDesc& rtIDDesc,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050032 GrWrapCacheable cacheable,
Greg Daniel177e6952017-10-12 12:27:11 -040033 GrMipMapsStatus mipMapsStatus)
Greg Daniel6ecc9112017-06-16 16:17:03 +000034 : GrSurface(gpu, desc)
Brian Salomone2826ab2019-06-04 15:58:31 -040035 , GrGLTexture(gpu, desc, texIDDesc, std::move(parameters), mipMapsStatus)
Greg Daniel4065d452018-11-16 15:43:41 -050036 , GrGLRenderTarget(gpu, desc, texIDDesc.fInfo.fFormat, rtIDDesc) {
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050037 this->registerWithCacheWrapped(cacheable);
Greg Daniel6ecc9112017-06-16 16:17:03 +000038}
39
ericrk0a5fa482015-09-15 14:16:10 -070040void GrGLTextureRenderTarget::dumpMemoryStatistics(
41 SkTraceMemoryDump* traceMemoryDump) const {
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040042#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
Eric Karlaf770022018-03-19 13:04:03 -070043 // Delegate to the base classes
44 GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
45 GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040046#else
47 SkString resourceName = this->getResourceName();
48 resourceName.append("/texture_renderbuffer");
49 this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
50 this->gpuMemorySize());
51#endif
ericrk0a5fa482015-09-15 14:16:10 -070052}
kkinnunen2e6055b2016-04-22 01:48:29 -070053
54bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
55 // The RT FBO of GrGLTextureRenderTarget is never created from a
Eric Karl5c779752017-05-08 12:02:07 -070056 // wrapped FBO, so we only care about the flag.
Robert Phillips9da87e02019-02-04 13:26:26 -050057 return !this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers();
kkinnunen2e6055b2016-04-22 01:48:29 -070058}
59
bungeman6bd52842016-10-27 09:30:08 -070060sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050061 GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc,
Brian Salomone2826ab2019-06-04 15:58:31 -040062 sk_sp<GrGLTextureParameters> parameters, const GrGLRenderTarget::IDDesc& rtIDDesc,
63 GrWrapCacheable cacheable, GrMipMapsStatus mipMapsStatus) {
64 return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget(
65 gpu, desc, texIDDesc, std::move(parameters), rtIDDesc, cacheable, mipMapsStatus));
kkinnunen2e6055b2016-04-22 01:48:29 -070066}
Robert Phillips646e4292017-06-13 12:44:56 -040067
68size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
69 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
Brian Salomone2826ab2019-06-04 15:58:31 -040070 this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
Robert Phillips646e4292017-06-13 12:44:56 -040071}