Bug 1850713: remove duplicated setting of early hint preloader id in `ScriptLoader...
[gecko.git] / dom / canvas / WebGLBuffer.h
blobce3f9a407f0146ff9b5d01bb58122277a54f34fd
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/. */
6 #ifndef WEBGL_BUFFER_H_
7 #define WEBGL_BUFFER_H_
9 #include <map>
11 #include "CacheInvalidator.h"
12 #include "GLDefs.h"
13 #include "WebGLObjectModel.h"
14 #include "WebGLTypes.h"
16 namespace mozilla {
18 class WebGLBuffer final : public WebGLContextBoundObject {
19 friend class WebGLContext;
20 friend class WebGL2Context;
21 friend class WebGLMemoryTracker;
22 friend class WebGLTexture;
24 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(WebGLBuffer, override)
26 public:
27 enum class Kind { Undefined, ElementArray, OtherData };
29 WebGLBuffer(WebGLContext* webgl, GLuint buf);
31 void SetContentAfterBind(GLenum target);
32 Kind Content() const { return mContent; }
34 size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
36 GLenum Usage() const { return mUsage; }
37 size_t ByteLength() const { return mByteLength; }
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;
43 bool ValidateCanBindToTarget(GLenum target);
44 void BufferData(GLenum target, uint64_t size, const void* data, GLenum usage);
45 void BufferSubData(GLenum target, uint64_t dstByteOffset, uint64_t dataLen,
46 const void* data, bool unsynchronized = false) const;
48 ////
50 const GLenum mGLName;
52 protected:
53 ~WebGLBuffer() override;
55 void InvalidateCacheRange(uint64_t byteOffset, uint64_t byteLength) const;
57 Kind mContent = Kind::Undefined;
58 GLenum mUsage = LOCAL_GL_STATIC_DRAW;
59 size_t mByteLength = 0;
60 mutable uint64_t mLastUpdateFenceId = 0;
62 struct IndexRange final {
63 GLenum type;
64 uint64_t byteOffset;
65 uint32_t indexCount;
67 bool operator<(const IndexRange& x) const {
68 if (type != x.type) return type < x.type;
70 if (byteOffset != x.byteOffset) return byteOffset < x.byteOffset;
72 return indexCount < x.indexCount;
76 UniqueBuffer mIndexCache;
77 mutable std::map<IndexRange, Maybe<uint32_t>> mIndexRanges;
79 public:
80 CacheInvalidator mFetchInvalidator;
82 void ResetLastUpdateFenceId() const;
85 } // namespace mozilla
87 #endif // WEBGL_BUFFER_H_