2012-10-04 13:35:54 -07: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 13:38:20 -08:00
|
|
|
#include "WebGLBuffer.h"
|
2014-03-17 07:52:56 -07:00
|
|
|
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h"
|
2012-10-04 13:35:54 -07:00
|
|
|
#include "mozilla/dom/WebGLRenderingContextBinding.h"
|
2014-03-17 07:52:56 -07:00
|
|
|
#include "WebGLContext.h"
|
|
|
|
#include "WebGLElementArrayCache.h"
|
2012-10-04 13:35:54 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
namespace mozilla {
|
2012-10-04 13:35:54 -07:00
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::WebGLBuffer(WebGLContext* webgl, GLuint buf)
|
2014-11-16 18:21:04 -08:00
|
|
|
: WebGLBindableName<BufferBinding>(buf)
|
2014-11-13 20:03:50 -08:00
|
|
|
, WebGLContextBoundObject(webgl)
|
2012-11-20 13:38:20 -08:00
|
|
|
, mByteLength(0)
|
|
|
|
{
|
|
|
|
mContext->mBuffers.insertBack(this);
|
|
|
|
}
|
|
|
|
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::~WebGLBuffer()
|
|
|
|
{
|
2012-11-20 13:38:20 -08:00
|
|
|
DeleteOnce();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::Delete()
|
|
|
|
{
|
2012-11-20 13:38:20 -08:00
|
|
|
mContext->MakeContextCurrent();
|
|
|
|
mContext->gl->fDeleteBuffers(1, &mGLName);
|
|
|
|
mByteLength = 0;
|
|
|
|
mCache = nullptr;
|
|
|
|
LinkedListElement<WebGLBuffer>::remove(); // remove from mContext->mBuffers
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::OnTargetChanged()
|
|
|
|
{
|
2012-11-20 13:38:20 -08:00
|
|
|
if (!mCache && mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
|
|
|
mCache = new WebGLElementArrayCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::ElementArrayCacheBufferData(const void* ptr,
|
|
|
|
size_t bufferSizeInBytes)
|
|
|
|
{
|
2012-11-20 13:38:20 -08:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
2014-11-13 20:03:50 -08:00
|
|
|
return mCache->BufferData(ptr, bufferSizeInBytes);
|
|
|
|
|
2012-11-20 13:38:20 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::ElementArrayCacheBufferSubData(size_t pos, const void* ptr,
|
|
|
|
size_t updateSizeInBytes)
|
|
|
|
{
|
2012-11-20 13:38:20 -08:00
|
|
|
if (mTarget == LOCAL_GL_ELEMENT_ARRAY_BUFFER)
|
2014-11-13 20:03:50 -08:00
|
|
|
mCache->BufferSubData(pos, ptr, updateSizeInBytes);
|
2012-11-20 13:38:20 -08:00
|
|
|
}
|
|
|
|
|
2014-03-17 07:52:56 -07:00
|
|
|
size_t
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const
|
2014-03-17 07:52:56 -07:00
|
|
|
{
|
2014-11-13 20:03:50 -08:00
|
|
|
size_t sizeOfCache = mCache ? mCache->SizeOfIncludingThis(mallocSizeOf)
|
|
|
|
: 0;
|
|
|
|
return mallocSizeOf(this) + sizeOfCache;
|
2014-03-17 07:52:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-13 20:03:50 -08:00
|
|
|
WebGLBuffer::Validate(GLenum type, uint32_t maxAllowed, size_t first,
|
|
|
|
size_t count, uint32_t* const out_upperBound)
|
2014-03-17 07:52:56 -07:00
|
|
|
{
|
2014-11-13 20:03:50 -08:00
|
|
|
return mCache->Validate(type, maxAllowed, first, count, out_upperBound);
|
2014-03-17 07:52:56 -07:00
|
|
|
}
|
|
|
|
|
2014-06-02 13:30:00 -07:00
|
|
|
bool
|
|
|
|
WebGLBuffer::IsElementArrayUsedWithMultipleTypes() const
|
|
|
|
{
|
|
|
|
return mCache->BeenUsedWithMultipleTypes();
|
|
|
|
}
|
2014-03-17 07:52:56 -07:00
|
|
|
|
2012-10-04 13:35:54 -07: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 07:13:33 -07:00
|
|
|
WebGLBuffer::WrapObject(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
|
2014-11-13 20:03:50 -08: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 07:13:33 -07:00
|
|
|
return dom::WebGLBufferBinding::Wrap(cx, this, aGivenProto);
|
2012-10-04 13:35:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(WebGLBuffer)
|
|
|
|
|
2013-08-29 08:39:17 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(WebGLBuffer, AddRef)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(WebGLBuffer, Release)
|
2014-11-13 20:03:50 -08:00
|
|
|
|
|
|
|
} // namespace mozilla
|