blob: de86e9f4c19b846b716e3e0d0336a8cd7bb3e78e [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,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040018 int sampleCount,
Greg Daniel6ecc9112017-06-16 16:17:03 +000019 const GrGLTexture::IDDesc& texIDDesc,
20 const GrGLRenderTarget::IDDesc& rtIDDesc,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040021 GrMipMapsStatus mipMapsStatus)
Brian Salomone8a766b2019-07-19 14:24:36 -040022 : GrSurface(gpu, desc, GrProtected::kNo)
Brian Salomone2826ab2019-06-04 15:58:31 -040023 , GrGLTexture(gpu, desc, texIDDesc, nullptr, mipMapsStatus)
Brian Salomon27b4d8d2019-07-22 14:23:45 -040024 , GrGLRenderTarget(gpu, desc, sampleCount, texIDDesc.fInfo.fFormat, rtIDDesc) {
Greg Daniel6ecc9112017-06-16 16:17:03 +000025 this->registerWithCache(budgeted);
26}
27
28GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
29 const GrSurfaceDesc& desc,
Brian Salomon27b4d8d2019-07-22 14:23:45 -040030 int sampleCount,
Greg Daniel6ecc9112017-06-16 16:17:03 +000031 const GrGLTexture::IDDesc& texIDDesc,
Brian Salomone2826ab2019-06-04 15:58:31 -040032 sk_sp<GrGLTextureParameters> parameters,
Greg Daniel177e6952017-10-12 12:27:11 -040033 const GrGLRenderTarget::IDDesc& rtIDDesc,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050034 GrWrapCacheable cacheable,
Greg Daniel177e6952017-10-12 12:27:11 -040035 GrMipMapsStatus mipMapsStatus)
Brian Salomone8a766b2019-07-19 14:24:36 -040036 : GrSurface(gpu, desc, GrProtected::kNo)
Brian Salomone2826ab2019-06-04 15:58:31 -040037 , GrGLTexture(gpu, desc, texIDDesc, std::move(parameters), mipMapsStatus)
Brian Salomon27b4d8d2019-07-22 14:23:45 -040038 , GrGLRenderTarget(gpu, desc, sampleCount, texIDDesc.fInfo.fFormat, rtIDDesc) {
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 Salomon27b4d8d2019-07-22 14:23:45 -040063 GrGLGpu* gpu, const GrSurfaceDesc& desc, int sampleCount,
64 const GrGLTexture::IDDesc& texIDDesc, sk_sp<GrGLTextureParameters> parameters,
65 const GrGLRenderTarget::IDDesc& rtIDDesc, GrWrapCacheable cacheable,
66 GrMipMapsStatus mipMapsStatus) {
67 return sk_sp<GrGLTextureRenderTarget>(
68 new GrGLTextureRenderTarget(gpu, desc, sampleCount, texIDDesc, std::move(parameters),
69 rtIDDesc, cacheable, mipMapsStatus));
kkinnunen2e6055b2016-04-22 01:48:29 -070070}
Robert Phillips646e4292017-06-13 12:44:56 -040071
72size_t GrGLTextureRenderTarget::onGpuMemorySize() const {
73 return GrSurface::ComputeSize(this->config(), this->width(), this->height(),
Brian Salomone2826ab2019-06-04 15:58:31 -040074 this->numSamplesOwnedPerPixel(), this->texturePriv().mipMapped());
Robert Phillips646e4292017-06-13 12:44:56 -040075}