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_
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"
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
{
36 explicit PixelRefMap(const gfx::Size
& cell_size
);
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
{
48 // Default iterator constructor that is used as place holder for invalid
51 Iterator(const gfx::Rect
& layer_rect
, const Picture
* picture
);
52 Iterator(const gfx::Rect
& layer_rect
, const DisplayItemList
* picture
);
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();
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_
;
87 gfx::Point min_pixel_cell_
;
88 gfx::Point max_pixel_cell_
;
91 PixelRefHashmap data_hash_map_
;
96 #endif // CC_PLAYBACK_PIXEL_REF_MAP_H_