Bumping gaia.json for 1 gaia revision(s) a=gaia-bump
[gecko.git] / dom / canvas / WebGLBuffer.cpp
blob061404d0d481a2570041b48212485353d18b21c2
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "WebGLBuffer.h"
8 #include "GLContext.h"
9 #include "mozilla/dom/WebGLRenderingContextBinding.h"
10 #include "WebGLContext.h"
11 #include "WebGLElementArrayCache.h"
13 using namespace mozilla;
15 WebGLBuffer::WebGLBuffer(WebGLContext *context)
16 : WebGLBindableName()
17 , WebGLContextBoundObject(context)
18 , mByteLength(0)
20 SetIsDOMBinding();
21 mContext->MakeContextCurrent();
22 mContext->gl->fGenBuffers(1, &mGLName);
23 mContext->mBuffers.insertBack(this);
26 WebGLBuffer::~WebGLBuffer() {
27 DeleteOnce();
30 void
31 WebGLBuffer::Delete() {
32 mContext->MakeContextCurrent();
33 mContext->gl->fDeleteBuffers(1, &mGLName);
34 mByteLength = 0;
35 mCache = nullptr;
36 LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
39 void
40 WebGLBuffer::OnTargetChanged() {
41 if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
42 mCache = new WebGLElementArrayCache;
45 bool
46 WebGLBuffer::ElementArrayCacheBufferData(const void* ptr, size_t buffer_size_in_bytes) {
47 if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
48 return mCache->BufferData(ptr, buffer_size_in_bytes);
49 return true;
52 void
53 WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr, size_t update_size_in_bytes) {
54 if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
55 mCache->BufferSubData(pos, ptr, update_size_in_bytes);
58 size_t
59 WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
61 size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(aMallocSizeOf) : 0;
62 return aMallocSizeOf(this) + sizeOfCache;
65 bool
66 WebGLBuffer::Validate(GLenum type, uint32_t max_allowed,
67 size_t first, size_t count,
68 uint32_t* out_upperBound)
70 return mCache->Validate(type, max_allowed, first, count, out_upperBound);
73 bool
74 WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const
76 return mCache->BeenUsedWithMultipleTypes();
79 JSObject*
80 WebGLBuffer::WrapObject(JSContext *cx) {
81 return dom::WebGLBufferBinding::Wrap(cx, this);
84 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
86 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
87 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)