1 /* -*- Mode: C++; tab-width: 20; 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 #include "MaskLayerImageCache.h"
7 #include "ImageContainer.h"
9 using namespace mozilla::layers
;
13 MaskLayerImageCache::MaskLayerImageCache()
15 MOZ_COUNT_CTOR(MaskLayerImageCache
);
17 MaskLayerImageCache::~MaskLayerImageCache()
19 MOZ_COUNT_DTOR(MaskLayerImageCache
);
23 /* static */ PLDHashOperator
24 MaskLayerImageCache::SweepFunc(MaskLayerImageEntry
* aEntry
,
27 const MaskLayerImageCache::MaskLayerImageKey
* key
= aEntry
->mKey
;
29 if (key
->mLayerCount
== 0) {
30 return PL_DHASH_REMOVE
;
37 MaskLayerImageCache::Sweep()
39 mMaskImageContainers
.EnumerateEntries(SweepFunc
, nullptr);
43 MaskLayerImageCache::FindImageFor(const MaskLayerImageKey
** aKey
)
45 if (MaskLayerImageEntry
* entry
= mMaskImageContainers
.GetEntry(**aKey
)) {
46 *aKey
= entry
->mKey
.get();
47 return entry
->mContainer
;
54 MaskLayerImageCache::PutImage(const MaskLayerImageKey
* aKey
, ImageContainer
* aContainer
)
56 MaskLayerImageEntry
* entry
= mMaskImageContainers
.PutEntry(*aKey
);
57 entry
->mContainer
= aContainer
;
60 // This case is particularly 'clever' because it uses AddRef/Release to track the use
61 // not to release the object.
63 struct HasDangerousPublicDestructor
<MaskLayerImageCache::MaskLayerImageKey
>
65 static const bool value
= true;
68 MaskLayerImageCache::MaskLayerImageKey::MaskLayerImageKey()
72 MOZ_COUNT_CTOR(MaskLayerImageKey
);
75 MaskLayerImageCache::MaskLayerImageKey::MaskLayerImageKey(const MaskLayerImageKey
& aKey
)
76 : mLayerCount(aKey
.mLayerCount
)
77 , mRoundedClipRects(aKey
.mRoundedClipRects
)
79 MOZ_COUNT_CTOR(MaskLayerImageKey
);
82 MaskLayerImageCache::MaskLayerImageKey::~MaskLayerImageKey()
84 MOZ_COUNT_DTOR(MaskLayerImageKey
);