[NaCl SDK]: use standard __BEGIN_DECLS macros in sys/select.h
[chromium-blink-merge.git] / cc / resources / picture_pile_base.h
blobfb6cf5f029bdd55f8b3a01d550886c431b59d54e
1 // Copyright 2013 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_RESOURCES_PICTURE_PILE_BASE_H_
6 #define CC_RESOURCES_PICTURE_PILE_BASE_H_
8 #include <bitset>
9 #include <list>
10 #include <utility>
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/ref_counted.h"
14 #include "cc/base/cc_export.h"
15 #include "cc/base/region.h"
16 #include "cc/base/tiling_data.h"
17 #include "cc/resources/picture.h"
18 #include "ui/gfx/size.h"
20 namespace base {
21 namespace debug {
22 class TracedValue;
24 class Value;
27 namespace cc {
29 class CC_EXPORT PicturePileBase : public base::RefCounted<PicturePileBase> {
30 public:
31 PicturePileBase();
32 explicit PicturePileBase(const PicturePileBase* other);
34 gfx::Size tiling_size() const { return tiling_.tiling_size(); }
35 void SetMinContentsScale(float min_contents_scale);
37 // If non-empty, all pictures tiles inside this rect are recorded. There may
38 // be recordings outside this rect, but everything inside the rect is
39 // recorded.
40 gfx::Rect recorded_viewport() const { return recorded_viewport_; }
42 int num_tiles_x() const { return tiling_.num_tiles_x(); }
43 int num_tiles_y() const { return tiling_.num_tiles_y(); }
44 gfx::Rect tile_bounds(int x, int y) const { return tiling_.TileBounds(x, y); }
45 bool HasRecordingAt(int x, int y);
46 bool CanRaster(float contents_scale, const gfx::Rect& content_rect);
48 // If this pile contains any valid recordings. May have false positives.
49 bool HasRecordings() const { return has_any_recordings_; }
51 // If this pile has ever contained any recordings with text.
52 bool has_text() const { return has_text_; }
54 void set_is_mask(bool is_mask) { is_mask_ = is_mask; }
55 bool is_mask() const { return is_mask_; }
57 static void ComputeTileGridInfo(const gfx::Size& tile_grid_size,
58 SkTileGridFactory::TileGridInfo* info);
60 void SetTileGridSize(const gfx::Size& tile_grid_size);
61 TilingData& tiling() { return tiling_; }
63 void AsValueInto(base::debug::TracedValue* array) const;
65 protected:
66 class CC_EXPORT PictureInfo {
67 public:
68 enum {
69 INVALIDATION_FRAMES_TRACKED = 32
72 PictureInfo();
73 ~PictureInfo();
75 bool Invalidate(int frame_number);
76 bool NeedsRecording(int frame_number, int distance_to_visible);
77 void SetPicture(scoped_refptr<Picture> picture);
78 const Picture* GetPicture() const;
80 float GetInvalidationFrequencyForTesting() const {
81 return GetInvalidationFrequency();
84 private:
85 void AdvanceInvalidationHistory(int frame_number);
86 float GetInvalidationFrequency() const;
88 int last_frame_number_;
89 scoped_refptr<const Picture> picture_;
90 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
93 typedef std::pair<int, int> PictureMapKey;
94 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
96 virtual ~PicturePileBase();
98 int buffer_pixels() const { return tiling_.border_texels(); }
99 void Clear();
101 gfx::Rect PaddedRect(const PictureMapKey& key) const;
102 gfx::Rect PadRect(const gfx::Rect& rect) const;
104 // An internal CanRaster check that goes to the picture_map rather than
105 // using the recorded_viewport hint.
106 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
108 // A picture pile is a tiled set of pictures. The picture map is a map of tile
109 // indices to picture infos.
110 PictureMap picture_map_;
111 TilingData tiling_;
112 gfx::Rect recorded_viewport_;
113 float min_contents_scale_;
114 SkTileGridFactory::TileGridInfo tile_grid_info_;
115 SkColor background_color_;
116 int slow_down_raster_scale_factor_for_debug_;
117 bool contents_opaque_;
118 bool contents_fill_bounds_completely_;
119 bool show_debug_picture_borders_;
120 bool clear_canvas_with_debug_color_;
121 // A hint about whether there are any recordings. This may be a false
122 // positive.
123 bool has_any_recordings_;
124 bool has_text_;
125 bool is_mask_;
127 private:
128 void SetBufferPixels(int buffer_pixels);
130 friend class base::RefCounted<PicturePileBase>;
131 DISALLOW_COPY_AND_ASSIGN(PicturePileBase);
134 } // namespace cc
136 #endif // CC_RESOURCES_PICTURE_PILE_BASE_H_