2012-10-05 00:35:54 +04: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-21 01:38:20 +04:00
|
|
|
#include "WebGLBuffer.h"
|
2014-03-17 18:52:56 +04:00
|
|
|
|
2013-09-04 16:14:52 +04:00
|
|
|
#include "GLContext.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-03-17 18:52:56 +04:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLElementArrayCache.h"
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
namespace mozilla {
|
2012-10-05 00:35:54 +04:00
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::WebGLBuffer(WebGLContext* webgl, GLuint buf)
|
2015-05-22 08:49:30 +03:00
|
|
|
: WebGLContextBoundObject(webgl)
|
|
|
|
, mGLName(buf)
|
|
|
|
, mTarget(LOCAL_GL_NONE)
|
2012-11-21 01:38:20 +04:00
|
|
|
, mByteLength(0)
|
|
|
|
{
|
|
|
|
mContext->mBuffers.insertBack(this);
|
|
|
|
}
|
|
|
|
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::~WebGLBuffer()
|
|
|
|
{
|
2012-11-21 01:38:20 +04:00
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::Delete()
|
|
|
|
{
|
2012-11-21 01:38:20 +04:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteBuffers(1, &mGLName);
|
|
|
|
mByteLength = 0;
|
|
|
|
mCache = nullptr;
|
|
|
|
LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
|
|
|
|
}
|
|
|
|
|
2015-05-22 08:49:30 +03:00
|
|
|
void
|
|
|
|
WebGLBuffer::BindTo(GLenum target)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(target != LOCAL_GL_NONE, "Can't bind to GL_NONE.");
|
|
|
|
MOZ_ASSERT(!HasEverBeenBound() || mTarget == target, "Rebinding is illegal.");
|
|
|
|
|
|
|
|
bool targetChanged = (target != mTarget);
|
|
|
|
mTarget = target;
|
|
|
|
if (targetChanged)
|
|
|
|
OnTargetChanged();
|
|
|
|
}
|
|
|
|
|
2012-11-21 01:38:20 +04:00
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::OnTargetChanged()
|
|
|
|
{
|
2012-11-21 01:38:20 +04:00
|
|
|
if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
|
|
|
mCache = new WebGLElementArrayCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::ElementArrayCacheBufferData(const void* ptr,
|
|
|
|
size_t bufferSizeInBytes)
|
|
|
|
{
|
2012-11-21 01:38:20 +04:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
2014-11-14 07:03:50 +03:00
|
|
|
return mCache->BufferData(ptr, bufferSizeInBytes);
|
|
|
|
|
2012-11-21 01:38:20 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr,
|
|
|
|
size_t updateSizeInBytes)
|
|
|
|
{
|
2012-11-21 01:38:20 +04:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
2014-11-14 07:03:50 +03:00
|
|
|
mCache->BufferSubData(pos, ptr, updateSizeInBytes);
|
2012-11-21 01:38:20 +04:00
|
|
|
}
|
|
|
|
|
2014-03-17 18:52:56 +04:00
|
|
|
size_t
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
|
2014-03-17 18:52:56 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(mallocSizeOf)
|
|
|
|
: 0;
|
|
|
|
return mallocSizeOf(this) + sizeOfCache;
|
2014-03-17 18:52:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-14 07:03:50 +03:00
|
|
|
WebGLBuffer::Validate(GLenum type, uint32_t maxAllowed, size_t first,
|
|
|
|
size_t count, uint32_t* const out_upperBound)
|
2014-03-17 18:52:56 +04:00
|
|
|
{
|
2014-11-14 07:03:50 +03:00
|
|
|
return mCache->Validate(type, maxAllowed, first, count, out_upperBound);
|
2014-03-17 18:52:56 +04:00
|
|
|
}
|
|
|
|
|
2014-06-03 00:30:00 +04:00
|
|
|
bool
|
|
|
|
WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const
|
|
|
|
{
|
|
|
|
return mCache->BeenUsedWithMultipleTypes();
|
|
|
|
}
|
2014-03-17 18:52:56 +04:00
|
|
|
|
2012-10-05 00:35:54 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
WebGLBuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
|
2014-11-14 07:03:50 +03:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return dom::WebGLBufferBinding::Wrap(cx, this, aGivenProto);
|
2012-10-05 00:35:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
|
|
|
|
|
2013-08-29 19:39:17 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)
|
2014-11-14 07:03:50 +03:00
|
|
|
|
|
|
|
} // namespace mozilla
|