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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef WEBGLELEMENTARRAYCACHE_H |
michael@0 | 7 | #define WEBGLELEMENTARRAYCACHE_H |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/MemoryReporting.h" |
michael@0 | 10 | #include <stdint.h> |
michael@0 | 11 | #include "nscore.h" |
michael@0 | 12 | #include "GLDefs.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace mozilla { |
michael@0 | 15 | |
michael@0 | 16 | template<typename T> |
michael@0 | 17 | struct WebGLElementArrayCacheTree; |
michael@0 | 18 | |
michael@0 | 19 | /* |
michael@0 | 20 | * WebGLElementArrayCache implements WebGL element array buffer validation for drawElements. |
michael@0 | 21 | * |
michael@0 | 22 | * Its exposes methods meant to be called by WebGL method implementations: |
michael@0 | 23 | * - Validate, to be called by WebGLContext::DrawElements, is where we use the cache |
michael@0 | 24 | * - BufferData and BufferSubData, to be called by eponymous WebGL methods, are how |
michael@0 | 25 | * data is fed into the cache |
michael@0 | 26 | * |
michael@0 | 27 | * Most of the implementation is hidden in the auxilary class template, WebGLElementArrayCacheTree. |
michael@0 | 28 | * Refer to its code for design comments. |
michael@0 | 29 | */ |
michael@0 | 30 | class WebGLElementArrayCache { |
michael@0 | 31 | |
michael@0 | 32 | public: |
michael@0 | 33 | bool BufferData(const void* ptr, size_t byteSize); |
michael@0 | 34 | void BufferSubData(size_t pos, const void* ptr, size_t updateByteSize); |
michael@0 | 35 | |
michael@0 | 36 | bool Validate(GLenum type, uint32_t maxAllowed, size_t first, size_t count, |
michael@0 | 37 | uint32_t* out_upperBound = nullptr); |
michael@0 | 38 | |
michael@0 | 39 | template<typename T> |
michael@0 | 40 | T Element(size_t i) const { return Elements<T>()[i]; } |
michael@0 | 41 | |
michael@0 | 42 | WebGLElementArrayCache() |
michael@0 | 43 | : mUntypedData(nullptr) |
michael@0 | 44 | , mByteSize(0) |
michael@0 | 45 | , mUint8Tree(nullptr) |
michael@0 | 46 | , mUint16Tree(nullptr) |
michael@0 | 47 | , mUint32Tree(nullptr) |
michael@0 | 48 | {} |
michael@0 | 49 | |
michael@0 | 50 | ~WebGLElementArrayCache(); |
michael@0 | 51 | |
michael@0 | 52 | size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; |
michael@0 | 53 | |
michael@0 | 54 | private: |
michael@0 | 55 | |
michael@0 | 56 | template<typename T> |
michael@0 | 57 | bool Validate(uint32_t maxAllowed, size_t first, size_t count, |
michael@0 | 58 | uint32_t* out_upperBound); |
michael@0 | 59 | |
michael@0 | 60 | size_t ByteSize() const { |
michael@0 | 61 | return mByteSize; |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | template<typename T> |
michael@0 | 65 | const T* Elements() const { return static_cast<const T*>(mUntypedData); } |
michael@0 | 66 | template<typename T> |
michael@0 | 67 | T* Elements() { return static_cast<T*>(mUntypedData); } |
michael@0 | 68 | |
michael@0 | 69 | void InvalidateTrees(size_t firstByte, size_t lastByte); |
michael@0 | 70 | |
michael@0 | 71 | template<typename T> |
michael@0 | 72 | friend struct WebGLElementArrayCacheTree; |
michael@0 | 73 | template<typename T> |
michael@0 | 74 | friend struct TreeForType; |
michael@0 | 75 | |
michael@0 | 76 | void* mUntypedData; |
michael@0 | 77 | size_t mByteSize; |
michael@0 | 78 | WebGLElementArrayCacheTree<uint8_t>* mUint8Tree; |
michael@0 | 79 | WebGLElementArrayCacheTree<uint16_t>* mUint16Tree; |
michael@0 | 80 | WebGLElementArrayCacheTree<uint32_t>* mUint32Tree; |
michael@0 | 81 | }; |
michael@0 | 82 | |
michael@0 | 83 | |
michael@0 | 84 | } // end namespace mozilla |
michael@0 | 85 | |
michael@0 | 86 | #endif // WEBGLELEMENTARRAYCACHE_H |