| 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_PLAYBACK_PIXEL_REF_MAP_H_ | 5 #ifndef CC_PLAYBACK_PIXEL_REF_MAP_H_ |
| 6 #define CC_PLAYBACK_PIXEL_REF_MAP_H_ | 6 #define CC_PLAYBACK_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 "skia/ext/pixel_ref_utils.h" |
| 15 #include "third_party/skia/include/core/SkPicture.h" | 16 #include "third_party/skia/include/core/SkPicture.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
| 18 | 19 |
| 19 class SkPixelRef; | 20 class SkPixelRef; |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 | 23 |
| 23 class Picture; | 24 class Picture; |
| 24 class DisplayItemList; | 25 class DisplayItemList; |
| 25 | 26 |
| 26 typedef std::pair<int, int> PixelRefMapKey; | 27 typedef std::pair<int, int> PixelRefMapKey; |
| 27 typedef std::vector<SkPixelRef*> PixelRefs; | 28 typedef std::vector<skia::PositionPixelRef> PixelRefs; |
| 28 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefHashmap; | 29 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefHashmap; |
| 29 | 30 |
| 30 // This class is used and owned by cc Picture class. It is used to gather pixel | 31 // 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 | 32 // refs which would happen after record. It takes in |cell_size| to decide how |
| 32 // big each grid cell should be. | 33 // big each grid cell should be. |
| 33 class CC_EXPORT PixelRefMap { | 34 class CC_EXPORT PixelRefMap { |
| 34 public: | 35 public: |
| 35 explicit PixelRefMap(const gfx::Size& cell_size); | 36 explicit PixelRefMap(const gfx::Size& cell_size); |
| 36 ~PixelRefMap(); | 37 ~PixelRefMap(); |
| 37 void GatherPixelRefsFromPicture(SkPicture* picture); | 38 void GatherPixelRefsFromPicture(SkPicture* picture, |
| 39 const gfx::Rect& layer_rect); |
| 38 | 40 |
| 39 bool empty() const { return data_hash_map_.empty(); } | 41 bool empty() const { return data_hash_map_.empty(); } |
| 40 | 42 |
| 41 // This iterator imprecisely returns the set of pixel refs that are needed to | 43 // 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 | 44 // raster this layer rect from this picture. Internally, pixel refs are |
| 43 // clumped into tile grid buckets, so there may be false positives. | 45 // clumped into tile grid buckets, so there may be false positives. |
| 44 class CC_EXPORT Iterator { | 46 class CC_EXPORT Iterator { |
| 45 public: | 47 public: |
| 46 // Default iterator constructor that is used as place holder for invalid | 48 // Default iterator constructor that is used as place holder for invalid |
| 47 // Iterator. | 49 // Iterator. |
| 48 Iterator(); | 50 Iterator(); |
| 49 Iterator(const gfx::Rect& layer_rect, const Picture* picture); | 51 Iterator(const gfx::Rect& layer_rect, const Picture* picture); |
| 50 Iterator(const gfx::Rect& layer_rect, const DisplayItemList* picture); | 52 Iterator(const gfx::Rect& layer_rect, const DisplayItemList* picture); |
| 51 ~Iterator(); | 53 ~Iterator(); |
| 52 | 54 |
| 53 SkPixelRef* operator->() const { | 55 const skia::PositionPixelRef* operator->() const { |
| 56 DCHECK_LT(current_index_, current_pixel_refs_->size()); |
| 57 return &(*current_pixel_refs_)[current_index_]; |
| 58 } |
| 59 |
| 60 const skia::PositionPixelRef& operator*() const { |
| 54 DCHECK_LT(current_index_, current_pixel_refs_->size()); | 61 DCHECK_LT(current_index_, current_pixel_refs_->size()); |
| 55 return (*current_pixel_refs_)[current_index_]; | 62 return (*current_pixel_refs_)[current_index_]; |
| 56 } | 63 } |
| 57 | |
| 58 SkPixelRef* operator*() const { | |
| 59 DCHECK_LT(current_index_, current_pixel_refs_->size()); | |
| 60 return (*current_pixel_refs_)[current_index_]; | |
| 61 } | |
| 62 | 64 |
| 63 Iterator& operator++(); | 65 Iterator& operator++(); |
| 64 operator bool() const { | 66 operator bool() const { |
| 65 return current_index_ < current_pixel_refs_->size(); | 67 return current_index_ < current_pixel_refs_->size(); |
| 66 } | 68 } |
| 67 | 69 |
| 68 private: | 70 private: |
| 69 void PointToFirstPixelRef(const gfx::Rect& query_rect); | 71 void PointToFirstPixelRef(const gfx::Rect& query_rect); |
| 70 | 72 |
| 71 static base::LazyInstance<PixelRefs> empty_pixel_refs_; | 73 static base::LazyInstance<PixelRefs> empty_pixel_refs_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 85 gfx::Point min_pixel_cell_; | 87 gfx::Point min_pixel_cell_; |
| 86 gfx::Point max_pixel_cell_; | 88 gfx::Point max_pixel_cell_; |
| 87 gfx::Size cell_size_; | 89 gfx::Size cell_size_; |
| 88 | 90 |
| 89 PixelRefHashmap data_hash_map_; | 91 PixelRefHashmap data_hash_map_; |
| 90 }; | 92 }; |
| 91 | 93 |
| 92 } // namespace cc | 94 } // namespace cc |
| 93 | 95 |
| 94 #endif // CC_PLAYBACK_PIXEL_REF_MAP_H_ | 96 #endif // CC_PLAYBACK_PIXEL_REF_MAP_H_ |
| OLD | NEW |