diff options
Diffstat (limited to '')
-rw-r--r-- | gfx/skia/skia/src/gpu/GrSamplePatternDictionary.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/gfx/skia/skia/src/gpu/GrSamplePatternDictionary.h b/gfx/skia/skia/src/gpu/GrSamplePatternDictionary.h new file mode 100644 index 0000000000..b0044782a6 --- /dev/null +++ b/gfx/skia/skia/src/gpu/GrSamplePatternDictionary.h @@ -0,0 +1,39 @@ +/* + * Copyright 2019 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrSamplePatternDictionary_DEFINED +#define GrSamplePatternDictionary_DEFINED + +#include "include/core/SkPoint.h" +#include "include/private/SkTArray.h" +#include <map> + +/** + * A bidirectional dictionary mapping between sample patterns (i.e., a list of sample locations) and + * unique keys. Since we expect that most render targets will draw from the same small pool of + * sample patterns, we favor sample pattern keys over actual arrays of points. + */ +class GrSamplePatternDictionary { +public: + static constexpr int kInvalidSamplePatternKey = -1; + + int findOrAssignSamplePatternKey(const SkTArray<SkPoint>& sampleLocations); + + const SkTArray<SkPoint>& retrieveSampleLocations(int samplePatternKey) const { + return *fSampleLocationsArray[samplePatternKey]; + } + +private: + struct LessThan { + bool operator()(const SkTArray<SkPoint>&, const SkTArray<SkPoint>&) const; + }; + + std::map<SkTArray<SkPoint>, int, LessThan> fSamplePatternKeyMap; + SkTArray<const SkTArray<SkPoint>*> fSampleLocationsArray; +}; + +#endif |