blob: d6bdaaf603d1db9ad90e4062fb58863c488fb613 [file] [log] [blame]
bsalomon@google.com0b77d682011-08-19 13:28:54 +00001/*
2 * Copyright 2011 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
Greg Danielc0d69152020-10-08 14:59:00 -04008#include "src/gpu/gl/GrGLAttachment.h"
bsalomon@google.com0b77d682011-08-19 13:28:54 +00009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "include/core/SkTraceMemoryDump.h"
11#include "src/gpu/gl/GrGLGpu.h"
bsalomon@google.com0b77d682011-08-19 13:28:54 +000012
Greg Danielc0d69152020-10-08 14:59:00 -040013size_t GrGLAttachment::onGpuMemorySize() const {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000014 uint64_t size = this->width();
15 size *= this->height();
Greg Daniel8ade5e82020-10-07 13:09:48 -040016 size *= GrGLFormatBytesPerBlock(fFormat);
Brian Salomonbdecacf2018-02-02 20:32:49 -050017 size *= this->numSamples();
Greg Daniel8ade5e82020-10-07 13:09:48 -040018 return static_cast<size_t>(size);
bsalomon@google.com0b77d682011-08-19 13:28:54 +000019}
20
Greg Danielc0d69152020-10-08 14:59:00 -040021void GrGLAttachment::onRelease() {
kkinnunen2e6055b2016-04-22 01:48:29 -070022 if (0 != fRenderbufferID) {
Greg Danielc0d69152020-10-08 14:59:00 -040023 GrGLGpu* gpuGL = (GrGLGpu*)this->getGpu();
bsalomon@google.com0b77d682011-08-19 13:28:54 +000024 const GrGLInterface* gl = gpuGL->glInterface();
25 GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID));
26 fRenderbufferID = 0;
27 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000028
29 INHERITED::onRelease();
bsalomon@google.com0b77d682011-08-19 13:28:54 +000030}
31
Greg Danielc0d69152020-10-08 14:59:00 -040032void GrGLAttachment::onAbandon() {
bsalomon@google.com0b77d682011-08-19 13:28:54 +000033 fRenderbufferID = 0;
robertphillips@google.comd3645542012-09-05 18:37:39 +000034
35 INHERITED::onAbandon();
bsalomon@google.com0b77d682011-08-19 13:28:54 +000036}
ericrk0a5fa482015-09-15 14:16:10 -070037
Greg Danielc0d69152020-10-08 14:59:00 -040038GrBackendFormat GrGLAttachment::backendFormat() const {
Greg Daniel8ade5e82020-10-07 13:09:48 -040039 return GrBackendFormat::MakeGL(GrGLFormatToEnum(fFormat), GR_GL_TEXTURE_NONE);
Greg Daniele77162e2020-09-21 15:32:11 -040040}
41
Greg Danielc0d69152020-10-08 14:59:00 -040042void GrGLAttachment::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
43 const SkString& dumpName) const {
ericrk0a5fa482015-09-15 14:16:10 -070044 SkString renderbuffer_id;
45 renderbuffer_id.appendU32(this->renderbufferID());
Greg Danielc0d69152020-10-08 14:59:00 -040046 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer", renderbuffer_id.c_str());
ericrk0a5fa482015-09-15 14:16:10 -070047}