Update V8 to version 4.7.37.
[chromium-blink-merge.git] / cc / playback / picture_pile_impl.h
bloba7f1e8fb505956b3f6a10a95bec47292345fb905
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& layer_rect,
54 std::vector<skia::PositionPixelRef>* pixel_refs) const override;
55 bool CoversRect(const gfx::Rect& layer_rect) const override;
56 void SetShouldAttemptToUseDistanceFieldText() 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 gfx::Rect RecordedViewport() const override;
63 bool CanUseLCDText() const override;
64 scoped_refptr<RasterSource> CreateCloneWithoutLCDText() const override;
66 // Tracing functionality.
67 void DidBeginTracing() override;
68 void AsValueInto(base::trace_event::TracedValue* array) const override;
69 skia::RefPtr<SkPicture> GetFlattenedPicture() override;
70 size_t GetPictureMemoryUsage() const override;
72 // Iterator used to return SkPixelRefs from this picture pile.
73 // Public for testing.
74 class CC_EXPORT PixelRefIterator {
75 public:
76 PixelRefIterator(const gfx::Rect& layer_rect,
77 const PicturePileImpl* picture_pile);
78 ~PixelRefIterator();
80 const skia::PositionPixelRef* operator->() const {
81 return &(*pixel_ref_iterator_);
83 const skia::PositionPixelRef& operator*() const {
84 return *pixel_ref_iterator_;
86 PixelRefIterator& operator++();
87 operator bool() const { return pixel_ref_iterator_; }
89 private:
90 void AdvanceToTilePictureWithPixelRefs();
92 const PicturePileImpl* picture_pile_;
93 gfx::Rect layer_rect_;
94 TilingData::Iterator tile_iterator_;
95 PixelRefMap::Iterator pixel_ref_iterator_;
96 std::set<const void*> processed_pictures_;
99 protected:
100 friend class PicturePile;
101 friend class PixelRefIterator;
103 using PictureMapKey = PicturePile::PictureMapKey;
104 using PictureMap = PicturePile::PictureMap;
106 PicturePileImpl();
107 explicit PicturePileImpl(const PicturePile* other, bool can_use_lcd_text);
108 explicit PicturePileImpl(const PicturePileImpl* other, bool can_use_lcd_text);
109 ~PicturePileImpl() override;
111 int buffer_pixels() const { return tiling_.border_texels(); }
113 // These members are const as this raster source may be in use on another
114 // thread and so should not be touched after construction.
115 const PictureMap picture_map_;
116 const TilingData tiling_;
117 const SkColor background_color_;
118 const bool requires_clear_;
119 const bool can_use_lcd_text_;
120 const bool is_solid_color_;
121 const SkColor solid_color_;
122 const gfx::Rect recorded_viewport_;
123 const bool has_any_recordings_;
124 const bool clear_canvas_with_debug_color_;
125 const float min_contents_scale_;
126 const int slow_down_raster_scale_factor_for_debug_;
127 // TODO(enne/vmiura): this has a read/write race between raster and compositor
128 // threads with multi-threaded Ganesh. Make this const or remove it.
129 bool should_attempt_to_use_distance_field_text_;
131 size_t picture_memory_usage_;
133 private:
134 typedef std::map<const Picture*, Region> PictureRegionMap;
136 // Called when analyzing a tile. We can use AnalysisCanvas as
137 // SkPicture::AbortCallback, which allows us to early out from analysis.
138 void RasterForAnalysis(skia::AnalysisCanvas* canvas,
139 const gfx::Rect& canvas_rect,
140 float contents_scale) const;
142 void CoalesceRasters(const gfx::Rect& canvas_rect,
143 const gfx::Rect& content_rect,
144 float contents_scale,
145 PictureRegionMap* result) const;
147 void RasterCommon(SkCanvas* canvas,
148 SkPicture::AbortCallback* callback,
149 const gfx::Rect& canvas_rect,
150 float contents_scale) const;
152 // An internal CanRaster check that goes to the picture_map rather than
153 // using the recorded_viewport hint.
154 bool CanRasterSlowTileCheck(const gfx::Rect& layer_rect) const;
156 gfx::Rect PaddedRect(const PictureMapKey& key) const;
158 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl);
161 } // namespace cc
163 #endif // CC_PLAYBACK_PICTURE_PILE_IMPL_H_