OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCES_PICTURE_PILE_H_ | 5 #ifndef CC_RESOURCES_PICTURE_PILE_H_ |
6 #define CC_RESOURCES_PICTURE_PILE_H_ | 6 #define CC_RESOURCES_PICTURE_PILE_H_ |
7 | 7 |
| 8 #include <bitset> |
| 9 |
8 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
9 #include "cc/resources/picture_pile_base.h" | 11 #include "cc/base/tiling_data.h" |
10 #include "ui/gfx/geometry/rect.h" | 12 #include "cc/resources/recording_source.h" |
11 | 13 |
12 namespace cc { | 14 namespace cc { |
13 class PicturePileImpl; | 15 class PicturePileImpl; |
14 class Region; | |
15 class RenderingStatsInstrumentation; | |
16 | 16 |
17 class CC_EXPORT PicturePile : public PicturePileBase { | 17 class CC_EXPORT PicturePile : public RecordingSource { |
18 public: | 18 public: |
19 PicturePile(); | 19 PicturePile(); |
20 ~PicturePile() override; | 20 ~PicturePile() override; |
21 | 21 |
22 // Re-record parts of the picture that are invalid. | 22 // RecordingSource overrides. |
23 // Invalidations are in layer space, and will be expanded to cover everything | |
24 // that was either recorded/changed or that has no recording, leaving out only | |
25 // pieces that we had a recording for and it was not changed. | |
26 // Return true iff the pile was modified. | |
27 bool UpdateAndExpandInvalidation( | 23 bool UpdateAndExpandInvalidation( |
28 ContentLayerClient* painter, | 24 ContentLayerClient* painter, |
29 Region* invalidation, | 25 Region* invalidation, |
30 SkColor background_color, | 26 SkColor background_color, |
31 bool contents_opaque, | 27 bool contents_opaque, |
32 bool contents_fill_bounds_completely, | 28 bool contents_fill_bounds_completely, |
33 const gfx::Size& layer_size, | 29 const gfx::Size& layer_size, |
34 const gfx::Rect& visible_layer_rect, | 30 const gfx::Rect& visible_layer_rect, |
35 int frame_number, | 31 int frame_number, |
36 Picture::RecordingMode recording_mode, | 32 Picture::RecordingMode recording_mode) override; |
37 RenderingStatsInstrumentation* stats_instrumentation); | 33 gfx::Size GetSize() const final; |
| 34 void SetEmptyBounds() override; |
| 35 void SetMinContentsScale(float min_contents_scale) override; |
| 36 void SetTileGridSize(const gfx::Size& tile_grid_size) override; |
| 37 void SetSlowdownRasterScaleFactor(int factor) override; |
| 38 void SetIsMask(bool is_mask) override; |
| 39 bool IsSuitableForGpuRasterization() const override; |
| 40 scoped_refptr<RasterSource> CreateRasterSource() const override; |
| 41 void SetUnsuitableForGpuRasterizationForTesting() override; |
| 42 SkTileGridFactory::TileGridInfo GetTileGridInfoForTesting() const override; |
38 | 43 |
39 void SetEmptyBounds(); | 44 static void ComputeTileGridInfo(const gfx::Size& tile_grid_size, |
| 45 SkTileGridFactory::TileGridInfo* info); |
40 | 46 |
41 void set_slow_down_raster_scale_factor(int factor) { | 47 protected: |
42 slow_down_raster_scale_factor_for_debug_ = factor; | 48 class CC_EXPORT PictureInfo { |
43 } | 49 public: |
| 50 enum { INVALIDATION_FRAMES_TRACKED = 32 }; |
44 | 51 |
45 void set_show_debug_picture_borders(bool show) { | 52 PictureInfo(); |
46 show_debug_picture_borders_ = show; | 53 ~PictureInfo(); |
47 } | |
48 | 54 |
49 bool is_suitable_for_gpu_rasterization() const { | 55 bool Invalidate(int frame_number); |
50 return is_suitable_for_gpu_rasterization_; | 56 bool NeedsRecording(int frame_number, int distance_to_visible); |
51 } | 57 void SetPicture(scoped_refptr<Picture> picture); |
52 void SetUnsuitableForGpuRasterizationForTesting() { | 58 const Picture* GetPicture() const; |
53 is_suitable_for_gpu_rasterization_ = false; | |
54 } | |
55 | 59 |
56 void SetPixelRecordDistanceForTesting(int d) { pixel_record_distance_ = d; } | 60 float GetInvalidationFrequencyForTesting() const { |
| 61 return GetInvalidationFrequency(); |
| 62 } |
| 63 |
| 64 private: |
| 65 void AdvanceInvalidationHistory(int frame_number); |
| 66 float GetInvalidationFrequency() const; |
| 67 |
| 68 int last_frame_number_; |
| 69 scoped_refptr<const Picture> picture_; |
| 70 std::bitset<INVALIDATION_FRAMES_TRACKED> invalidation_history_; |
| 71 }; |
| 72 |
| 73 typedef std::pair<int, int> PictureMapKey; |
| 74 typedef base::hash_map<PictureMapKey, PictureInfo> PictureMap; |
| 75 |
| 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; |
| 79 |
| 80 void Clear(); |
| 81 |
| 82 gfx::Rect PaddedRect(const PictureMapKey& key) const; |
| 83 gfx::Rect PadRect(const gfx::Rect& rect) const; |
| 84 |
| 85 int buffer_pixels() const { return tiling_.border_texels(); } |
| 86 |
| 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_; |
| 91 |
| 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 SkColor background_color_; |
| 99 int slow_down_raster_scale_factor_for_debug_; |
| 100 bool contents_opaque_; |
| 101 bool contents_fill_bounds_completely_; |
| 102 bool clear_canvas_with_debug_color_; |
| 103 // A hint about whether there are any recordings. This may be a false |
| 104 // positive. |
| 105 bool has_any_recordings_; |
| 106 bool is_mask_; |
| 107 bool is_solid_color_; |
| 108 SkColor solid_color_; |
| 109 int pixel_record_distance_; |
57 | 110 |
58 private: | 111 private: |
59 friend class PicturePileImpl; | 112 friend class PicturePileImpl; |
60 | 113 |
61 void DetermineIfSolidColor(); | 114 void DetermineIfSolidColor(); |
| 115 void SetBufferPixels(int buffer_pixels); |
62 | 116 |
63 bool is_suitable_for_gpu_rasterization_; | 117 bool is_suitable_for_gpu_rasterization_; |
64 int pixel_record_distance_; | |
65 | 118 |
66 DISALLOW_COPY_AND_ASSIGN(PicturePile); | 119 DISALLOW_COPY_AND_ASSIGN(PicturePile); |
67 }; | 120 }; |
68 | 121 |
69 } // namespace cc | 122 } // namespace cc |
70 | 123 |
71 #endif // CC_RESOURCES_PICTURE_PILE_H_ | 124 #endif // CC_RESOURCES_PICTURE_PILE_H_ |
OLD | NEW |