Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / cc / playback / picture_pile_impl.h
blob8da3cad1d92d4f97c2318a10717961cf879282f3
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/picture_pile.h"
16 #include "cc/playback/pixel_ref_map.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;
23 class SkPixelRef;
25 namespace gfx {
26 class Rect;
29 namespace cc {
31 class CC_EXPORT PicturePileImpl : public RasterSource {
32 public:
33 static scoped_refptr<PicturePileImpl> CreateFromPicturePile(
34 const PicturePile* other,
35 bool can_use_lcd_text);
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_bitmap_rect,
43 const gfx::Rect& canvas_playback_rect,
44 float contents_scale) const override;
45 void PlaybackToSharedCanvas(SkCanvas* canvas,
46 const gfx::Rect& canvas_rect,
47 float contents_scale) const override;
48 void PerformSolidColorAnalysis(
49 const gfx::Rect& content_rect,
50 float contents_scale,
51 RasterSource::SolidColorAnalysis* analysis) const override;
52 void GatherPixelRefs(
53 const gfx::Rect& content_rect,
54 float contents_scale,
55 std::vector<skia::PositionPixelRef>* pixel_refs) const override;
56 bool CoversRect(const gfx::Rect& content_rect,
57 float contents_scale) const override;
58 void SetShouldAttemptToUseDistanceFieldText() 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;
65 scoped_refptr<RasterSource> CreateCloneWithoutLCDText() const override;
67 // Tracing functionality.
68 void DidBeginTracing() override;
69 void AsValueInto(base::trace_event::TracedValue* array) const override;
70 skia::RefPtr<SkPicture> GetFlattenedPicture() override;
71 size_t GetPictureMemoryUsage() const override;
73 // Iterator used to return SkPixelRefs from this picture pile.
74 // Public for testing.
75 class CC_EXPORT PixelRefIterator {
76 public:
77 PixelRefIterator(const gfx::Rect& content_rect,
78 float contents_scale,
79 const PicturePileImpl* picture_pile);
80 ~PixelRefIterator();
82 const skia::PositionPixelRef* operator->() const {
83 return &(*pixel_ref_iterator_);
85 const skia::PositionPixelRef& operator*() const {
86 return *pixel_ref_iterator_;
88 PixelRefIterator& operator++();
89 operator bool() const { return pixel_ref_iterator_; }
91 private:
92 void AdvanceToTilePictureWithPixelRefs();
94 const PicturePileImpl* picture_pile_;
95 gfx::Rect layer_rect_;
96 TilingData::Iterator tile_iterator_;
97 PixelRefMap::Iterator pixel_ref_iterator_;
98 std::set<const void*> processed_pictures_;
101 protected:
102 friend class PicturePile;
103 friend class PixelRefIterator;
105 using PictureMapKey = PicturePile::PictureMapKey;
106 using PictureMap = PicturePile::PictureMap;
108 PicturePileImpl();
109 explicit PicturePileImpl(const PicturePile* other, bool can_use_lcd_text);
110 explicit PicturePileImpl(const PicturePileImpl* other, bool can_use_lcd_text);
111 ~PicturePileImpl() override;
113 int buffer_pixels() const { return tiling_.border_texels(); }
115 // These members are const as this raster source may be in use on another
116 // thread and so should not be touched after construction.
117 const PictureMap picture_map_;
118 const TilingData tiling_;
119 const SkColor background_color_;
120 const bool requires_clear_;
121 const bool can_use_lcd_text_;
122 const bool is_solid_color_;
123 const SkColor solid_color_;
124 const gfx::Rect recorded_viewport_;
125 const bool has_any_recordings_;
126 const bool clear_canvas_with_debug_color_;
127 const float min_contents_scale_;
128 const int slow_down_raster_scale_factor_for_debug_;
129 // TODO(enne/vmiura): this has a read/write race between raster and compositor
130 // threads with multi-threaded Ganesh. Make this const or remove it.
131 bool should_attempt_to_use_distance_field_text_;
133 size_t picture_memory_usage_;
135 private:
136 typedef std::map<const Picture*, Region> PictureRegionMap;
138 // Called when analyzing a tile. We can use AnalysisCanvas as
139 // SkPicture::AbortCallback, which allows us to early out from analysis.
140 void RasterForAnalysis(skia::AnalysisCanvas* canvas,
141 const gfx::Rect& canvas_rect,
142 float contents_scale) const;
144 void CoalesceRasters(const gfx::Rect& canvas_rect,
145 const gfx::Rect& content_rect,
146 float contents_scale,
147 PictureRegionMap* result) const;
149 void RasterCommon(SkCanvas* canvas,
150 SkPicture::AbortCallback* callback,
151 const gfx::Rect& canvas_rect,
152 float contents_scale) const;
154 // An internal CanRaster check that goes to the picture_map rather than
155 // using the recorded_viewport hint.
156 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
158 gfx::Rect PaddedRect(const PictureMapKey& key) const;
160 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl);
163 } // namespace cc
165 #endif // CC_PLAYBACK_PICTURE_PILE_IMPL_H_