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.)

     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     : WebGLContextBoundObject(context)
    17     , mHasEverBeenBound(false)
    18     , mByteLength(0)
    19     , mTarget(LOCAL_GL_NONE)
    20 {
    21     SetIsDOMBinding();
    22     mContext->MakeContextCurrent();
    23     mContext->gl->fGenBuffers(1, &mGLName);
    24     mContext->mBuffers.insertBack(this);
    25 }
    27 WebGLBuffer::~WebGLBuffer() {
    28     DeleteOnce();
    29 }
    31 void
    32 WebGLBuffer::Delete() {
    33     mContext->MakeContextCurrent();
    34     mContext->gl->fDeleteBuffers(1, &mGLName);
    35     mByteLength = 0;
    36     mCache = nullptr;
    37     LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
    38 }
    40 void
    41 WebGLBuffer::SetTarget(GLenum target) {
    42     mTarget = target;
    43     if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
    44         mCache = new WebGLElementArrayCache;
    45 }
    47 bool
    48 WebGLBuffer::ElementArrayCacheBufferData(const void* ptr, size_t buffer_size_in_bytes) {
    49     if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
    50         return mCache->BufferData(ptr, buffer_size_in_bytes);
    51     return true;
    52 }
    54 void
    55 WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr, size_t update_size_in_bytes) {
    56     if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
    57         mCache->BufferSubData(pos, ptr, update_size_in_bytes);
    58 }
    60 size_t
    61 WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
    62 {
    63     size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(aMallocSizeOf) : 0;
    64     return aMallocSizeOf(this) + sizeOfCache;
    65 }
    67 bool
    68 WebGLBuffer::Validate(GLenum type, uint32_t max_allowed,
    69                       size_t first, size_t count,
    70                       uint32_t* out_upperBound)
    71 {
    72     return mCache->Validate(type, max_allowed, first, count, out_upperBound);
    73 }
    76 JSObject*
    77 WebGLBuffer::WrapObject(JSContext *cx) {
    78     return dom::WebGLBufferBinding::Wrap(cx, this);
    79 }
    81 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
    83 NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
    84 NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)

mercurial