GrSamplePatternDictionary.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #ifndef GrSamplePatternDictionary_DEFINED
  8. #define GrSamplePatternDictionary_DEFINED
  9. #include "include/core/SkPoint.h"
  10. #include "include/private/SkTArray.h"
  11. #include <map>
  12. /**
  13. * A bidirectional dictionary mapping between sample patterns (i.e., a list of sample locations) and
  14. * unique keys. Since we expect that most render targets will draw from the same small pool of
  15. * sample patterns, we favor sample pattern keys over actual arrays of points.
  16. */
  17. class GrSamplePatternDictionary {
  18. public:
  19. static constexpr int kInvalidSamplePatternKey = -1;
  20. int findOrAssignSamplePatternKey(const SkTArray<SkPoint>& sampleLocations);
  21. const SkTArray<SkPoint>& retrieveSampleLocations(int samplePatternKey) const {
  22. return *fSampleLocationsArray[samplePatternKey];
  23. }
  24. private:
  25. struct LessThan {
  26. bool operator()(const SkTArray<SkPoint>&, const SkTArray<SkPoint>&) const;
  27. };
  28. std::map<SkTArray<SkPoint>, int, LessThan> fSamplePatternKeyMap;
  29. SkTArray<const SkTArray<SkPoint>*> fSampleLocationsArray;
  30. };
  31. #endif