Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; 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 mozilla_BorderCache_h_
7 : #define mozilla_BorderCache_h_
8 :
9 : #include "mozilla/gfx/2D.h"
10 : #include "mozilla/HashFunctions.h"
11 : #include "nsDataHashtable.h"
12 : #include "PLDHashTable.h"
13 :
14 : namespace mozilla {
15 : // Cache for best overlap and best dashLength.
16 :
17 : struct FourFloats
18 : {
19 : typedef mozilla::gfx::Float Float;
20 :
21 : Float n[4];
22 :
23 : FourFloats()
24 : {
25 : n[0] = 0.0f;
26 : n[1] = 0.0f;
27 : n[2] = 0.0f;
28 : n[3] = 0.0f;
29 : }
30 :
31 0 : FourFloats(Float a, Float b, Float c, Float d)
32 0 : {
33 0 : n[0] = a;
34 0 : n[1] = b;
35 0 : n[2] = c;
36 0 : n[3] = d;
37 0 : }
38 :
39 : bool
40 0 : operator==(const FourFloats& aOther) const
41 : {
42 0 : return n[0] == aOther.n[0] &&
43 0 : n[1] == aOther.n[1] &&
44 0 : n[2] == aOther.n[2] &&
45 0 : n[3] == aOther.n[3];
46 : }
47 : };
48 :
49 : class FourFloatsHashKey : public PLDHashEntryHdr
50 : {
51 : public:
52 : typedef const FourFloats& KeyType;
53 : typedef const FourFloats* KeyTypePointer;
54 :
55 0 : explicit FourFloatsHashKey(KeyTypePointer aKey) : mValue(*aKey) {}
56 : FourFloatsHashKey(const FourFloatsHashKey& aToCopy) : mValue(aToCopy.mValue) {}
57 0 : ~FourFloatsHashKey() {}
58 :
59 : KeyType GetKey() const { return mValue; }
60 0 : bool KeyEquals(KeyTypePointer aKey) const { return *aKey == mValue; }
61 :
62 0 : static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
63 0 : static PLDHashNumber HashKey(KeyTypePointer aKey)
64 : {
65 0 : return HashBytes(aKey->n, sizeof(mozilla::gfx::Float) * 4);
66 : }
67 : enum { ALLOW_MEMMOVE = true };
68 :
69 : private:
70 : const FourFloats mValue;
71 : };
72 :
73 : } // namespace mozilla
74 :
75 : #endif /* mozilla_BorderCache_h_ */
|