blob: 9473c80b8c17d7e050042825c9cd6581a0ef19a1 [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,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040017 int sampleCount,
Brian Salomonea4ad302019-08-07 13:04:55 -040018 const GrGLTexture::Desc& texDesc,
19 const GrGLRenderTarget::IDs& rtIDs,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040020 GrMipMapsStatus mipMapsStatus)
Brian Salomonea4ad302019-08-07 13:04:55 -040021 : 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) {
Greg Daniel6ecc9112017-06-16 16:17:03 +000025 this->registerWithCache(budgeted);
26}
27
28GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040029 int sampleCount,
Brian Salomonea4ad302019-08-07 13:04:55 -040030 const GrGLTexture::Desc& texDesc,
Brian Salomone2826ab2019-06-04 15:58:31 -040031 sk_sp<GrGLTextureParameters> parameters,
Brian Salomonea4ad302019-08-07 13:04:55 -040032 const GrGLRenderTarget::IDs& rtIDs,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050033 GrWrapCacheable cacheable,
Greg Daniel177e6952017-10-12 12:27:11 -040034 GrMipMapsStatus mipMapsStatus)
Brian Salomonea4ad302019-08-07 13:04:55 -040035 : 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) {
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050039 this->registerWithCacheWrapped(cacheable);
Greg Daniel6ecc9112017-06-16 16:17:03 +000040}
41
ericrk0a5fa482015-09-15 14:16:10 -070042void GrGLTextureRenderTarget::dumpMemoryStatistics(
43 SkTraceMemoryDump* traceMemoryDump) const {
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040044#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
Eric Karlaf770022018-03-19 13:04:03 -070045 // Delegate to the base classes
46 GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
47 GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040048#else
49 SkString resourceName = this->getResourceName();
50 resourceName.append("/texture_renderbuffer");
51 this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
52 this->gpuMemorySize());
53#endif
ericrk0a5fa482015-09-15 14:16:10 -070054}
kkinnunen2e6055b2016-04-22 01:48:29 -070055
56bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
57 // The RT FBO of GrGLTextureRenderTarget is never created from a
Eric Karl5c779752017-05-08 12:02:07 -070058 // wrapped FBO, so we only care about the flag.
Robert Phillips9da87e02019-02-04 13:26:26 -050059 return !this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers();
kkinnunen2e6055b2016-04-22 01:48:29 -070060}
61
bungeman6bd52842016-10-27 09:30:08 -070062sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
Brian Salomonea4ad302019-08-07 13:04:55 -040063 GrGLGpu* gpu,
64 int sampleCount,
65 const GrGLTexture::Desc& texDesc,
66 sk_sp<GrGLTextureParameters> parameters,
67 const GrGLRenderTarget::IDs& rtIDs,
68 GrWrapCacheable cacheable,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040069 GrMipMapsStatus mipMapsStatus) {
Brian Salomonea4ad302019-08-07 13:04:55 -040070 return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget(
71 gpu, sampleCount, texDesc, std::move(parameters), rtIDs, cacheable, mipMapsStatus));
kkinnunen2e6055b2016-04-22 01:48:29 -070072}
Robert Phillips646e4292017-06-13 12:44:56 -040073
74size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
75 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
Brian Salomone2826ab2019-06-04 15:58:31 -040076 this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
Robert Phillips646e4292017-06-13 12:44:56 -040077}