Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrSamplePatternDictionary_DEFINED |
| 9 | #define GrSamplePatternDictionary_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/core/SkPoint.h" |
| 12 | #include "include/private/SkTArray.h" |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 13 | #include <map> |
| 14 | |
| 15 | /** |
| 16 | * A bidirectional dictionary mapping between sample patterns (i.e., a list of sample locations) and |
| 17 | * unique keys. Since we expect that most render targets will draw from the same small pool of |
| 18 | * sample patterns, we favor sample pattern keys over actual arrays of points. |
| 19 | */ |
| 20 | class GrSamplePatternDictionary { |
| 21 | public: |
| 22 | static constexpr int kInvalidSamplePatternKey = -1; |
| 23 | |
| 24 | int findOrAssignSamplePatternKey(const SkTArray<SkPoint>& sampleLocations); |
| 25 | |
| 26 | const SkTArray<SkPoint>& retrieveSampleLocations(int samplePatternKey) const { |
| 27 | return *fSampleLocationsArray[samplePatternKey]; |
| 28 | } |
| 29 | |
| 30 | private: |
| 31 | struct LessThan { |
| 32 | bool operator()(const SkTArray<SkPoint>&, const SkTArray<SkPoint>&) const; |
| 33 | }; |
| 34 | |
| 35 | std::map<SkTArray<SkPoint>, int, LessThan> fSamplePatternKeyMap; |
| 36 | SkTArray<const SkTArray<SkPoint>*> fSampleLocationsArray; |
| 37 | }; |
| 38 | |
| 39 | #endif |