2012-09-21 10:44:35 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef WEBGLELEMENTARRAYCACHE_H
|
|
|
|
#define WEBGLELEMENTARRAYCACHE_H
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-07-30 07:25:31 -07:00
|
|
|
#include <stdint.h>
|
2012-09-21 10:44:35 -07:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "GLDefs.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct WebGLElementArrayCacheTree;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WebGLElementArrayCache implements WebGL element array buffer validation for drawElements.
|
|
|
|
*
|
|
|
|
* Its exposes methods meant to be called by WebGL method implementations:
|
|
|
|
* - Validate, to be called by WebGLContext::DrawElements, is where we use the cache
|
|
|
|
* - BufferData and BufferSubData, to be called by eponymous WebGL methods, are how
|
|
|
|
* data is fed into the cache
|
|
|
|
*
|
|
|
|
* Most of the implementation is hidden in the auxilary class template, WebGLElementArrayCacheTree.
|
|
|
|
* Refer to its code for design comments.
|
|
|
|
*/
|
|
|
|
class WebGLElementArrayCache {
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool BufferData(const void* ptr, size_t byteSize);
|
2014-05-09 10:49:27 -07:00
|
|
|
bool BufferSubData(size_t pos, const void* ptr, size_t updateByteSize);
|
2012-09-21 10:44:35 -07:00
|
|
|
|
2014-03-17 07:52:56 -07:00
|
|
|
bool Validate(GLenum type, uint32_t maxAllowed, size_t first, size_t count,
|
|
|
|
uint32_t* out_upperBound = nullptr);
|
2012-09-21 10:44:35 -07:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T Element(size_t i) const { return Elements<T>()[i]; }
|
|
|
|
|
|
|
|
WebGLElementArrayCache()
|
|
|
|
: mUntypedData(nullptr)
|
|
|
|
, mByteSize(0)
|
|
|
|
, mUint8Tree(nullptr)
|
|
|
|
, mUint16Tree(nullptr)
|
2013-05-13 06:22:30 -07:00
|
|
|
, mUint32Tree(nullptr)
|
2012-09-21 10:44:35 -07:00
|
|
|
{}
|
|
|
|
|
|
|
|
~WebGLElementArrayCache();
|
|
|
|
|
2013-06-23 05:03:39 -07:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2012-09-21 10:44:35 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
template<typename T>
|
2014-03-17 07:52:56 -07:00
|
|
|
bool Validate(uint32_t maxAllowed, size_t first, size_t count,
|
|
|
|
uint32_t* out_upperBound);
|
2012-09-21 10:44:35 -07:00
|
|
|
|
|
|
|
size_t ByteSize() const {
|
|
|
|
return mByteSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
const T* Elements() const { return static_cast<const T*>(mUntypedData); }
|
|
|
|
template<typename T>
|
|
|
|
T* Elements() { return static_cast<T*>(mUntypedData); }
|
|
|
|
|
2014-05-09 10:49:27 -07:00
|
|
|
bool UpdateTrees(size_t firstByte, size_t lastByte);
|
2012-09-21 10:44:35 -07:00
|
|
|
|
|
|
|
template<typename T>
|
2012-10-11 15:27:09 -07:00
|
|
|
friend struct WebGLElementArrayCacheTree;
|
2012-09-21 10:44:35 -07:00
|
|
|
template<typename T>
|
|
|
|
friend struct TreeForType;
|
|
|
|
|
|
|
|
void* mUntypedData;
|
|
|
|
size_t mByteSize;
|
|
|
|
WebGLElementArrayCacheTree<uint8_t>* mUint8Tree;
|
|
|
|
WebGLElementArrayCacheTree<uint16_t>* mUint16Tree;
|
2013-05-13 06:22:30 -07:00
|
|
|
WebGLElementArrayCacheTree<uint32_t>* mUint32Tree;
|
2012-09-21 10:44:35 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace mozilla
|
|
|
|
|
|
|
|
#endif // WEBGLELEMENTARRAYCACHE_H
|