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