1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci#include "src/gpu/gl/GrGLTextureRenderTarget.h"
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ci#include "include/core/SkTraceMemoryDump.h"
11cb93a386Sopenharmony_ci#include "include/gpu/GrDirectContext.h"
12cb93a386Sopenharmony_ci#include "src/gpu/GrDirectContextPriv.h"
13cb93a386Sopenharmony_ci#include "src/gpu/GrTexture.h"
14cb93a386Sopenharmony_ci#include "src/gpu/gl/GrGLGpu.h"
15cb93a386Sopenharmony_ci
16cb93a386Sopenharmony_ciGrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
17cb93a386Sopenharmony_ci                                                 SkBudgeted budgeted,
18cb93a386Sopenharmony_ci                                                 int sampleCount,
19cb93a386Sopenharmony_ci                                                 const GrGLTexture::Desc& texDesc,
20cb93a386Sopenharmony_ci                                                 const GrGLRenderTarget::IDs& rtIDs,
21cb93a386Sopenharmony_ci                                                 GrMipmapStatus mipmapStatus)
22cb93a386Sopenharmony_ci        : GrSurface(gpu, texDesc.fSize, GrProtected::kNo)
23cb93a386Sopenharmony_ci        , GrGLTexture(gpu, texDesc, nullptr, mipmapStatus)
24cb93a386Sopenharmony_ci        , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount, rtIDs) {
25cb93a386Sopenharmony_ci    this->registerWithCache(budgeted);
26cb93a386Sopenharmony_ci}
27cb93a386Sopenharmony_ci
28cb93a386Sopenharmony_ciGrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu,
29cb93a386Sopenharmony_ci                                                 int sampleCount,
30cb93a386Sopenharmony_ci                                                 const GrGLTexture::Desc& texDesc,
31cb93a386Sopenharmony_ci                                                 sk_sp<GrGLTextureParameters> parameters,
32cb93a386Sopenharmony_ci                                                 const GrGLRenderTarget::IDs& rtIDs,
33cb93a386Sopenharmony_ci                                                 GrWrapCacheable cacheable,
34cb93a386Sopenharmony_ci                                                 GrMipmapStatus mipmapStatus)
35cb93a386Sopenharmony_ci        : GrSurface(gpu, texDesc.fSize, GrProtected::kNo)
36cb93a386Sopenharmony_ci        , GrGLTexture(gpu, texDesc, std::move(parameters), mipmapStatus)
37cb93a386Sopenharmony_ci        , GrGLRenderTarget(gpu, texDesc.fSize, texDesc.fFormat, sampleCount,
38cb93a386Sopenharmony_ci                           rtIDs) {
39cb93a386Sopenharmony_ci    this->registerWithCacheWrapped(cacheable);
40cb93a386Sopenharmony_ci}
41cb93a386Sopenharmony_ci
42cb93a386Sopenharmony_civoid GrGLTextureRenderTarget::dumpMemoryStatistics(
43cb93a386Sopenharmony_ci    SkTraceMemoryDump* traceMemoryDump) const {
44cb93a386Sopenharmony_ci#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
45cb93a386Sopenharmony_ci    // Delegate to the base classes
46cb93a386Sopenharmony_ci    GrGLRenderTarget::dumpMemoryStatistics(traceMemoryDump);
47cb93a386Sopenharmony_ci    GrGLTexture::dumpMemoryStatistics(traceMemoryDump);
48cb93a386Sopenharmony_ci#else
49cb93a386Sopenharmony_ci    SkString resourceName = this->getResourceName();
50cb93a386Sopenharmony_ci    resourceName.append("/texture_renderbuffer");
51cb93a386Sopenharmony_ci    this->dumpMemoryStatisticsPriv(traceMemoryDump, resourceName, "RenderTarget",
52cb93a386Sopenharmony_ci                                   this->gpuMemorySize());
53cb93a386Sopenharmony_ci#endif
54cb93a386Sopenharmony_ci}
55cb93a386Sopenharmony_ci
56cb93a386Sopenharmony_cibool GrGLTextureRenderTarget::canAttemptStencilAttachment(bool useMultisampleFBO) const {
57cb93a386Sopenharmony_ci    // This cap should have been handled at a higher level.
58cb93a386Sopenharmony_ci    SkASSERT(!this->getGpu()->getContext()->priv().caps()->avoidStencilBuffers());
59cb93a386Sopenharmony_ci    // The RT FBO of GrGLTextureRenderTarget is never created from a wrapped FBO.
60cb93a386Sopenharmony_ci    return true;
61cb93a386Sopenharmony_ci}
62cb93a386Sopenharmony_ci
63cb93a386Sopenharmony_cisk_sp<GrGLTextureRenderTarget> GrGLTextureRenderTarget::MakeWrapped(
64cb93a386Sopenharmony_ci        GrGLGpu* gpu,
65cb93a386Sopenharmony_ci        int sampleCount,
66cb93a386Sopenharmony_ci        const GrGLTexture::Desc& texDesc,
67cb93a386Sopenharmony_ci        sk_sp<GrGLTextureParameters> parameters,
68cb93a386Sopenharmony_ci        const GrGLRenderTarget::IDs& rtIDs,
69cb93a386Sopenharmony_ci        GrWrapCacheable cacheable,
70cb93a386Sopenharmony_ci        GrMipmapStatus mipmapStatus) {
71cb93a386Sopenharmony_ci    return sk_sp<GrGLTextureRenderTarget>(new GrGLTextureRenderTarget(
72cb93a386Sopenharmony_ci            gpu, sampleCount, texDesc, std::move(parameters), rtIDs, cacheable, mipmapStatus));
73cb93a386Sopenharmony_ci}
74cb93a386Sopenharmony_ci
75cb93a386Sopenharmony_cisize_t GrGLTextureRenderTarget::onGpuMemorySize() const {
76cb93a386Sopenharmony_ci    return GrSurface::ComputeSize(this->backendFormat(), this->dimensions(),
77cb93a386Sopenharmony_ci                                  this->totalMemorySamplesPerPixel(), this->mipmapped());
78cb93a386Sopenharmony_ci}
79