ScrollGeneration.h (1926B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef mozilla_ScrollGeneration_h_ 6 #define mozilla_ScrollGeneration_h_ 7 8 #include <cstdint> 9 #include <iosfwd> 10 #include <tuple> 11 12 namespace mozilla { 13 14 struct ScrollGenerationCounter; 15 16 class APZTag {}; 17 class MainThreadTag {}; 18 19 template <typename Tag> 20 struct ScrollGeneration; 21 22 template <typename Tag> 23 std::ostream& operator<<(std::ostream& aStream, 24 const ScrollGeneration<Tag>& aGen); 25 26 template <typename Tag> 27 struct ScrollGeneration final { 28 friend struct ScrollGenerationCounter; 29 30 private: 31 // Private constructor; use ScrollGenerationCounter to get a new instance. 32 explicit ScrollGeneration(uint64_t aValue); 33 34 public: 35 // Dummy constructor, needed for IPDL purposes. Not intended for manual use. 36 ScrollGeneration(); 37 38 uint64_t Raw() const { return mValue; } 39 40 bool operator<(const ScrollGeneration<Tag>& aOther) const; 41 bool operator==(const ScrollGeneration<Tag>& aOther) const; 42 bool operator!=(const ScrollGeneration<Tag>& aOther) const; 43 44 friend std::ostream& operator<< <>(std::ostream& aStream, 45 const ScrollGeneration<Tag>& aGen); 46 47 auto MutTiedFields() { return std::tie(mValue); } 48 49 private: 50 uint64_t mValue; 51 }; 52 53 using APZScrollGeneration = ScrollGeneration<APZTag>; 54 using MainThreadScrollGeneration = ScrollGeneration<MainThreadTag>; 55 56 struct ScrollGenerationCounter { 57 MainThreadScrollGeneration NewMainThreadGeneration() { 58 uint64_t value = ++mCounter; 59 return MainThreadScrollGeneration(value); 60 } 61 62 APZScrollGeneration NewAPZGeneration() { 63 uint64_t value = ++mCounter; 64 return APZScrollGeneration(value); 65 } 66 67 private: 68 uint64_t mCounter = 0; 69 }; 70 71 } // namespace mozilla 72 73 #endif // mozilla_ScrollGeneration_h_