1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_BorderCache_h_ 8 #define mozilla_BorderCache_h_ 9 10 #include "mozilla/gfx/2D.h" 11 #include "mozilla/HashFunctions.h" 12 #include "PLDHashTable.h" 13 14 namespace mozilla { 15 // Cache for best overlap and best dashLength. 16 17 struct FourFloats { 18 typedef mozilla::gfx::Float Float; 19 20 Float n[4]; 21 FourFloatsFourFloats22 FourFloats() { 23 n[0] = 0.0f; 24 n[1] = 0.0f; 25 n[2] = 0.0f; 26 n[3] = 0.0f; 27 } 28 FourFloatsFourFloats29 FourFloats(Float a, Float b, Float c, Float d) { 30 n[0] = a; 31 n[1] = b; 32 n[2] = c; 33 n[3] = d; 34 } 35 36 bool operator==(const FourFloats& aOther) const { 37 return n[0] == aOther.n[0] && n[1] == aOther.n[1] && n[2] == aOther.n[2] && 38 n[3] == aOther.n[3]; 39 } 40 }; 41 42 class FourFloatsHashKey : public PLDHashEntryHdr { 43 public: 44 typedef const FourFloats& KeyType; 45 typedef const FourFloats* KeyTypePointer; 46 FourFloatsHashKey(KeyTypePointer aKey)47 explicit FourFloatsHashKey(KeyTypePointer aKey) : mValue(*aKey) {} FourFloatsHashKey(const FourFloatsHashKey & aToCopy)48 FourFloatsHashKey(const FourFloatsHashKey& aToCopy) 49 : mValue(aToCopy.mValue) {} 50 ~FourFloatsHashKey() = default; 51 GetKey()52 KeyType GetKey() const { return mValue; } KeyEquals(KeyTypePointer aKey)53 bool KeyEquals(KeyTypePointer aKey) const { return *aKey == mValue; } 54 KeyToPointer(KeyType aKey)55 static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; } HashKey(KeyTypePointer aKey)56 static PLDHashNumber HashKey(KeyTypePointer aKey) { 57 return HashBytes(aKey->n, sizeof(mozilla::gfx::Float) * 4); 58 } 59 enum { ALLOW_MEMMOVE = true }; 60 61 private: 62 const FourFloats mValue; 63 }; 64 65 } // namespace mozilla 66 67 #endif /* mozilla_BorderCache_h_ */ 68