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