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_
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"
18 class PicturePileImpl
;
20 class CC_EXPORT PicturePile
: public RecordingSource
{
22 PicturePile(float min_contents_scale
, const gfx::Size
& tile_grid_size
);
23 ~PicturePile() override
;
25 // RecordingSource overrides.
26 bool UpdateAndExpandInvalidation(ContentLayerClient
* painter
,
28 const gfx::Size
& layer_size
,
29 const gfx::Rect
& visible_layer_rect
,
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
;
45 class CC_EXPORT PictureInfo
{
47 enum { INVALIDATION_FRAMES_TRACKED
= 32 };
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();
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;
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_
;
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
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
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_
;
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
,
121 std::vector
<gfx::Rect
>* invalid_tiles
);
122 bool ApplyInvalidationAndResize(const gfx::Rect
& interest_rect
,
123 Region
* invalidation
,
124 const gfx::Size
& layer_size
,
126 void DetermineIfSolidColor();
127 void SetBufferPixels(int buffer_pixels
);
129 bool is_suitable_for_gpu_rasterization_
;
131 DISALLOW_COPY_AND_ASSIGN(PicturePile
);
136 #endif // CC_RESOURCES_PICTURE_PILE_H_