Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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"
10 #include <stdint.h>
11 #include "nscore.h"
12 #include "GLDefs.h"
14 namespace mozilla {
16 template<typename T>
17 struct WebGLElementArrayCacheTree;
19 /*
20 * WebGLElementArrayCache implements WebGL element array buffer validation for drawElements.
21 *
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
26 *
27 * Most of the implementation is hidden in the auxilary class template, WebGLElementArrayCacheTree.
28 * Refer to its code for design comments.
29 */
30 class WebGLElementArrayCache {
32 public:
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,
37 uint32_t* out_upperBound = nullptr);
39 template<typename T>
40 T Element(size_t i) const { return Elements<T>()[i]; }
42 WebGLElementArrayCache()
43 : mUntypedData(nullptr)
44 , mByteSize(0)
45 , mUint8Tree(nullptr)
46 , mUint16Tree(nullptr)
47 , mUint32Tree(nullptr)
48 {}
50 ~WebGLElementArrayCache();
52 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
54 private:
56 template<typename T>
57 bool Validate(uint32_t maxAllowed, size_t first, size_t count,
58 uint32_t* out_upperBound);
60 size_t ByteSize() const {
61 return mByteSize;
62 }
64 template<typename T>
65 const T* Elements() const { return static_cast<const T*>(mUntypedData); }
66 template<typename T>
67 T* Elements() { return static_cast<T*>(mUntypedData); }
69 void InvalidateTrees(size_t firstByte, size_t lastByte);
71 template<typename T>
72 friend struct WebGLElementArrayCacheTree;
73 template<typename T>
74 friend struct TreeForType;
76 void* mUntypedData;
77 size_t mByteSize;
78 WebGLElementArrayCacheTree<uint8_t>* mUint8Tree;
79 WebGLElementArrayCacheTree<uint16_t>* mUint16Tree;
80 WebGLElementArrayCacheTree<uint32_t>* mUint32Tree;
81 };
84 } // end namespace mozilla
86 #endif // WEBGLELEMENTARRAYCACHE_H