Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / cc / playback / picture_pile_impl.h
blob61288def758b63a82f0dbcbcc2f0f2da518a5c38
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_PLAYBACK_PICTURE_PILE_IMPL_H_
6 #define CC_PLAYBACK_PICTURE_PILE_IMPL_H_
8 #include <map>
9 #include <set>
10 #include <vector>
12 #include "base/time/time.h"
13 #include "cc/base/cc_export.h"
14 #include "cc/debug/rendering_stats_instrumentation.h"
15 #include "cc/playback/discardable_image_map.h"
16 #include "cc/playback/picture_pile.h"
17 #include "cc/playback/raster_source.h"
18 #include "skia/ext/analysis_canvas.h"
19 #include "skia/ext/refptr.h"
21 class SkCanvas;
22 class SkPicture;
24 namespace gfx {
25 class Rect;
28 namespace cc {
30 class CC_EXPORT PicturePileImpl : public RasterSource {
31 public:
32 static scoped_refptr<PicturePileImpl> CreateFromPicturePile(
33 const PicturePile* other,
34 bool can_use_lcd_text);
36 // RasterSource overrides. See RasterSource header for full description.
37 // When slow-down-raster-scale-factor is set to a value greater than 1, the
38 // reported rasterize time (in stats_instrumentation) is the minimum measured
39 // value over all runs.
40 void PlaybackToCanvas(SkCanvas* canvas,
41 const gfx::Rect& canvas_bitmap_rect,
42 const gfx::Rect& canvas_playback_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,
49 float contents_scale,
50 RasterSource::SolidColorAnalysis* analysis) const override;
51 void GatherDiscardableImages(
52 const gfx::Rect& layer_rect,
53 std::vector<skia::PositionImage>* images) const override;
54 bool CoversRect(const gfx::Rect& layer_rect) const override;
55 void SetShouldAttemptToUseDistanceFieldText() override;
56 bool ShouldAttemptToUseDistanceFieldText() const override;
57 gfx::Size GetSize() const override;
58 bool IsSolidColor() const override;
59 SkColor GetSolidColor() const override;
60 bool HasRecordings() const override;
61 gfx::Rect RecordedViewport() const override;
62 bool CanUseLCDText() const override;
63 scoped_refptr<RasterSource> CreateCloneWithoutLCDText() const override;
65 // Tracing functionality.
66 void DidBeginTracing() override;
67 void AsValueInto(base::trace_event::TracedValue* array) const override;
68 skia::RefPtr<SkPicture> GetFlattenedPicture() override;
69 size_t GetPictureMemoryUsage() const override;
71 // Iterator used to return SkImages from this picture pile.
72 // Public for testing.
73 class CC_EXPORT ImageIterator {
74 public:
75 ImageIterator(const gfx::Rect& layer_rect,
76 const PicturePileImpl* picture_pile);
77 ~ImageIterator();
79 const skia::PositionImage* operator->() const {
80 return &(*image_iterator_);
82 const skia::PositionImage& operator*() const { return *image_iterator_; }
83 ImageIterator& operator++();
84 operator bool() const { return image_iterator_; }
86 private:
87 void AdvanceToTilePictureWithImages();
89 const PicturePileImpl* picture_pile_;
90 gfx::Rect layer_rect_;
91 TilingData::Iterator tile_iterator_;
92 DiscardableImageMap::Iterator image_iterator_;
93 std::set<const void*> processed_pictures_;
96 protected:
97 friend class PicturePile;
98 friend class ImageIterator;
100 using PictureMapKey = PicturePile::PictureMapKey;
101 using PictureMap = PicturePile::PictureMap;
103 PicturePileImpl();
104 explicit PicturePileImpl(const PicturePile* other, bool can_use_lcd_text);
105 explicit PicturePileImpl(const PicturePileImpl* other, bool can_use_lcd_text);
106 ~PicturePileImpl() override;
108 int buffer_pixels() const { return tiling_.border_texels(); }
110 // These members are const as this raster source may be in use on another
111 // thread and so should not be touched after construction.
112 const PictureMap picture_map_;
113 const TilingData tiling_;
114 const SkColor background_color_;
115 const bool requires_clear_;
116 const bool can_use_lcd_text_;
117 const bool is_solid_color_;
118 const SkColor solid_color_;
119 const gfx::Rect recorded_viewport_;
120 const bool has_any_recordings_;
121 const bool clear_canvas_with_debug_color_;
122 const float min_contents_scale_;
123 const int slow_down_raster_scale_factor_for_debug_;
124 // TODO(enne/vmiura): this has a read/write race between raster and compositor
125 // threads with multi-threaded Ganesh. Make this const or remove it.
126 bool should_attempt_to_use_distance_field_text_;
128 size_t picture_memory_usage_;
130 private:
131 typedef std::map<const Picture*, Region> PictureRegionMap;
133 // Called when analyzing a tile. We can use AnalysisCanvas as
134 // SkPicture::AbortCallback, which allows us to early out from analysis.
135 void RasterForAnalysis(skia::AnalysisCanvas* canvas,
136 const gfx::Rect& canvas_rect,
137 float contents_scale) const;
139 void CoalesceRasters(const gfx::Rect& canvas_rect,
140 const gfx::Rect& content_rect,
141 float contents_scale,
142 PictureRegionMap* result) const;
144 void RasterCommon(SkCanvas* canvas,
145 SkPicture::AbortCallback* callback,
146 const gfx::Rect& canvas_rect,
147 float contents_scale) const;
149 // An internal CanRaster check that goes to the picture_map rather than
150 // using the recorded_viewport hint.
151 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
153 gfx::Rect PaddedRect(const PictureMapKey& key) const;
155 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl);
158 } // namespace cc
160 #endif // CC_PLAYBACK_PICTURE_PILE_IMPL_H_