bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 1 | /* |
| 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 Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 8 | #include "src/gpu/gl/GrGLAttachment.h" |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/core/SkTraceMemoryDump.h" |
| 11 | #include "src/gpu/gl/GrGLGpu.h" |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 12 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 13 | size_t GrGLAttachment::onGpuMemorySize() const { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 14 | uint64_t size = this->width(); |
| 15 | size *= this->height(); |
Greg Daniel | 8ade5e8 | 2020-10-07 13:09:48 -0400 | [diff] [blame] | 16 | size *= GrGLFormatBytesPerBlock(fFormat); |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 17 | size *= this->numSamples(); |
Greg Daniel | 8ade5e8 | 2020-10-07 13:09:48 -0400 | [diff] [blame] | 18 | return static_cast<size_t>(size); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 21 | void GrGLAttachment::onRelease() { |
kkinnunen | 2e6055b | 2016-04-22 01:48:29 -0700 | [diff] [blame] | 22 | if (0 != fRenderbufferID) { |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 23 | GrGLGpu* gpuGL = (GrGLGpu*)this->getGpu(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 24 | const GrGLInterface* gl = gpuGL->glInterface(); |
| 25 | GR_GL_CALL(gl, DeleteRenderbuffers(1, &fRenderbufferID)); |
| 26 | fRenderbufferID = 0; |
| 27 | } |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 28 | |
| 29 | INHERITED::onRelease(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 30 | } |
| 31 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 32 | void GrGLAttachment::onAbandon() { |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 33 | fRenderbufferID = 0; |
robertphillips@google.com | d364554 | 2012-09-05 18:37:39 +0000 | [diff] [blame] | 34 | |
| 35 | INHERITED::onAbandon(); |
bsalomon@google.com | 0b77d68 | 2011-08-19 13:28:54 +0000 | [diff] [blame] | 36 | } |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 37 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 38 | GrBackendFormat GrGLAttachment::backendFormat() const { |
Greg Daniel | 8ade5e8 | 2020-10-07 13:09:48 -0400 | [diff] [blame] | 39 | return GrBackendFormat::MakeGL(GrGLFormatToEnum(fFormat), GR_GL_TEXTURE_NONE); |
Greg Daniel | e77162e | 2020-09-21 15:32:11 -0400 | [diff] [blame] | 40 | } |
| 41 | |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 42 | void GrGLAttachment::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump, |
| 43 | const SkString& dumpName) const { |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 44 | SkString renderbuffer_id; |
| 45 | renderbuffer_id.appendU32(this->renderbufferID()); |
Greg Daniel | c0d6915 | 2020-10-08 14:59:00 -0400 | [diff] [blame^] | 46 | traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_renderbuffer", renderbuffer_id.c_str()); |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 47 | } |