content/canvas/src/WebGLBuffer.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "WebGLBuffer.h"
michael@0 7
michael@0 8 #include "GLContext.h"
michael@0 9 #include "mozilla/dom/WebGLRenderingContextBinding.h"
michael@0 10 #include "WebGLContext.h"
michael@0 11 #include "WebGLElementArrayCache.h"
michael@0 12
michael@0 13 using namespace mozilla;
michael@0 14
michael@0 15 WebGLBuffer::WebGLBuffer(WebGLContext *context)
michael@0 16 : WebGLContextBoundObject(context)
michael@0 17 , mHasEverBeenBound(false)
michael@0 18 , mByteLength(0)
michael@0 19 , mTarget(LOCAL_GL_NONE)
michael@0 20 {
michael@0 21 SetIsDOMBinding();
michael@0 22 mContext->MakeContextCurrent();
michael@0 23 mContext->gl->fGenBuffers(1, &mGLName);
michael@0 24 mContext->mBuffers.insertBack(this);
michael@0 25 }
michael@0 26
michael@0 27 WebGLBuffer::~WebGLBuffer() {
michael@0 28 DeleteOnce();
michael@0 29 }
michael@0 30
michael@0 31 void
michael@0 32 WebGLBuffer::Delete() {
michael@0 33 mContext->MakeContextCurrent();
michael@0 34 mContext->gl->fDeleteBuffers(1, &mGLName);
michael@0 35 mByteLength = 0;
michael@0 36 mCache = nullptr;
michael@0 37 LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
michael@0 38 }
michael@0 39
michael@0 40 void
michael@0 41 WebGLBuffer::SetTarget(GLenum target) {
michael@0 42 mTarget = target;
michael@0 43 if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
michael@0 44 mCache = new WebGLElementArrayCache;
michael@0 45 }
michael@0 46
michael@0 47 bool
michael@0 48 WebGLBuffer::ElementArrayCacheBufferData(const void* ptr, size_t buffer_size_in_bytes) {
michael@0 49 if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
michael@0 50 return mCache->BufferData(ptr, buffer_size_in_bytes);
michael@0 51 return true;
michael@0 52 }
michael@0 53
michael@0 54 void
michael@0 55 WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr, size_t update_size_in_bytes) {
michael@0 56 if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
michael@0 57 mCache->BufferSubData(pos, ptr, update_size_in_bytes);
michael@0 58 }
michael@0 59
michael@0 60 size_t
michael@0 61 WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
michael@0 62 {
michael@0 63 size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(aMallocSizeOf) : 0;
michael@0 64 return aMallocSizeOf(this) + sizeOfCache;
michael@0 65 }
michael@0 66
michael@0 67 bool
michael@0 68 WebGLBuffer::Validate(GLenum type, uint32_t max_allowed,
michael@0 69 size_t first, size_t count,
michael@0 70 uint32_t* out_upperBound)
michael@0 71 {
michael@0 72 return mCache->Validate(type, max_allowed, first, count, out_upperBound);
michael@0 73 }
michael@0 74
michael@0 75
michael@0 76 JSObject*
michael@0 77 WebGLBuffer::WrapObject(JSContext *cx) {
michael@0 78 return dom::WebGLBufferBinding::Wrap(cx, this);
michael@0 79 }
michael@0 80
michael@0 81 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
michael@0 82
michael@0 83 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
michael@0 84 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)

mercurial