Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / cc / resources / picture_pile_impl.h
blob54a69880d2e1ba422bd20da250720b5375aa4727
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 "skia/ext/analysis_canvas.h"
18 #include "skia/ext/refptr.h"
19 #include "third_party/skia/include/core/SkPicture.h"
21 namespace cc {
23 class CC_EXPORT PicturePileImpl : public PicturePileBase {
24 public:
25 static scoped_refptr<PicturePileImpl> Create();
26 static scoped_refptr<PicturePileImpl> CreateFromOther(
27 const PicturePileBase* other);
29 // Get paint-safe version of this picture for a specific thread.
30 PicturePileImpl* GetCloneForDrawingOnThread(unsigned thread_index) const;
32 // Raster a subrect of this PicturePileImpl into the given canvas.
33 // It's only safe to call paint on a cloned version. It is assumed
34 // that contents_scale has already been applied to this canvas.
35 // Writes the total number of pixels rasterized and the time spent
36 // rasterizing to the stats if the respective pointer is not
37 // NULL. When slow-down-raster-scale-factor is set to a value
38 // greater than 1, the reported rasterize time is the minimum
39 // measured value over all runs.
40 void RasterDirect(
41 SkCanvas* canvas,
42 const gfx::Rect& canvas_rect,
43 float contents_scale,
44 RenderingStatsInstrumentation* rendering_stats_instrumentation);
46 // Similar to the above RasterDirect method, but this is a convenience method
47 // for when it is known that the raster is going to an intermediate bitmap
48 // that itself will then be blended and thus that a canvas clear is required.
49 void RasterToBitmap(
50 SkCanvas* canvas,
51 const gfx::Rect& canvas_rect,
52 float contents_scale,
53 RenderingStatsInstrumentation* stats_instrumentation);
55 // Called when analyzing a tile. We can use AnalysisCanvas as
56 // SkDrawPictureCallback, which allows us to early out from analysis.
57 void RasterForAnalysis(
58 skia::AnalysisCanvas* canvas,
59 const gfx::Rect& canvas_rect,
60 float contents_scale,
61 RenderingStatsInstrumentation* stats_instrumentation);
63 skia::RefPtr<SkPicture> GetFlattenedPicture();
65 struct CC_EXPORT Analysis {
66 Analysis();
67 ~Analysis();
69 bool is_solid_color;
70 bool has_text;
71 SkColor solid_color;
74 void AnalyzeInRect(const gfx::Rect& content_rect,
75 float contents_scale,
76 Analysis* analysis);
78 void AnalyzeInRect(const gfx::Rect& content_rect,
79 float contents_scale,
80 Analysis* analysis,
81 RenderingStatsInstrumentation* stats_instrumentation);
83 class CC_EXPORT PixelRefIterator {
84 public:
85 PixelRefIterator(const gfx::Rect& content_rect,
86 float contents_scale,
87 const PicturePileImpl* picture_pile);
88 ~PixelRefIterator();
90 SkPixelRef* operator->() const { return *pixel_ref_iterator_; }
91 SkPixelRef* operator*() const { return *pixel_ref_iterator_; }
92 PixelRefIterator& operator++();
93 operator bool() const { return pixel_ref_iterator_; }
95 private:
96 void AdvanceToTilePictureWithPixelRefs();
98 const PicturePileImpl* picture_pile_;
99 gfx::Rect layer_rect_;
100 TilingData::Iterator tile_iterator_;
101 Picture::PixelRefIterator pixel_ref_iterator_;
102 std::set<const void*> processed_pictures_;
105 void DidBeginTracing();
107 protected:
108 friend class PicturePile;
109 friend class PixelRefIterator;
111 PicturePileImpl();
112 explicit PicturePileImpl(const PicturePileBase* other);
113 virtual ~PicturePileImpl();
115 private:
116 class ClonesForDrawing {
117 public:
118 ClonesForDrawing(const PicturePileImpl* pile, int num_threads);
119 ~ClonesForDrawing();
121 typedef std::vector<scoped_refptr<PicturePileImpl> > PicturePileVector;
122 PicturePileVector clones_;
125 static scoped_refptr<PicturePileImpl> CreateCloneForDrawing(
126 const PicturePileImpl* other, unsigned thread_index);
128 PicturePileImpl(const PicturePileImpl* other, unsigned thread_index);
130 private:
131 typedef std::map<Picture*, Region> PictureRegionMap;
132 void CoalesceRasters(const gfx::Rect& canvas_rect,
133 const gfx::Rect& content_rect,
134 float contents_scale,
135 PictureRegionMap* result);
137 void RasterCommon(
138 SkCanvas* canvas,
139 SkDrawPictureCallback* callback,
140 const gfx::Rect& canvas_rect,
141 float contents_scale,
142 RenderingStatsInstrumentation* rendering_stats_instrumentation,
143 bool is_analysis);
145 // Once instantiated, |clones_for_drawing_| can't be modified. This
146 // guarantees thread-safe access during the life time of a PicturePileImpl
147 // instance. This member variable must be last so that other member
148 // variables have already been initialized and can be clonable.
149 const ClonesForDrawing clones_for_drawing_;
151 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl);
154 } // namespace cc
156 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_