Update V8 to version 4.7.44.
[chromium-blink-merge.git] / cc / playback / discardable_image_map.h
blob68b8ac1352bbb58f3329bd87490f9707911cdc1c
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_DISCARDABLE_IMAGE_MAP_H_
6 #define CC_PLAYBACK_DISCARDABLE_IMAGE_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/discardable_image_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 SkImage;
22 namespace cc {
24 class Picture;
25 class DisplayItemList;
27 typedef std::pair<int, int> ImageMapKey;
28 typedef std::vector<skia::PositionImage> Images;
29 typedef base::hash_map<ImageMapKey, Images> ImageHashmap;
31 // This class is used and owned by cc Picture class. It is used to gather images
32 // which would happen after record. It takes in |cell_size| to decide how
33 // big each grid cell should be.
34 class CC_EXPORT DiscardableImageMap {
35 public:
36 explicit DiscardableImageMap(const gfx::Size& cell_size);
37 ~DiscardableImageMap();
39 void GatherImagesFromPicture(SkPicture* picture, const gfx::Rect& layer_rect);
41 bool empty() const { return data_hash_map_.empty(); }
43 // This iterator imprecisely returns the set of images that are needed to
44 // raster this layer rect from this picture. Internally, images 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::PositionImage* operator->() const {
56 DCHECK_LT(current_index_, current_images_->size());
57 return &(*current_images_)[current_index_];
60 const skia::PositionImage& operator*() const {
61 DCHECK_LT(current_index_, current_images_->size());
62 return (*current_images_)[current_index_];
65 Iterator& operator++();
66 operator bool() const { return current_index_ < current_images_->size(); }
68 private:
69 void PointToFirstImage(const gfx::Rect& query_rect);
71 static base::LazyInstance<Images> empty_images_;
72 const DiscardableImageMap* target_image_map_;
73 const Images* current_images_;
74 unsigned current_index_;
76 gfx::Rect map_layer_rect_;
78 gfx::Point min_point_;
79 gfx::Point max_point_;
80 int current_x_;
81 int current_y_;
84 private:
85 gfx::Point min_pixel_cell_;
86 gfx::Point max_pixel_cell_;
87 gfx::Size cell_size_;
89 ImageHashmap data_hash_map_;
92 } // namespace cc
94 #endif // CC_PLAYBACK_DISCARDABLE_IMAGE_MAP_H_