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_
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"
26 class CC_EXPORT PicturePileBase : public base::RefCounted<PicturePileBase> {
29 explicit PicturePileBase(const PicturePileBase* other);
30 PicturePileBase(const PicturePileBase* other, unsigned thread_index);
32 void Resize(const gfx::Size& size);
33 gfx::Size size() const { return tiling_.total_size(); }
34 void SetMinContentsScale(float min_contents_scale);
36 void UpdateRecordedRegion();
37 const Region& recorded_region() const { return recorded_region_; }
39 int num_tiles_x() const { return tiling_.num_tiles_x(); }
40 int num_tiles_y() const { return tiling_.num_tiles_y(); }
41 gfx::Rect tile_bounds(int x, int y) const { return tiling_.TileBounds(x, y); }
42 bool HasRecordingAt(int x, int y);
43 bool CanRaster(float contents_scale, const gfx::Rect& content_rect);
45 static void ComputeTileGridInfo(const gfx::Size& tile_grid_size,
46 SkTileGridPicture::TileGridInfo* info);
48 void SetTileGridSize(const gfx::Size& tile_grid_size);
49 TilingData& tiling() { return tiling_; }
51 scoped_ptr<base::Value> AsValue() const;
54 class CC_EXPORT PictureInfo {
57 INVALIDATION_FRAMES_TRACKED = 32
63 bool Invalidate(int frame_number);
64 bool NeedsRecording(int frame_number, int distance_to_visible);
65 PictureInfo CloneForThread(int thread_index) const;
66 void SetPicture(scoped_refptr<Picture> picture);
67 Picture* GetPicture() const;
69 float GetInvalidationFrequencyForTesting() const {
70 return GetInvalidationFrequency();
74 void AdvanceInvalidationHistory(int frame_number);
75 float GetInvalidationFrequency() const;
77 int last_frame_number_;
78 scoped_refptr<Picture> picture_;
79 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
82 typedef std::pair<int, int> PictureMapKey;
83 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
85 virtual ~PicturePileBase();
87 void SetRecordedRegionForTesting(const Region& recorded_region) {
88 recorded_region_ = recorded_region;
91 int buffer_pixels() const { return tiling_.border_texels(); }
94 gfx::Rect PaddedRect(const PictureMapKey& key);
95 gfx::Rect PadRect(const gfx::Rect& rect);
97 // A picture pile is a tiled set of pictures. The picture map is a map of tile
98 // indices to picture infos.
99 PictureMap picture_map_;
101 Region recorded_region_;
102 float min_contents_scale_;
103 SkTileGridPicture::TileGridInfo tile_grid_info_;
104 SkColor background_color_;
105 int slow_down_raster_scale_factor_for_debug_;
106 bool contents_opaque_;
107 bool show_debug_picture_borders_;
108 bool clear_canvas_with_debug_color_;
111 void SetBufferPixels(int buffer_pixels);
113 friend class base::RefCounted<PicturePileBase>;
114 DISALLOW_COPY_AND_ASSIGN(PicturePileBase);
119 #endif // CC_RESOURCES_PICTURE_PILE_BASE_H_