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_IMPL_H_
6 #define CC_RESOURCES_PICTURE_PILE_IMPL_H_
12 #include "base/time/time.h"
13 #include "cc/base/cc_export.h"
14 #include "cc/debug/rendering_stats_instrumentation.h"
15 #include "cc/resources/picture_pile.h"
16 #include "cc/resources/raster_source.h"
17 #include "skia/ext/analysis_canvas.h"
18 #include "skia/ext/refptr.h"
30 class CC_EXPORT PicturePileImpl
: public RasterSource
{
32 static scoped_refptr
<PicturePileImpl
> CreateFromPicturePile(
33 const PicturePile
* other
);
35 // RasterSource overrides. See RasterSource header for full description.
36 // When slow-down-raster-scale-factor is set to a value greater than 1, the
37 // reported rasterize time (in stats_instrumentation) is the minimum measured
38 // value over all runs.
39 void PlaybackToCanvas(SkCanvas
* canvas
,
40 const gfx::Rect
& canvas_rect
,
41 float contents_scale
) const override
;
42 void PlaybackToSharedCanvas(SkCanvas
* canvas
,
43 const gfx::Rect
& canvas_rect
,
44 float contents_scale
) const override
;
45 void PerformSolidColorAnalysis(
46 const gfx::Rect
& content_rect
,
48 RasterSource::SolidColorAnalysis
* analysis
) const override
;
49 void GatherPixelRefs(const gfx::Rect
& content_rect
,
51 std::vector
<SkPixelRef
*>* pixel_refs
) const override
;
52 bool CoversRect(const gfx::Rect
& content_rect
,
53 float contents_scale
) const override
;
54 void SetShouldAttemptToUseDistanceFieldText() override
;
55 void SetBackgoundColor(SkColor background_color
) override
;
56 void SetRequiresClear(bool requires_clear
) override
;
57 bool ShouldAttemptToUseDistanceFieldText() const override
;
58 gfx::Size
GetSize() const override
;
59 bool IsSolidColor() const override
;
60 SkColor
GetSolidColor() const override
;
61 bool HasRecordings() const override
;
62 bool CanUseLCDText() const override
;
64 // Tracing functionality.
65 void DidBeginTracing() override
;
66 void AsValueInto(base::debug::TracedValue
* array
) const override
;
67 skia::RefPtr
<SkPicture
> GetFlattenedPicture() override
;
68 size_t GetPictureMemoryUsage() const override
;
70 // Iterator used to return SkPixelRefs from this picture pile.
71 // Public for testing.
72 class CC_EXPORT PixelRefIterator
{
74 PixelRefIterator(const gfx::Rect
& content_rect
,
76 const PicturePileImpl
* picture_pile
);
79 SkPixelRef
* operator->() const { return *pixel_ref_iterator_
; }
80 SkPixelRef
* operator*() const { return *pixel_ref_iterator_
; }
81 PixelRefIterator
& operator++();
82 operator bool() const { return pixel_ref_iterator_
; }
85 void AdvanceToTilePictureWithPixelRefs();
87 const PicturePileImpl
* picture_pile_
;
88 gfx::Rect layer_rect_
;
89 TilingData::Iterator tile_iterator_
;
90 Picture::PixelRefIterator pixel_ref_iterator_
;
91 std::set
<const void*> processed_pictures_
;
95 friend class PicturePile
;
96 friend class PixelRefIterator
;
98 // TODO(vmpstr): Change this when pictures are split from invalidation info.
99 using PictureMapKey
= PicturePile::PictureMapKey
;
100 using PictureMap
= PicturePile::PictureMap
;
101 using PictureInfo
= PicturePile::PictureInfo
;
104 explicit PicturePileImpl(const PicturePile
* other
);
105 ~PicturePileImpl() override
;
107 int buffer_pixels() const { return tiling_
.border_texels(); }
109 PictureMap picture_map_
;
111 SkColor background_color_
;
112 bool requires_clear_
;
113 bool can_use_lcd_text_
;
114 bool is_solid_color_
;
115 SkColor solid_color_
;
116 gfx::Rect recorded_viewport_
;
117 bool has_any_recordings_
;
118 bool clear_canvas_with_debug_color_
;
119 float min_contents_scale_
;
120 int slow_down_raster_scale_factor_for_debug_
;
123 typedef std::map
<const Picture
*, Region
> PictureRegionMap
;
125 // Called when analyzing a tile. We can use AnalysisCanvas as
126 // SkDrawPictureCallback, which allows us to early out from analysis.
127 void RasterForAnalysis(skia::AnalysisCanvas
* canvas
,
128 const gfx::Rect
& canvas_rect
,
129 float contents_scale
) const;
131 void CoalesceRasters(const gfx::Rect
& canvas_rect
,
132 const gfx::Rect
& content_rect
,
133 float contents_scale
,
134 PictureRegionMap
* result
) const;
138 SkDrawPictureCallback
* callback
,
139 const gfx::Rect
& canvas_rect
,
140 float contents_scale
,
141 bool is_analysis
) const;
143 // An internal CanRaster check that goes to the picture_map rather than
144 // using the recorded_viewport hint.
145 bool CanRasterSlowTileCheck(const gfx::Rect
& layer_rect
) const;
147 gfx::Rect
PaddedRect(const PictureMapKey
& key
) const;
149 bool should_attempt_to_use_distance_field_text_
;
151 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl
);
156 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_