Chromium Code Reviews| 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 | |
| 28 // This class is used and owned by cc Picture class. It is used to gather pixel | |
| 29 // refs which would happen after record. It takes in |tile_grid_size| to decide | |
|
ajuma
2015/02/11 15:29:03
s/"tile_grid_size"/"cell_size"?
| |
| 30 // how big each grid should be. | |
|
ajuma
2015/02/11 15:29:03
s/"each grid"/"each grid cell"?
| |
| 31 class CC_EXPORT PixelRefMap : public base::hash_map<PixelRefMapKey, PixelRefs> { | |
| 32 public: | |
| 33 explicit PixelRefMap(const gfx::Size& cell_size); | |
| 34 ~PixelRefMap(); | |
| 35 void GatherPixelRefsFromPicture(SkPicture* picture); | |
| 36 | |
| 37 private: | |
| 38 gfx::Point min_pixel_cell_; | |
| 39 gfx::Point max_pixel_cell_; | |
| 40 gfx::Size cell_size_; | |
| 41 | |
| 42 friend class PixelRefMapIterator; | |
| 43 }; | |
| 44 | |
| 45 // This iterator imprecisely returns the set of pixel refs that are needed to | |
| 46 // raster this layer rect from this picture. Internally, pixel refs are | |
| 47 // clumped into tile grid buckets, so there may be false positives. | |
| 48 class CC_EXPORT PixelRefMapIterator { | |
| 49 public: | |
| 50 // Default iterator constructor that is used as place holder for invalid | |
| 51 // PixelRefMapIterator. | |
| 52 PixelRefMapIterator(); | |
| 53 PixelRefMapIterator(const gfx::Rect& layer_rect, const Picture* picture); | |
| 54 ~PixelRefMapIterator(); | |
| 55 | |
| 56 SkPixelRef* operator->() const { | |
| 57 DCHECK_LT(current_index_, current_pixel_refs_->size()); | |
| 58 return (*current_pixel_refs_)[current_index_]; | |
| 59 } | |
| 60 | |
| 61 SkPixelRef* operator*() const { | |
| 62 DCHECK_LT(current_index_, current_pixel_refs_->size()); | |
| 63 return (*current_pixel_refs_)[current_index_]; | |
| 64 } | |
| 65 | |
| 66 PixelRefMapIterator& operator++(); | |
| 67 operator bool() const { return current_index_ < current_pixel_refs_->size(); } | |
| 68 | |
| 69 private: | |
| 70 static base::LazyInstance<PixelRefs> empty_pixel_refs_; | |
| 71 const PixelRefMap* map_; | |
| 72 const PixelRefs* current_pixel_refs_; | |
| 73 unsigned current_index_; | |
| 74 | |
| 75 gfx::Rect layer_rect_; | |
| 76 | |
| 77 gfx::Point min_point_; | |
| 78 gfx::Point max_point_; | |
| 79 int current_x_; | |
| 80 int current_y_; | |
| 81 }; | |
| 82 | |
| 83 } // namespace cc | |
| 84 | |
| 85 #endif // CC_RESOURCES_PIXEL_REF_MAP_H_ | |
| OLD | NEW |