Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / cc / resources / picture_pile.h
blobbab06c81aead743c8501897b08c0591b38554f92
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/picture.h"
17 namespace cc {
18 class PicturePileImpl;
20 class CC_EXPORT PicturePile : public RecordingSource {
21 public:
22 PicturePile(float min_contents_scale, const gfx::Size& tile_grid_size);
23 ~PicturePile() override;
25 // RecordingSource overrides.
26 bool UpdateAndExpandInvalidation(ContentLayerClient* painter,
27 Region* invalidation,
28 const gfx::Size& layer_size,
29 const gfx::Rect& visible_layer_rect,
30 int frame_number,
31 RecordingMode recording_mode) override;
32 scoped_refptr<RasterSource> CreateRasterSource(
33 bool can_use_lcd_text) const override;
34 gfx::Size GetSize() const final;
35 void SetEmptyBounds() override;
36 void SetSlowdownRasterScaleFactor(int factor) override;
37 void SetBackgroundColor(SkColor background_color) override;
38 void SetRequiresClear(bool requires_clear) override;
39 bool IsSuitableForGpuRasterization() const override;
40 void SetUnsuitableForGpuRasterizationForTesting() override;
41 gfx::Size GetTileGridSizeForTesting() const override;
43 protected:
44 class CC_EXPORT PictureInfo {
45 public:
46 enum { INVALIDATION_FRAMES_TRACKED = 32 };
48 PictureInfo();
49 ~PictureInfo();
51 bool Invalidate(int frame_number);
52 bool NeedsRecording(int frame_number, int distance_to_visible);
53 void SetPicture(scoped_refptr<Picture> picture);
54 const Picture* GetPicture() const;
56 float GetInvalidationFrequencyForTesting() const {
57 return GetInvalidationFrequency();
60 private:
61 void AdvanceInvalidationHistory(int frame_number);
62 float GetInvalidationFrequency() const;
64 int last_frame_number_;
65 scoped_refptr<const Picture> picture_;
66 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
69 typedef std::pair<int, int> PictureMapKey;
70 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
72 // An internal CanRaster check that goes to the picture_map rather than
73 // using the recorded_viewport hint.
74 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
76 void Clear();
78 void SetMinContentsScale(float min_contents_scale);
79 void SetTileGridSize(const gfx::Size& tile_grid_size);
81 gfx::Rect PaddedRect(const PictureMapKey& key) const;
82 gfx::Rect PadRect(const gfx::Rect& rect) const;
84 int buffer_pixels() const { return tiling_.border_texels(); }
86 // A picture pile is a tiled set of pictures. The picture map is a map of tile
87 // indices to picture infos.
88 PictureMap picture_map_;
89 TilingData tiling_;
91 // If non-empty, all pictures tiles inside this rect are recorded. There may
92 // be recordings outside this rect, but everything inside the rect is
93 // recorded.
94 gfx::Rect recorded_viewport_;
95 float min_contents_scale_;
96 gfx::Size tile_grid_size_;
97 int slow_down_raster_scale_factor_for_debug_;
98 // A hint about whether there are any recordings. This may be a false
99 // positive.
100 bool has_any_recordings_;
101 bool clear_canvas_with_debug_color_;
102 bool requires_clear_;
103 bool is_solid_color_;
104 SkColor solid_color_;
105 SkColor background_color_;
106 int pixel_record_distance_;
108 private:
109 friend class PicturePileImpl;
111 void CreatePictures(ContentLayerClient* painter,
112 RecordingMode recording_mode,
113 const std::vector<gfx::Rect>& record_rects);
114 void GetInvalidTileRects(const gfx::Rect& interest_rect,
115 Region* invalidation,
116 const gfx::Rect& visible_layer_rect,
117 int frame_number,
118 std::vector<gfx::Rect>* invalid_tiles);
119 bool ApplyInvalidationAndResize(const gfx::Rect& interest_rect,
120 Region* invalidation,
121 const gfx::Size& layer_size,
122 int frame_number);
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_