content/canvas/src/WebGLBuffer.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLBuffer.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "WebGLBuffer.h"
    1.10 +
    1.11 +#include "GLContext.h"
    1.12 +#include "mozilla/dom/WebGLRenderingContextBinding.h"
    1.13 +#include "WebGLContext.h"
    1.14 +#include "WebGLElementArrayCache.h"
    1.15 +
    1.16 +using namespace mozilla;
    1.17 +
    1.18 +WebGLBuffer::WebGLBuffer(WebGLContext *context)
    1.19 +    : WebGLContextBoundObject(context)
    1.20 +    , mHasEverBeenBound(false)
    1.21 +    , mByteLength(0)
    1.22 +    , mTarget(LOCAL_GL_NONE)
    1.23 +{
    1.24 +    SetIsDOMBinding();
    1.25 +    mContext->MakeContextCurrent();
    1.26 +    mContext->gl->fGenBuffers(1, &mGLName);
    1.27 +    mContext->mBuffers.insertBack(this);
    1.28 +}
    1.29 +
    1.30 +WebGLBuffer::~WebGLBuffer() {
    1.31 +    DeleteOnce();
    1.32 +}
    1.33 +
    1.34 +void
    1.35 +WebGLBuffer::Delete() {
    1.36 +    mContext->MakeContextCurrent();
    1.37 +    mContext->gl->fDeleteBuffers(1, &mGLName);
    1.38 +    mByteLength = 0;
    1.39 +    mCache = nullptr;
    1.40 +    LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
    1.41 +}
    1.42 +
    1.43 +void
    1.44 +WebGLBuffer::SetTarget(GLenum target) {
    1.45 +    mTarget = target;
    1.46 +    if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
    1.47 +        mCache = new WebGLElementArrayCache;
    1.48 +}
    1.49 +
    1.50 +bool
    1.51 +WebGLBuffer::ElementArrayCacheBufferData(const void* ptr, size_t buffer_size_in_bytes) {
    1.52 +    if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
    1.53 +        return mCache->BufferData(ptr, buffer_size_in_bytes);
    1.54 +    return true;
    1.55 +}
    1.56 +
    1.57 +void
    1.58 +WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr, size_t update_size_in_bytes) {
    1.59 +    if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
    1.60 +        mCache->BufferSubData(pos, ptr, update_size_in_bytes);
    1.61 +}
    1.62 +
    1.63 +size_t
    1.64 +WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
    1.65 +{
    1.66 +    size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(aMallocSizeOf) : 0;
    1.67 +    return aMallocSizeOf(this) + sizeOfCache;
    1.68 +}
    1.69 +
    1.70 +bool
    1.71 +WebGLBuffer::Validate(GLenum type, uint32_t max_allowed,
    1.72 +                      size_t first, size_t count,
    1.73 +                      uint32_t* out_upperBound)
    1.74 +{
    1.75 +    return mCache->Validate(type, max_allowed, first, count, out_upperBound);
    1.76 +}
    1.77 +
    1.78 +
    1.79 +JSObject*
    1.80 +WebGLBuffer::WrapObject(JSContext *cx) {
    1.81 +    return dom::WebGLBufferBinding::Wrap(cx, this);
    1.82 +}
    1.83 +
    1.84 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
    1.85 +
    1.86 +NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
    1.87 +NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)

mercurial