2 * Copyright 2015 Julian Harnath <julian.harnath@rwth-aachen.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
5 #ifndef ALPHA_MASK_CACHE_H
6 #define ALPHA_MASK_CACHE_H
10 #include "ShapePrivate.h"
12 #include <kernel/OS.h>
19 class AlphaMaskCache
{
22 kMaxCacheBytes
= 8 * 1024 * 1024 // 8 MiB
29 static AlphaMaskCache
* Default();
31 status_t
Put(ShapeAlphaMask
* mask
);
32 ShapeAlphaMask
* Get(const shape_data
& shape
,
33 AlphaMask
* previousMask
,
39 size_t _FindUncachedPreviousMasks(AlphaMask
* mask
,
41 void _PrintAndResetStatistics();
44 struct ShapeMaskElement
{
45 ShapeMaskElement(const shape_data
* shape
,
46 ShapeAlphaMask
* mask
, AlphaMask
* previousMask
,
52 fPreviousMask(previousMask
)
56 bool operator<(const ShapeMaskElement
& other
) const
58 if (fInverse
!= other
.fInverse
)
59 return fInverse
< other
.fInverse
;
60 if (fPreviousMask
!= other
.fPreviousMask
)
61 return fPreviousMask
< other
.fPreviousMask
;
64 if (fShape
->ptCount
!= other
.fShape
->ptCount
)
65 return fShape
->ptCount
< other
.fShape
->ptCount
;
66 if (fShape
->opCount
!= other
.fShape
->opCount
)
67 return fShape
->opCount
< other
.fShape
->opCount
;
68 int diff
= memcmp(fShape
->ptList
, other
.fShape
->ptList
,
72 diff
= memcmp(fShape
->opList
, other
.fShape
->opList
,
81 const shape_data
* fShape
;
83 ShapeAlphaMask
* fMask
;
84 AlphaMask
* fPreviousMask
;
88 typedef std::set
<ShapeMaskElement
> ShapeMaskSet
;
90 static AlphaMaskCache sDefaultInstance
;
94 size_t fCurrentCacheBytes
;
95 ShapeMaskSet fShapeMasks
;
97 // Statistics counters
98 uint32 fTooLargeMaskCount
;
99 uint32 fMasksReplacedCount
;
102 uint32 fLowerMaskReferencedCount
;
106 #endif // ALPHA_MASK_CACHE_H