tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebGLBuffer.h (2488B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      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/. */
      5 
      6 #ifndef WEBGL_BUFFER_H_
      7 #define WEBGL_BUFFER_H_
      8 
      9 #include <map>
     10 
     11 #include "CacheInvalidator.h"
     12 #include "GLDefs.h"
     13 #include "WebGLObjectModel.h"
     14 #include "WebGLTypes.h"
     15 
     16 namespace mozilla {
     17 
     18 class WebGLBuffer final : public WebGLContextBoundObject {
     19  friend class WebGLContext;
     20  friend class WebGL2Context;
     21  friend class WebGLMemoryTracker;
     22  friend class WebGLTexture;
     23 
     24  MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLBuffer, override)
     25 
     26 public:
     27  enum class Kind { Undefined, ElementArray, OtherData };
     28 
     29  WebGLBuffer(WebGLContext* webgl, GLuint buf);
     30 
     31  void SetContentAfterBind(GLenum target);
     32  Kind Content() const { return mContent; }
     33 
     34  size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
     35 
     36  GLenum Usage() const { return mUsage; }
     37  size_t ByteLength() const { return mByteLength; }
     38 
     39  Maybe<uint32_t> GetIndexedFetchMaxVert(GLenum type, uint64_t byteOffset,
     40                                         uint32_t indexCount) const;
     41  bool ValidateRange(size_t byteOffset, size_t byteLen) const;
     42 
     43  bool ValidateCanBindToTarget(GLenum target);
     44  void BufferData(GLenum target, uint64_t size, const void* data, GLenum usage,
     45                  bool allowUninitialized = false);
     46  void BufferSubData(GLenum target, uint64_t dstByteOffset, uint64_t dataLen,
     47                     const void* data, bool unsynchronized = false) const;
     48 
     49  ////
     50 
     51  const GLenum mGLName;
     52 
     53 protected:
     54  ~WebGLBuffer() override;
     55 
     56  void InvalidateCacheRange(uint64_t byteOffset, uint64_t byteLength) const;
     57 
     58  Kind mContent = Kind::Undefined;
     59  GLenum mUsage = LOCAL_GL_STATIC_DRAW;
     60  size_t mByteLength = 0;
     61  mutable uint64_t mLastUpdateFenceId = 0;
     62 
     63  struct IndexRange final {
     64    GLenum type;
     65    uint64_t byteOffset;
     66    uint32_t indexCount;
     67 
     68    bool operator<(const IndexRange& x) const {
     69      if (type != x.type) return type < x.type;
     70 
     71      if (byteOffset != x.byteOffset) return byteOffset < x.byteOffset;
     72 
     73      return indexCount < x.indexCount;
     74    }
     75  };
     76 
     77  UniqueBuffer mIndexCache;
     78  mutable std::map<IndexRange, Maybe<uint32_t>> mIndexRanges;
     79 
     80 public:
     81  CacheInvalidator mFetchInvalidator;
     82 
     83  void ResetLastUpdateFenceId() const;
     84 };
     85 
     86 }  // namespace mozilla
     87 
     88 #endif  // WEBGL_BUFFER_H_