Backed out changeset 58dbd2146e24 (bug 944961) for bustage.
[gecko.git] / content / canvas / src / WebGLBuffer.h
bloba653bd74839b0b47cabc4a01f3ef490492e5376d
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/. */
6 #ifndef WEBGLBUFFER_H_
7 #define WEBGLBUFFER_H_
9 #include "WebGLObjectModel.h"
10 #include "WebGLElementArrayCache.h"
11 #include "GLDefs.h"
13 #include "nsWrapperCache.h"
15 #include "mozilla/LinkedList.h"
16 #include "mozilla/MemoryReporting.h"
18 namespace mozilla {
20 class WebGLElementArrayCache;
22 class WebGLBuffer MOZ_FINAL
23 : public nsWrapperCache
24 , public WebGLRefCountedObject<WebGLBuffer>
25 , public LinkedListElement<WebGLBuffer>
26 , public WebGLContextBoundObject
28 public:
29 WebGLBuffer(WebGLContext *context);
31 ~WebGLBuffer();
33 void Delete();
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 {
59 return Context();
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)
68 protected:
70 GLuint mGLName;
71 bool mHasEverBeenBound;
72 WebGLsizeiptr mByteLength;
73 GLenum mTarget;
75 nsAutoPtr<WebGLElementArrayCache> mCache;
78 #endif //WEBGLBUFFER_H_