2012-10-04 20:35:54 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-11-20 21:38:20 +00:00
|
|
|
#include "WebGLBuffer.h"
|
2014-03-17 14:52:56 +00:00
|
|
|
|
2013-09-04 12:14:52 +00:00
|
|
|
#include "GLContext.h"
|
2012-10-04 20:35:54 +00:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-03-17 14:52:56 +00:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLElementArrayCache.h"
|
2012-10-04 20:35:54 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
namespace mozilla {
|
2012-10-04 20:35:54 +00:00
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::WebGLBuffer(WebGLContext* webgl, GLuint buf)
|
2014-11-17 02:21:04 +00:00
|
|
|
: WebGLBindableName<BufferBinding>(buf)
|
2014-11-14 04:03:50 +00:00
|
|
|
, WebGLContextBoundObject(webgl)
|
2012-11-20 21:38:20 +00:00
|
|
|
, mByteLength(0)
|
|
|
|
{
|
|
|
|
mContext->mBuffers.insertBack(this);
|
|
|
|
}
|
|
|
|
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::~WebGLBuffer()
|
|
|
|
{
|
2012-11-20 21:38:20 +00:00
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::Delete()
|
|
|
|
{
|
2012-11-20 21:38:20 +00:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteBuffers(1, &mGLName);
|
|
|
|
mByteLength = 0;
|
|
|
|
mCache = nullptr;
|
|
|
|
LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::OnTargetChanged()
|
|
|
|
{
|
2012-11-20 21:38:20 +00:00
|
|
|
if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
|
|
|
mCache = new WebGLElementArrayCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::ElementArrayCacheBufferData(const void* ptr,
|
|
|
|
size_t bufferSizeInBytes)
|
|
|
|
{
|
2012-11-20 21:38:20 +00:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
2014-11-14 04:03:50 +00:00
|
|
|
return mCache->BufferData(ptr, bufferSizeInBytes);
|
|
|
|
|
2012-11-20 21:38:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr,
|
|
|
|
size_t updateSizeInBytes)
|
|
|
|
{
|
2012-11-20 21:38:20 +00:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
2014-11-14 04:03:50 +00:00
|
|
|
mCache->BufferSubData(pos, ptr, updateSizeInBytes);
|
2012-11-20 21:38:20 +00:00
|
|
|
}
|
|
|
|
|
2014-03-17 14:52:56 +00:00
|
|
|
size_t
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
|
2014-03-17 14:52:56 +00:00
|
|
|
{
|
2014-11-14 04:03:50 +00:00
|
|
|
size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(mallocSizeOf)
|
|
|
|
: 0;
|
|
|
|
return mallocSizeOf(this) + sizeOfCache;
|
2014-03-17 14:52:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::Validate(GLenum type, uint32_t maxAllowed, size_t first,
|
|
|
|
size_t count, uint32_t* const out_upperBound)
|
2014-03-17 14:52:56 +00:00
|
|
|
{
|
2014-11-14 04:03:50 +00:00
|
|
|
return mCache->Validate(type, maxAllowed, first, count, out_upperBound);
|
2014-03-17 14:52:56 +00:00
|
|
|
}
|
|
|
|
|
2014-06-02 20:30:00 +00:00
|
|
|
bool
|
|
|
|
WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const
|
|
|
|
{
|
|
|
|
return mCache->BeenUsedWithMultipleTypes();
|
|
|
|
}
|
2014-03-17 14:52:56 +00:00
|
|
|
|
2012-10-04 20:35:54 +00:00
|
|
|
JSObject*
|
2014-11-14 04:03:50 +00:00
|
|
|
WebGLBuffer::WrapObject(JSContext* cx)
|
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 22:27:17 +00:00
|
|
|
return dom::WebGLBufferBinding::Wrap(cx, this);
|
2012-10-04 20:35:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
|
|
|
|
|
2013-08-29 15:39:17 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)
|
2014-11-14 04:03:50 +00:00
|
|
|
|
|
|
|
} // namespace mozilla
|