blob: 2747f298f7ef2c5378ef96753b3d76bc82c03c94 [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"
Adlai Holler3d0359a2020-07-09 15:35:55 -04009#include "include/gpu/GrDirectContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#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)
Greg Danield51fa2f2020-01-22 16:53:38 -050021 : GrSurface(gpu, texDesc.fSize, GrProtected::kNo)
Brian Salomonea4ad302019-08-07 13:04:55 -040022 , GrGLTexture(gpu, texDesc, nullptr, mipMapsStatus)
Greg Danield51fa2f2020-01-22 16:53:38 -050023 , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, rtIDs) {
Greg Daniel6ecc9112017-06-16 16:17:03 +000024 this->registerWithCache(budgeted);
25}
26
27GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040028 int sampleCount,
Brian Salomonea4ad302019-08-07 13:04:55 -040029 const GrGLTexture::Desc& texDesc,
Brian Salomone2826ab2019-06-04 15:58:31 -040030 sk_sp<GrGLTextureParameters> parameters,
Brian Salomonea4ad302019-08-07 13:04:55 -040031 const GrGLRenderTarget::IDs& rtIDs,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050032 GrWrapCacheable cacheable,
Greg Daniel177e6952017-10-12 12:27:11 -040033 GrMipMapsStatus mipMapsStatus)
Greg Danield51fa2f2020-01-22 16:53:38 -050034 : GrSurface(gpu, texDesc.fSize, GrProtected::kNo)
Brian Salomonea4ad302019-08-07 13:04:55 -040035 , GrGLTexture(gpu, texDesc, std::move(parameters), mipMapsStatus)
Greg Danield51fa2f2020-01-22 16:53:38 -050036 , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount,
Brian Salomonea4ad302019-08-07 13:04:55 -040037 rtIDs) {
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050038 this->registerWithCacheWrapped(cacheable);
Greg Daniel6ecc9112017-06-16 16:17:03 +000039}
40
ericrk0a5fa482015-09-15 14:16:10 -070041void GrGLTextureRenderTarget::dumpMemoryStatistics(
42 SkTraceMemoryDump* traceMemoryDump) const {
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040043#ifndef SK_BUILD_FOR_ANDROID_FRAMEWORK
Eric Karlaf770022018-03-19 13:04:03 -070044 // Delegate to the base classes
45 GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
46 GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
Derek Sollenbergercf6da8c2018-03-29 13:40:02 -040047#else
48 SkString resourceName = this->getResourceName();
49 resourceName.append("/texture_renderbuffer");
50 this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
51 this->gpuMemorySize());
52#endif
ericrk0a5fa482015-09-15 14:16:10 -070053}
kkinnunen2e6055b2016-04-22 01:48:29 -070054
55bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const {
56 // The RT FBO of GrGLTextureRenderTarget is never created from a
Eric Karl5c779752017-05-08 12:02:07 -070057 // wrapped FBO, so we only care about the flag.
Robert Phillips9da87e02019-02-04 13:26:26 -050058 return !this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers();
kkinnunen2e6055b2016-04-22 01:48:29 -070059}
60
bungeman6bd52842016-10-27 09:30:08 -070061sk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
Brian Salomonea4ad302019-08-07 13:04:55 -040062 GrGLGpu* gpu,
63 int sampleCount,
64 const GrGLTexture::Desc& texDesc,
65 sk_sp<GrGLTextureParameters> parameters,
66 const GrGLRenderTarget::IDs& rtIDs,
67 GrWrapCacheable cacheable,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040068 GrMipMapsStatus mipMapsStatus) {
Brian Salomonea4ad302019-08-07 13:04:55 -040069 return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget(
70 gpu, sampleCount, texDesc, std::move(parameters), rtIDs, cacheable, mipMapsStatus));
kkinnunen2e6055b2016-04-22 01:48:29 -070071}
Robert Phillips646e4292017-06-13 12:44:56 -040072
73size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
Greg Daniel7fd7a8a2019-10-10 16:10:31 -040074 const GrCaps& caps = *this->getGpu()->caps();
Brian Salomon9f2b86c2019-10-22 10:37:46 -040075 return GrSurface::ComputeSize(caps, this->backendFormat(), this->dimensions(),
Greg Daniela00bcad2019-10-11 13:21:48 -040076 this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
Robert Phillips646e4292017-06-13 12:44:56 -040077}