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 WEBGLELEMENTARRAYCACHE_H
7 #define WEBGLELEMENTARRAYCACHE_H
9 #include "mozilla/MemoryReporting.h"
17 struct WebGLElementArrayCacheTree
;
20 * WebGLElementArrayCache implements WebGL element array buffer validation for drawElements.
22 * Its exposes methods meant to be called by WebGL method implementations:
23 * - Validate, to be called by WebGLContext::DrawElements, is where we use the cache
24 * - BufferData and BufferSubData, to be called by eponymous WebGL methods, are how
25 * data is fed into the cache
27 * Most of the implementation is hidden in the auxilary class template, WebGLElementArrayCacheTree.
28 * Refer to its code for design comments.
30 class WebGLElementArrayCache
{
33 bool BufferData(const void* ptr
, size_t byteSize
);
34 void BufferSubData(size_t pos
, const void* ptr
, size_t updateByteSize
);
36 bool Validate(GLenum type
, uint32_t maxAllowed
, size_t first
, size_t count
);
39 T
Element(size_t i
) const { return Elements
<T
>()[i
]; }
41 WebGLElementArrayCache()
42 : mUntypedData(nullptr)
45 , mUint16Tree(nullptr)
46 , mUint32Tree(nullptr)
49 ~WebGLElementArrayCache();
51 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf
) const;
56 bool Validate(uint32_t maxAllowed
, size_t first
, size_t count
);
58 size_t ByteSize() const {
63 const T
* Elements() const { return static_cast<const T
*>(mUntypedData
); }
65 T
* Elements() { return static_cast<T
*>(mUntypedData
); }
67 void InvalidateTrees(size_t firstByte
, size_t lastByte
);
70 friend struct WebGLElementArrayCacheTree
;
72 friend struct TreeForType
;
76 WebGLElementArrayCacheTree
<uint8_t>* mUint8Tree
;
77 WebGLElementArrayCacheTree
<uint16_t>* mUint16Tree
;
78 WebGLElementArrayCacheTree
<uint32_t>* mUint32Tree
;
82 } // end namespace mozilla
84 #endif // WEBGLELEMENTARRAYCACHE_H