1 /* -*- Mode: C++; tab-width: 4; 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/. */
9 #include "WebGLObjectModel.h"
10 #include "WebGLElementArrayCache.h"
13 #include "nsWrapperCache.h"
15 #include "mozilla/LinkedList.h"
16 #include "mozilla/MemoryReporting.h"
20 class WebGLElementArrayCache
;
22 class WebGLBuffer MOZ_FINAL
23 : public nsWrapperCache
24 , public WebGLRefCountedObject
<WebGLBuffer
>
25 , public LinkedListElement
<WebGLBuffer
>
26 , public WebGLContextBoundObject
29 WebGLBuffer(WebGLContext
*context
);
35 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const {
36 size_t sizeOfCache
= mCache
? mCache
->SizeOfIncludingThis(aMallocSizeOf
) : 0;
37 return aMallocSizeOf(this) + sizeOfCache
;
40 bool HasEverBeenBound() { return mHasEverBeenBound
; }
41 void SetHasEverBeenBound(bool x
) { mHasEverBeenBound
= x
; }
42 GLuint
GLName() const { return mGLName
; }
43 WebGLsizeiptr
ByteLength() const { return mByteLength
; }
44 GLenum
Target() const { return mTarget
; }
46 void SetByteLength(WebGLsizeiptr byteLength
) { mByteLength
= byteLength
; }
48 void SetTarget(GLenum target
);
50 bool ElementArrayCacheBufferData(const void* ptr
, size_t buffer_size_in_bytes
);
52 void ElementArrayCacheBufferSubData(size_t pos
, const void* ptr
, size_t update_size_in_bytes
);
54 bool Validate(GLenum type
, uint32_t max_allowed
, size_t first
, size_t count
) {
55 return mCache
->Validate(type
, max_allowed
, first
, count
);
58 WebGLContext
*GetParentObject() const {
62 virtual JSObject
* WrapObject(JSContext
*cx
,
63 JS::Handle
<JSObject
*> scope
) MOZ_OVERRIDE
;
65 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGLBuffer
)
66 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(WebGLBuffer
)
71 bool mHasEverBeenBound
;
72 WebGLsizeiptr mByteLength
;
75 nsAutoPtr
<WebGLElementArrayCache
> mCache
;
78 #endif //WEBGLBUFFER_H_