Revert 279472 "Mojo: Add mojo_shell_tests to the Linux bots."
[chromium-blink-merge.git] / cc / resources / picture_pile_base.h
blob9f8acffd294fb21f41f41899e3e24f0e1317c5a6
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 class Value;
24 namespace cc {
26 class CC_EXPORT PicturePileBase : public base::RefCounted<PicturePileBase> {
27 public:
28 PicturePileBase();
29 explicit PicturePileBase(const PicturePileBase* other);
30 PicturePileBase(const PicturePileBase* other, unsigned thread_index);
32 void SetTilingRect(const gfx::Rect& tiling_rect);
33 gfx::Rect tiling_rect() const { return tiling_.tiling_rect(); }
34 void SetMinContentsScale(float min_contents_scale);
36 // If non-empty, all pictures tiles inside this rect are recorded. There may
37 // be recordings outside this rect, but everything inside the rect is
38 // recorded.
39 gfx::Rect recorded_viewport() const { return recorded_viewport_; }
41 int num_tiles_x() const { return tiling_.num_tiles_x(); }
42 int num_tiles_y() const { return tiling_.num_tiles_y(); }
43 gfx::Rect tile_bounds(int x, int y) const { return tiling_.TileBounds(x, y); }
44 bool HasRecordingAt(int x, int y);
45 bool CanRaster(float contents_scale, const gfx::Rect& content_rect);
47 // If this pile contains any valid recordings. May have false positives.
48 bool HasRecordings() const { return has_any_recordings_; }
50 static void ComputeTileGridInfo(const gfx::Size& tile_grid_size,
51 SkTileGridFactory::TileGridInfo* info);
53 void SetTileGridSize(const gfx::Size& tile_grid_size);
54 TilingData& tiling() { return tiling_; }
56 scoped_ptr<base::Value> AsValue() const;
58 protected:
59 class CC_EXPORT PictureInfo {
60 public:
61 enum {
62 INVALIDATION_FRAMES_TRACKED = 32
65 PictureInfo();
66 ~PictureInfo();
68 bool Invalidate(int frame_number);
69 bool NeedsRecording(int frame_number, int distance_to_visible);
70 PictureInfo CloneForThread(int thread_index) const;
71 void SetPicture(scoped_refptr<Picture> picture);
72 Picture* GetPicture() const;
74 float GetInvalidationFrequencyForTesting() const {
75 return GetInvalidationFrequency();
78 private:
79 void AdvanceInvalidationHistory(int frame_number);
80 float GetInvalidationFrequency() const;
82 int last_frame_number_;
83 scoped_refptr<Picture> picture_;
84 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
87 typedef std::pair<int, int> PictureMapKey;
88 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
90 virtual ~PicturePileBase();
92 int buffer_pixels() const { return tiling_.border_texels(); }
93 void Clear();
95 gfx::Rect PaddedRect(const PictureMapKey& key);
96 gfx::Rect PadRect(const gfx::Rect& rect);
98 // An internal CanRaster check that goes to the picture_map rather than
99 // using the recorded_viewport hint.
100 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
102 // A picture pile is a tiled set of pictures. The picture map is a map of tile
103 // indices to picture infos.
104 PictureMap picture_map_;
105 TilingData tiling_;
106 gfx::Rect recorded_viewport_;
107 float min_contents_scale_;
108 SkTileGridFactory::TileGridInfo tile_grid_info_;
109 SkColor background_color_;
110 int slow_down_raster_scale_factor_for_debug_;
111 bool contents_opaque_;
112 bool contents_fill_bounds_completely_;
113 bool show_debug_picture_borders_;
114 bool clear_canvas_with_debug_color_;
115 // A hint about whether there are any recordings. This may be a false
116 // positive.
117 bool has_any_recordings_;
119 private:
120 void SetBufferPixels(int buffer_pixels);
122 friend class base::RefCounted<PicturePileBase>;
123 DISALLOW_COPY_AND_ASSIGN(PicturePileBase);
126 } // namespace cc
128 #endif // CC_RESOURCES_PICTURE_PILE_BASE_H_