Invalidate scans when the host volume is unmounted.
[chromium-blink-merge.git] / cc / resources / picture_pile.h
blobfd1c4540dc2a785f5c8087d22fac429c6d0216d0
1 // Copyright 2012 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_H_
6 #define CC_RESOURCES_PICTURE_PILE_H_
8 #include <bitset>
9 #include <utility>
10 #include <vector>
12 #include "base/containers/hash_tables.h"
13 #include "base/memory/ref_counted.h"
14 #include "cc/base/tiling_data.h"
15 #include "cc/resources/recording_source.h"
17 namespace cc {
18 class PicturePileImpl;
20 class CC_EXPORT PicturePile : public RecordingSource {
21 public:
22 PicturePile();
23 ~PicturePile() override;
25 // RecordingSource overrides.
26 bool UpdateAndExpandInvalidation(
27 ContentLayerClient* painter,
28 Region* invalidation,
29 bool can_use_lcd_text,
30 const gfx::Size& layer_size,
31 const gfx::Rect& visible_layer_rect,
32 int frame_number,
33 Picture::RecordingMode recording_mode) override;
34 scoped_refptr<RasterSource> CreateRasterSource() const override;
35 gfx::Size GetSize() const final;
36 void SetEmptyBounds() override;
37 void SetMinContentsScale(float min_contents_scale) override;
38 void SetSlowdownRasterScaleFactor(int factor) override;
39 bool IsSuitableForGpuRasterization() const override;
40 void SetTileGridSize(const gfx::Size& tile_grid_size) override;
41 void SetUnsuitableForGpuRasterizationForTesting() override;
42 SkTileGridFactory::TileGridInfo GetTileGridInfoForTesting() const override;
44 static void ComputeTileGridInfo(const gfx::Size& tile_grid_size,
45 SkTileGridFactory::TileGridInfo* info);
47 protected:
48 class CC_EXPORT PictureInfo {
49 public:
50 enum { INVALIDATION_FRAMES_TRACKED = 32 };
52 PictureInfo();
53 ~PictureInfo();
55 bool Invalidate(int frame_number);
56 bool NeedsRecording(int frame_number, int distance_to_visible);
57 void SetPicture(scoped_refptr<Picture> picture);
58 const Picture* GetPicture() const;
60 float GetInvalidationFrequencyForTesting() const {
61 return GetInvalidationFrequency();
64 private:
65 void AdvanceInvalidationHistory(int frame_number);
66 float GetInvalidationFrequency() const;
68 int last_frame_number_;
69 scoped_refptr<const Picture> picture_;
70 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
73 typedef std::pair<int, int> PictureMapKey;
74 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
76 // An internal CanRaster check that goes to the picture_map rather than
77 // using the recorded_viewport hint.
78 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
80 void Clear();
82 gfx::Rect PaddedRect(const PictureMapKey& key) const;
83 gfx::Rect PadRect(const gfx::Rect& rect) const;
85 int buffer_pixels() const { return tiling_.border_texels(); }
87 // A picture pile is a tiled set of pictures. The picture map is a map of tile
88 // indices to picture infos.
89 PictureMap picture_map_;
90 TilingData tiling_;
92 // If non-empty, all pictures tiles inside this rect are recorded. There may
93 // be recordings outside this rect, but everything inside the rect is
94 // recorded.
95 gfx::Rect recorded_viewport_;
96 float min_contents_scale_;
97 SkTileGridFactory::TileGridInfo tile_grid_info_;
98 int slow_down_raster_scale_factor_for_debug_;
99 bool can_use_lcd_text_;
100 // A hint about whether there are any recordings. This may be a false
101 // positive.
102 bool has_any_recordings_;
103 bool is_solid_color_;
104 SkColor solid_color_;
105 int pixel_record_distance_;
107 private:
108 friend class PicturePileImpl;
110 void CreatePictures(ContentLayerClient* painter,
111 Picture::RecordingMode recording_mode,
112 const std::vector<gfx::Rect>& record_rects);
113 void GetInvalidTileRects(const gfx::Rect& interest_rect,
114 Region* invalidation,
115 const gfx::Rect& visible_layer_rect,
116 int frame_number,
117 std::vector<gfx::Rect>* invalid_tiles);
118 bool ApplyInvalidationAndResize(const gfx::Rect& interest_rect,
119 Region* invalidation,
120 const gfx::Size& layer_size,
121 int frame_number,
122 bool can_use_lcd_text_changed);
123 void DetermineIfSolidColor();
124 void SetBufferPixels(int buffer_pixels);
126 bool is_suitable_for_gpu_rasterization_;
128 DISALLOW_COPY_AND_ASSIGN(PicturePile);
131 } // namespace cc
133 #endif // CC_RESOURCES_PICTURE_PILE_H_