blob: 5a794ad8240659a61957e0622837447022a5f2e1 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#include "GrGLIndexBuffer.h"
jvanverth39edf762014-12-22 11:44:19 -08009#include "GrGLGpu.h"
ericrk0a5fa482015-09-15 14:16:10 -070010#include "SkTraceMemoryDump.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000011
bsalomon861e1032014-12-16 07:33:49 -080012GrGLIndexBuffer::GrGLIndexBuffer(GrGLGpu* gpu, const Desc& desc)
jvanverth73063dc2015-12-03 09:15:47 -080013 : INHERITED(gpu, desc.fSizeInBytes, GrGLBufferImpl::kDynamicDraw_Usage == desc.fUsage,
14 0 == desc.fID)
bsalomon@google.come49ad452013-02-20 19:33:20 +000015 , fImpl(gpu, desc, GR_GL_ELEMENT_ARRAY_BUFFER) {
bsalomon16961262014-08-26 14:01:07 -070016 this->registerWithCache();
reed@google.comac10a2d2010-12-22 21:39:39 +000017}
18
bsalomon@google.com8fe72472011-03-30 21:26:44 +000019void GrGLIndexBuffer::onRelease() {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000020 if (!this->wasDestroyed()) {
bsalomon@google.come49ad452013-02-20 19:33:20 +000021 fImpl.release(this->getGpuGL());
reed@google.comac10a2d2010-12-22 21:39:39 +000022 }
robertphillips@google.comd3645542012-09-05 18:37:39 +000023
24 INHERITED::onRelease();
reed@google.comac10a2d2010-12-22 21:39:39 +000025}
26
bsalomon@google.com8fe72472011-03-30 21:26:44 +000027void GrGLIndexBuffer::onAbandon() {
bsalomon@google.come49ad452013-02-20 19:33:20 +000028 fImpl.abandon();
robertphillips@google.comd3645542012-09-05 18:37:39 +000029 INHERITED::onAbandon();
bsalomon@google.com8fe72472011-03-30 21:26:44 +000030}
31
commit-bot@chromium.orge529a612014-05-08 18:13:23 +000032void* GrGLIndexBuffer::onMap() {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000033 if (!this->wasDestroyed()) {
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000034 return fImpl.map(this->getGpuGL());
bsalomon@google.come49ad452013-02-20 19:33:20 +000035 } else {
halcanary96fcdcc2015-08-27 07:41:13 -070036 return nullptr;
reed@google.comac10a2d2010-12-22 21:39:39 +000037 }
reed@google.comac10a2d2010-12-22 21:39:39 +000038}
39
commit-bot@chromium.orge529a612014-05-08 18:13:23 +000040void GrGLIndexBuffer::onUnmap() {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000041 if (!this->wasDestroyed()) {
commit-bot@chromium.org8341eb72014-05-07 20:51:05 +000042 fImpl.unmap(this->getGpuGL());
bsalomon@google.come49ad452013-02-20 19:33:20 +000043 }
reed@google.comac10a2d2010-12-22 21:39:39 +000044}
45
commit-bot@chromium.orge529a612014-05-08 18:13:23 +000046bool GrGLIndexBuffer::onUpdateData(const void* src, size_t srcSizeInBytes) {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000047 if (!this->wasDestroyed()) {
bsalomon@google.come49ad452013-02-20 19:33:20 +000048 return fImpl.updateData(this->getGpuGL(), src, srcSizeInBytes);
49 } else {
reed@google.comac10a2d2010-12-22 21:39:39 +000050 return false;
51 }
reed@google.comac10a2d2010-12-22 21:39:39 +000052}
ericrk0a5fa482015-09-15 14:16:10 -070053
54void GrGLIndexBuffer::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
55 const SkString& dumpName) const {
56 SkString buffer_id;
57 buffer_id.appendU32(this->bufferID());
58 traceMemoryDump->setMemoryBacking(dumpName.c_str(), "gl_buffer",
59 buffer_id.c_str());
60}