Bumping manifests a=b2g-bump
[gecko.git] / dom / canvas / WebGLElementArrayCache.h
blob3ff2eac005fea14ea3ab5907622a5cd6b9fa291d
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 WEBGL_ELEMENT_ARRAY_CACHE_H
7 #define WEBGL_ELEMENT_ARRAY_CACHE_H
9 #include "GLDefs.h"
10 #include "mozilla/MemoryReporting.h"
11 #include "mozilla/Scoped.h"
12 #include "nscore.h"
13 #include "nsTArray.h"
14 #include <stdint.h>
16 namespace mozilla {
18 template<typename T>
19 struct WebGLElementArrayCacheTree;
21 /* WebGLElementArrayCache implements WebGL element array buffer validation for
22 * drawElements.
24 * Its exposes methods meant to be called by WebGL method implementations:
26 * - Validate, to be called by WebGLContext::DrawElements, is where we use the
27 * cache.
29 * - BufferData and BufferSubData, to be called by eponymous WebGL methods, are
30 * how data is fed into the cache.
32 * Most of the implementation is hidden in the auxilary class template,
33 * WebGLElementArrayCacheTree. Refer to its code for design comments.
35 class WebGLElementArrayCache {
36 public:
37 bool BufferData(const void* ptr, size_t byteLength);
38 bool BufferSubData(size_t pos, const void* ptr, size_t updateByteSize);
40 bool Validate(GLenum type, uint32_t maxAllowed, size_t first, size_t count,
41 uint32_t* const out_upperBound);
43 template<typename T>
44 T Element(size_t i) const { return Elements<T>()[i]; }
46 WebGLElementArrayCache();
47 ~WebGLElementArrayCache();
49 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
50 bool BeenUsedWithMultipleTypes() const;
52 private:
53 /* Returns true if a drawElements call with the given parameters should
54 * succeed, false otherwise.
56 * In other words, this returns true if all entries in the element array at
57 * positions:
59 * first .. first+count-1
61 * are less than or equal to maxAllowed.
63 * Input parameters:
64 * maxAllowed: Maximum value to be allowed in the specificied portion of
65 * the element array.
66 * first: Start of the portion of the element array to consume.
67 * count: Number of entries from the element array to consume.
69 * Output parameter:
70 * out_upperBound: Upon success, is set to the actual maximum value in the
71 * specified range, which is then guaranteed to be less
72 * than or equal to maxAllowed. upon failure, is set to
73 * the first value in the specified range, that is greater
74 * than maxAllowed.
76 template<typename T>
77 bool Validate(uint32_t maxAllowed, size_t first, size_t count,
78 uint32_t* const out_upperBound);
80 template<typename T>
81 const T* Elements() const {
82 return reinterpret_cast<const T*>(mBytes.Elements());
85 template<typename T>
86 T* Elements() { return reinterpret_cast<T*>(mBytes.Elements()); }
88 bool UpdateTrees(size_t firstByte, size_t lastByte);
90 template<typename T>
91 friend struct WebGLElementArrayCacheTree;
92 template<typename T>
93 friend struct TreeForType;
95 FallibleTArray<uint8_t> mBytes;
96 ScopedDeletePtr<WebGLElementArrayCacheTree<uint8_t>> mUint8Tree;
97 ScopedDeletePtr<WebGLElementArrayCacheTree<uint16_t>> mUint16Tree;
98 ScopedDeletePtr<WebGLElementArrayCacheTree<uint32_t>> mUint32Tree;
101 } // end namespace mozilla
103 #endif // WEBGL_ELEMENT_ARRAY_CACHE_H