content/canvas/src/WebGLElementArrayCache.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/canvas/src/WebGLElementArrayCache.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef WEBGLELEMENTARRAYCACHE_H
    1.10 +#define WEBGLELEMENTARRAYCACHE_H
    1.11 +
    1.12 +#include "mozilla/MemoryReporting.h"
    1.13 +#include <stdint.h>
    1.14 +#include "nscore.h"
    1.15 +#include "GLDefs.h"
    1.16 +
    1.17 +namespace mozilla {
    1.18 +
    1.19 +template<typename T>
    1.20 +struct WebGLElementArrayCacheTree;
    1.21 +
    1.22 +/*
    1.23 + * WebGLElementArrayCache implements WebGL element array buffer validation for drawElements.
    1.24 + *
    1.25 + * Its exposes methods meant to be called by WebGL method implementations:
    1.26 + *  - Validate, to be called by WebGLContext::DrawElements, is where we use the cache
    1.27 + *  - BufferData and BufferSubData, to be called by eponymous WebGL methods, are how
    1.28 + *    data is fed into the cache
    1.29 + *
    1.30 + * Most of the implementation is hidden in the auxilary class template, WebGLElementArrayCacheTree.
    1.31 + * Refer to its code for design comments.
    1.32 + */
    1.33 +class WebGLElementArrayCache {
    1.34 +
    1.35 +public:
    1.36 +  bool BufferData(const void* ptr, size_t byteSize);
    1.37 +  void BufferSubData(size_t pos, const void* ptr, size_t updateByteSize);
    1.38 +
    1.39 +  bool Validate(GLenum type, uint32_t maxAllowed, size_t first, size_t count,
    1.40 +                uint32_t* out_upperBound = nullptr);
    1.41 +
    1.42 +  template<typename T>
    1.43 +  T Element(size_t i) const { return Elements<T>()[i]; }
    1.44 +
    1.45 +  WebGLElementArrayCache()
    1.46 +    : mUntypedData(nullptr)
    1.47 +    , mByteSize(0)
    1.48 +    , mUint8Tree(nullptr)
    1.49 +    , mUint16Tree(nullptr)
    1.50 +    , mUint32Tree(nullptr)
    1.51 +  {}
    1.52 +
    1.53 +  ~WebGLElementArrayCache();
    1.54 +
    1.55 +  size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    1.56 +
    1.57 +private:
    1.58 +
    1.59 +  template<typename T>
    1.60 +  bool Validate(uint32_t maxAllowed, size_t first, size_t count,
    1.61 +                uint32_t* out_upperBound);
    1.62 +
    1.63 +  size_t ByteSize() const {
    1.64 +    return mByteSize;
    1.65 +  }
    1.66 +
    1.67 +  template<typename T>
    1.68 +  const T* Elements() const { return static_cast<const T*>(mUntypedData); }
    1.69 +  template<typename T>
    1.70 +  T* Elements() { return static_cast<T*>(mUntypedData); }
    1.71 +
    1.72 +  void InvalidateTrees(size_t firstByte, size_t lastByte);
    1.73 +
    1.74 +  template<typename T>
    1.75 +  friend struct WebGLElementArrayCacheTree;
    1.76 +  template<typename T>
    1.77 +  friend struct TreeForType;
    1.78 +
    1.79 +  void* mUntypedData;
    1.80 +  size_t mByteSize;
    1.81 +  WebGLElementArrayCacheTree<uint8_t>* mUint8Tree;
    1.82 +  WebGLElementArrayCacheTree<uint16_t>* mUint16Tree;
    1.83 +  WebGLElementArrayCacheTree<uint32_t>* mUint32Tree;
    1.84 +};
    1.85 +
    1.86 +
    1.87 +} // end namespace mozilla
    1.88 +
    1.89 +#endif // WEBGLELEMENTARRAYCACHE_H

mercurial