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