OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium 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 CC_RESOURCES_PIXEL_REF_MAP_H_ | |
6 #define CC_RESOURCES_PIXEL_REF_MAP_H_ | |
7 | |
8 #include <utility> | |
9 #include <vector> | |
10 | |
11 #include "base/containers/hash_tables.h" | |
12 #include "base/lazy_instance.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "cc/base/cc_export.h" | |
15 #include "third_party/skia/include/core/SkPicture.h" | |
16 #include "ui/gfx/geometry/rect.h" | |
17 #include "ui/gfx/geometry/size.h" | |
18 | |
19 class SkPixelRef; | |
20 | |
21 namespace cc { | |
22 | |
23 class Picture; | |
24 | |
25 typedef std::pair<int, int> PixelRefMapKey; | |
26 typedef std::vector<SkPixelRef*> PixelRefs; | |
27 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefHashmap; | |
28 | |
29 // This class is used and owned by cc Picture class. It is used to gather pixel | |
30 // refs which would happen after record. It takes in |cell_size| to decide how | |
31 // big each grid cell should be. | |
32 class CC_EXPORT PixelRefMap { | |
33 public: | |
34 explicit PixelRefMap(const gfx::Size& cell_size); | |
35 ~PixelRefMap(); | |
36 void GatherPixelRefsFromPicture(SkPicture* picture); | |
37 | |
38 bool empty() const { return data_hash_map_.empty(); } | |
39 | |
40 // This iterator imprecisely returns the set of pixel refs that are needed to | |
41 // raster this layer rect from this picture. Internally, pixel refs are | |
42 // clumped into tile grid buckets, so there may be false positives. | |
43 class CC_EXPORT Iterator { | |
44 public: | |
45 // Default iterator constructor that is used as place holder for invalid | |
46 // Iterator. | |
47 Iterator(); | |
48 Iterator(const gfx::Rect& layer_rect, const Picture* picture); | |
49 ~Iterator(); | |
50 | |
51 SkPixelRef* operator->() const { | |
52 DCHECK_LT(current_index_, current_pixel_refs_->size()); | |
53 return (*current_pixel_refs_)[current_index_]; | |
54 } | |
55 | |
56 SkPixelRef* operator*() const { | |
57 DCHECK_LT(current_index_, current_pixel_refs_->size()); | |
58 return (*current_pixel_refs_)[current_index_]; | |
59 } | |
60 | |
61 Iterator& operator++(); | |
62 operator bool() const { | |
63 return current_index_ < current_pixel_refs_->size(); | |
64 } | |
65 | |
66 private: | |
67 static base::LazyInstance<PixelRefs> empty_pixel_refs_; | |
68 const PixelRefMap* target_pixel_ref_map_; | |
69 const PixelRefs* current_pixel_refs_; | |
70 unsigned current_index_; | |
71 | |
72 gfx::Rect layer_rect_; | |
73 | |
74 gfx::Point min_point_; | |
75 gfx::Point max_point_; | |
76 int current_x_; | |
77 int current_y_; | |
78 }; | |
79 | |
80 private: | |
81 gfx::Point min_pixel_cell_; | |
82 gfx::Point max_pixel_cell_; | |
83 gfx::Size cell_size_; | |
84 | |
85 PixelRefHashmap data_hash_map_; | |
86 }; | |
87 | |
88 } // namespace cc | |
89 | |
90 #endif // CC_RESOURCES_PIXEL_REF_MAP_H_ | |
OLD | NEW |