cc: Remove some of the instrumentation plumbing
[chromium-blink-merge.git] / cc / resources / picture_pile_impl.h
blob9f350a9933c0bc18dbfd695dbfaf531f7e7a2392
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_
8 #include <list>
9 #include <map>
10 #include <set>
11 #include <vector>
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_base.h"
17 #include "cc/resources/raster_source.h"
18 #include "skia/ext/analysis_canvas.h"
19 #include "skia/ext/refptr.h"
20 #include "third_party/skia/include/core/SkPicture.h"
22 namespace cc {
24 // TODO(vmpstr): Clean up PicturePileBase and make it a member.
25 class CC_EXPORT PicturePileImpl : public PicturePileBase, public RasterSource {
26 public:
27 static scoped_refptr<PicturePileImpl> Create();
28 static scoped_refptr<PicturePileImpl> CreateFromOther(
29 const PicturePileBase* other);
31 // RasterSource overrides. See RasterSource header for full description.
32 // When slow-down-raster-scale-factor is set to a value greater than 1, the
33 // reported rasterize time (in stats_instrumentation) is the minimum measured
34 // value over all runs.
35 void PlaybackToCanvas(SkCanvas* canvas,
36 const gfx::Rect& canvas_rect,
37 float contents_scale) const override;
38 void PerformSolidColorAnalysis(
39 const gfx::Rect& content_rect,
40 float contents_scale,
41 RasterSource::SolidColorAnalysis* analysis) const override;
42 void GatherPixelRefs(const gfx::Rect& content_rect,
43 float contents_scale,
44 std::vector<SkPixelRef*>* pixel_refs) const override;
45 bool CoversRect(const gfx::Rect& content_rect,
46 float contents_scale) const override;
47 bool SuitableForDistanceFieldText() const override;
49 // Raster into the canvas without applying clips.
50 void RasterDirect(SkCanvas* canvas,
51 const gfx::Rect& canvas_rect,
52 float contents_scale) const;
54 // Tracing functionality.
55 void DidBeginTracing();
56 skia::RefPtr<SkPicture> GetFlattenedPicture();
58 void set_likely_to_be_used_for_transform_animation() {
59 likely_to_be_used_for_transform_animation_ = true;
62 // Iterator used to return SkPixelRefs from this picture pile.
63 // Public for testing.
64 class CC_EXPORT PixelRefIterator {
65 public:
66 PixelRefIterator(const gfx::Rect& content_rect,
67 float contents_scale,
68 const PicturePileImpl* picture_pile);
69 ~PixelRefIterator();
71 SkPixelRef* operator->() const { return *pixel_ref_iterator_; }
72 SkPixelRef* operator*() const { return *pixel_ref_iterator_; }
73 PixelRefIterator& operator++();
74 operator bool() const { return pixel_ref_iterator_; }
76 private:
77 void AdvanceToTilePictureWithPixelRefs();
79 const PicturePileImpl* picture_pile_;
80 gfx::Rect layer_rect_;
81 TilingData::Iterator tile_iterator_;
82 Picture::PixelRefIterator pixel_ref_iterator_;
83 std::set<const void*> processed_pictures_;
86 protected:
87 friend class PicturePile;
88 friend class PixelRefIterator;
90 PicturePileImpl();
91 explicit PicturePileImpl(const PicturePileBase* other);
92 ~PicturePileImpl() override;
94 private:
95 typedef std::map<const Picture*, Region> PictureRegionMap;
97 // Called when analyzing a tile. We can use AnalysisCanvas as
98 // SkDrawPictureCallback, which allows us to early out from analysis.
99 void RasterForAnalysis(skia::AnalysisCanvas* canvas,
100 const gfx::Rect& canvas_rect,
101 float contents_scale) const;
103 void CoalesceRasters(const gfx::Rect& canvas_rect,
104 const gfx::Rect& content_rect,
105 float contents_scale,
106 PictureRegionMap* result) const;
108 void RasterCommon(
109 SkCanvas* canvas,
110 SkDrawPictureCallback* callback,
111 const gfx::Rect& canvas_rect,
112 float contents_scale,
113 bool is_analysis) const;
115 bool likely_to_be_used_for_transform_animation_;
117 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl);
120 } // namespace cc
122 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_