blob: b0044782a6881eb28a5517bb1183f5bbccabfabf [file] [log] [blame]
Chris Daltond7291ba2019-03-07 14:17:03 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkPoint.h"
12#include "include/private/SkTArray.h"
Chris Daltond7291ba2019-03-07 14:17:03 -070013#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 */
20class GrSamplePatternDictionary {
21public:
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
30private:
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