ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / cc / resources / picture_pile.h
blobbdba5790832688d441b6c2705126986233bd5fb2
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 void DidMoveToNewCompositor() override;
33 scoped_refptr<RasterSource> CreateRasterSource(
34 bool can_use_lcd_text) const override;
35 gfx::Size GetSize() const final;
36 void SetEmptyBounds() override;
37 void SetSlowdownRasterScaleFactor(int factor) override;
38 void SetBackgroundColor(SkColor background_color) override;
39 void SetRequiresClear(bool requires_clear) override;
40 bool IsSuitableForGpuRasterization() const override;
41 void SetUnsuitableForGpuRasterizationForTesting() override;
42 gfx::Size GetTileGridSizeForTesting() const override;
44 protected:
45 class CC_EXPORT PictureInfo {
46 public:
47 enum { INVALIDATION_FRAMES_TRACKED = 32 };
49 PictureInfo();
50 ~PictureInfo();
52 bool Invalidate(int frame_number);
53 bool NeedsRecording(int frame_number, int distance_to_visible);
54 void SetPicture(scoped_refptr<Picture> picture);
55 const Picture* GetPicture() const;
57 float GetInvalidationFrequencyForTesting() const {
58 return GetInvalidationFrequency();
61 void ResetInvalidationHistory();
63 private:
64 void AdvanceInvalidationHistory(int frame_number);
65 float GetInvalidationFrequency() const;
67 int last_frame_number_;
68 scoped_refptr<const Picture> picture_;
69 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_;
72 typedef std::pair<int, int> PictureMapKey;
73 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap;
75 // An internal CanRaster check that goes to the picture_map rather than
76 // using the recorded_viewport hint.
77 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
79 void Clear();
81 void SetMinContentsScale(float min_contents_scale);
82 void SetTileGridSize(const gfx::Size& tile_grid_size);
84 gfx::Rect PaddedRect(const PictureMapKey& key) const;
85 gfx::Rect PadRect(const gfx::Rect& rect) const;
87 int buffer_pixels() const { return tiling_.border_texels(); }
89 // A picture pile is a tiled set of pictures. The picture map is a map of tile
90 // indices to picture infos.
91 PictureMap picture_map_;
92 TilingData tiling_;
94 // If non-empty, all pictures tiles inside this rect are recorded. There may
95 // be recordings outside this rect, but everything inside the rect is
96 // recorded.
97 gfx::Rect recorded_viewport_;
98 float min_contents_scale_;
99 gfx::Size tile_grid_size_;
100 int slow_down_raster_scale_factor_for_debug_;
101 // A hint about whether there are any recordings. This may be a false
102 // positive.
103 bool has_any_recordings_;
104 bool clear_canvas_with_debug_color_;
105 bool requires_clear_;
106 bool is_solid_color_;
107 SkColor solid_color_;
108 SkColor background_color_;
109 int pixel_record_distance_;
111 private:
112 friend class PicturePileImpl;
114 void CreatePictures(ContentLayerClient* painter,
115 RecordingMode recording_mode,
116 const std::vector<gfx::Rect>& record_rects);
117 void GetInvalidTileRects(const gfx::Rect& interest_rect,
118 Region* invalidation,
119 const gfx::Rect& visible_layer_rect,
120 int frame_number,
121 std::vector<gfx::Rect>* invalid_tiles);
122 bool ApplyInvalidationAndResize(const gfx::Rect& interest_rect,
123 Region* invalidation,
124 const gfx::Size& layer_size,
125 int frame_number);
126 void DetermineIfSolidColor();
127 void SetBufferPixels(int buffer_pixels);
129 bool is_suitable_for_gpu_rasterization_;
131 DISALLOW_COPY_AND_ASSIGN(PicturePile);
134 } // namespace cc
136 #endif // CC_RESOURCES_PICTURE_PILE_H_