Update V8 to version 4.7.37.
[chromium-blink-merge.git] / cc / playback / pixel_ref_map.h
blobf8c8ca781e5bd894ff8e1fc28df993dc902799b9
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.
5 #ifndef CC_PLAYBACK_PIXEL_REF_MAP_H_
6 #define CC_PLAYBACK_PIXEL_REF_MAP_H_
8 #include <utility>
9 #include <vector>
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 "skia/ext/pixel_ref_utils.h"
16 #include "third_party/skia/include/core/SkPicture.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
20 class SkPixelRef;
22 namespace cc {
24 class Picture;
25 class DisplayItemList;
27 typedef std::pair<int, int> PixelRefMapKey;
28 typedef std::vector<skia::PositionPixelRef> PixelRefs;
29 typedef base::hash_map<PixelRefMapKey, PixelRefs> PixelRefHashmap;
31 // This class is used and owned by cc Picture class. It is used to gather pixel
32 // refs which would happen after record. It takes in |cell_size| to decide how
33 // big each grid cell should be.
34 class CC_EXPORT PixelRefMap {
35 public:
36 explicit PixelRefMap(const gfx::Size& cell_size);
37 ~PixelRefMap();
38 void GatherPixelRefsFromPicture(SkPicture* picture,
39 const gfx::Rect& layer_rect);
41 bool empty() const { return data_hash_map_.empty(); }
43 // This iterator imprecisely returns the set of pixel refs that are needed to
44 // raster this layer rect from this picture. Internally, pixel refs are
45 // clumped into tile grid buckets, so there may be false positives.
46 class CC_EXPORT Iterator {
47 public:
48 // Default iterator constructor that is used as place holder for invalid
49 // Iterator.
50 Iterator();
51 Iterator(const gfx::Rect& layer_rect, const Picture* picture);
52 Iterator(const gfx::Rect& layer_rect, const DisplayItemList* picture);
53 ~Iterator();
55 const skia::PositionPixelRef* operator->() const {
56 DCHECK_LT(current_index_, current_pixel_refs_->size());
57 return &(*current_pixel_refs_)[current_index_];
60 const skia::PositionPixelRef& operator*() const {
61 DCHECK_LT(current_index_, current_pixel_refs_->size());
62 return (*current_pixel_refs_)[current_index_];
65 Iterator& operator++();
66 operator bool() const {
67 return current_index_ < current_pixel_refs_->size();
70 private:
71 void PointToFirstPixelRef(const gfx::Rect& query_rect);
73 static base::LazyInstance<PixelRefs> empty_pixel_refs_;
74 const PixelRefMap* target_pixel_ref_map_;
75 const PixelRefs* current_pixel_refs_;
76 unsigned current_index_;
78 gfx::Rect map_layer_rect_;
80 gfx::Point min_point_;
81 gfx::Point max_point_;
82 int current_x_;
83 int current_y_;
86 private:
87 gfx::Point min_pixel_cell_;
88 gfx::Point max_pixel_cell_;
89 gfx::Size cell_size_;
91 PixelRefHashmap data_hash_map_;
94 } // namespace cc
96 #endif // CC_PLAYBACK_PIXEL_REF_MAP_H_