1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #ifndef FLUTTER_FLOW_RASTER_CACHE_KEY_H_ |
6 | #define FLUTTER_FLOW_RASTER_CACHE_KEY_H_ |
7 | |
8 | #include <unordered_map> |
9 | #include "flutter/flow/matrix_decomposition.h" |
10 | #include "flutter/fml/logging.h" |
11 | |
12 | namespace flutter { |
13 | |
14 | template <typename ID> |
15 | class RasterCacheKey { |
16 | public: |
17 | RasterCacheKey(ID id, const SkMatrix& ctm) : id_(id), matrix_(ctm) { |
18 | matrix_[SkMatrix::kMTransX] = 0; |
19 | matrix_[SkMatrix::kMTransY] = 0; |
20 | } |
21 | |
22 | ID id() const { return id_; } |
23 | const SkMatrix& matrix() const { return matrix_; } |
24 | |
25 | struct Hash { |
26 | uint32_t operator()(RasterCacheKey const& key) const { |
27 | return std::hash<ID>()(key.id_); |
28 | } |
29 | }; |
30 | |
31 | struct Equal { |
32 | constexpr bool operator()(const RasterCacheKey& lhs, |
33 | const RasterCacheKey& rhs) const { |
34 | return lhs.id_ == rhs.id_ && lhs.matrix_ == rhs.matrix_; |
35 | } |
36 | }; |
37 | |
38 | template <class Value> |
39 | using Map = std::unordered_map<RasterCacheKey, Value, Hash, Equal>; |
40 | |
41 | private: |
42 | ID id_; |
43 | |
44 | // ctm where only fractional (0-1) translations are preserved: |
45 | // matrix_ = ctm; |
46 | // matrix_[SkMatrix::kMTransX] = SkScalarFraction(ctm.getTranslateX()); |
47 | // matrix_[SkMatrix::kMTransY] = SkScalarFraction(ctm.getTranslateY()); |
48 | SkMatrix matrix_; |
49 | }; |
50 | |
51 | // The ID is the uint32_t picture uniqueID |
52 | using PictureRasterCacheKey = RasterCacheKey<uint32_t>; |
53 | |
54 | class Layer; |
55 | |
56 | // The ID is the uint64_t layer unique_id |
57 | using LayerRasterCacheKey = RasterCacheKey<uint64_t>; |
58 | |
59 | } // namespace flutter |
60 | |
61 | #endif // FLUTTER_FLOW_RASTER_CACHE_KEY_H_ |
62 | |