Flutter Engine
raster_cache_key.h
Go to the documentation of this file.
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 
10 #include "flutter/flow/matrix_decomposition.h"
11 #include "flutter/fml/logging.h"
12 
13 namespace flutter {
14 
15 template <typename ID>
17  public:
18  RasterCacheKey(ID id, const SkMatrix& ctm) : id_(id), matrix_(ctm) {
19  matrix_[SkMatrix::kMTransX] = 0;
20  matrix_[SkMatrix::kMTransY] = 0;
21  }
22 
23  ID id() const { return id_; }
24  const SkMatrix& matrix() const { return matrix_; }
25 
26  struct Hash {
27  uint32_t operator()(RasterCacheKey const& key) const {
28  return std::hash<ID>()(key.id_);
29  }
30  };
31 
32  struct Equal {
33  constexpr bool operator()(const RasterCacheKey& lhs,
34  const RasterCacheKey& rhs) const {
35  return lhs.id_ == rhs.id_ && lhs.matrix_ == rhs.matrix_;
36  }
37  };
38 
39  template <class Value>
40  using Map = std::unordered_map<RasterCacheKey, Value, Hash, Equal>;
41 
42  private:
43  ID id_;
44 
45  // ctm where only fractional (0-1) translations are preserved:
46  // matrix_ = ctm;
47  // matrix_[SkMatrix::kMTransX] = SkScalarFraction(ctm.getTranslateX());
48  // matrix_[SkMatrix::kMTransY] = SkScalarFraction(ctm.getTranslateY());
49  SkMatrix matrix_;
50 };
51 
52 // The ID is the uint32_t picture uniqueID
54 
55 class Layer;
56 
57 // The ID is the uint64_t layer unique_id
59 
60 } // namespace flutter
61 
62 #endif // FLUTTER_FLOW_RASTER_CACHE_KEY_H_
uint32_t operator()(RasterCacheKey const &key) const
RasterCacheKey(ID id, const SkMatrix &ctm)
std::unordered_map< RasterCacheKey, Value, Hash, Equal > Map
constexpr bool operator()(const RasterCacheKey &lhs, const RasterCacheKey &rhs) const
const SkMatrix & matrix() const