OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCES_PICTURE_PILE_IMPL_H_ | 5 #ifndef CC_RESOURCES_PICTURE_PILE_IMPL_H_ |
6 #define CC_RESOURCES_PICTURE_PILE_IMPL_H_ | 6 #define CC_RESOURCES_PICTURE_PILE_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
15 #include "cc/debug/rendering_stats_instrumentation.h" | 15 #include "cc/debug/rendering_stats_instrumentation.h" |
16 #include "cc/resources/picture_pile_base.h" | 16 #include "cc/resources/picture_pile_base.h" |
17 #include "skia/ext/analysis_canvas.h" | 17 #include "skia/ext/analysis_canvas.h" |
18 #include "skia/ext/refptr.h" | 18 #include "skia/ext/refptr.h" |
19 #include "third_party/skia/include/core/SkPicture.h" | 19 #include "third_party/skia/include/core/SkPicture.h" |
20 | 20 |
21 namespace cc { | 21 namespace cc { |
22 | 22 |
23 class CC_EXPORT PicturePileImpl : public PicturePileBase { | 23 class CC_EXPORT PicturePileImpl : public PicturePileBase { |
24 public: | 24 public: |
25 static scoped_refptr<PicturePileImpl> Create(); | 25 static scoped_refptr<PicturePileImpl> Create(); |
26 static scoped_refptr<PicturePileImpl> CreateFromOther( | 26 static scoped_refptr<PicturePileImpl> CreateFromOther( |
27 const PicturePileBase* other); | 27 const PicturePileBase* other); |
28 | 28 |
29 // Get paint-safe version of this picture for a specific thread. | 29 // Raster a subrect of this PicturePileImpl into the given canvas. It is |
30 PicturePileImpl* GetCloneForDrawingOnThread(unsigned thread_index) const; | 30 // assumed that contents_scale has already been applied to this canvas. |
31 | |
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 | 31 // Writes the total number of pixels rasterized and the time spent |
36 // rasterizing to the stats if the respective pointer is not | 32 // rasterizing to the stats if the respective pointer is not NULL. When |
37 // NULL. When slow-down-raster-scale-factor is set to a value | 33 // slow-down-raster-scale-factor is set to a value greater than 1, the |
38 // greater than 1, the reported rasterize time is the minimum | 34 // reported rasterize time is the minimum measured value over all runs. |
39 // measured value over all runs. | |
40 void RasterDirect( | 35 void RasterDirect( |
41 SkCanvas* canvas, | 36 SkCanvas* canvas, |
42 const gfx::Rect& canvas_rect, | 37 const gfx::Rect& canvas_rect, |
43 float contents_scale, | 38 float contents_scale, |
44 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 39 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
45 | 40 |
46 // Similar to the above RasterDirect method, but this is a convenience method | 41 // 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 | 42 // 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. | 43 // that itself will then be blended and thus that a canvas clear is required. |
49 // Note that this function may write outside the canvas_rect. | 44 // Note that this function may write outside the canvas_rect. |
50 void RasterToBitmap( | 45 void RasterToBitmap( |
51 SkCanvas* canvas, | 46 SkCanvas* canvas, |
52 const gfx::Rect& canvas_rect, | 47 const gfx::Rect& canvas_rect, |
53 float contents_scale, | 48 float contents_scale, |
54 RenderingStatsInstrumentation* stats_instrumentation); | 49 RenderingStatsInstrumentation* stats_instrumentation) const; |
55 | 50 |
56 // Called when analyzing a tile. We can use AnalysisCanvas as | 51 // Called when analyzing a tile. We can use AnalysisCanvas as |
57 // SkDrawPictureCallback, which allows us to early out from analysis. | 52 // SkDrawPictureCallback, which allows us to early out from analysis. |
58 void RasterForAnalysis( | 53 void RasterForAnalysis( |
59 skia::AnalysisCanvas* canvas, | 54 skia::AnalysisCanvas* canvas, |
60 const gfx::Rect& canvas_rect, | 55 const gfx::Rect& canvas_rect, |
61 float contents_scale, | 56 float contents_scale, |
62 RenderingStatsInstrumentation* stats_instrumentation); | 57 RenderingStatsInstrumentation* stats_instrumentation) const; |
63 | 58 |
64 skia::RefPtr<SkPicture> GetFlattenedPicture(); | 59 skia::RefPtr<SkPicture> GetFlattenedPicture(); |
65 | 60 |
66 struct CC_EXPORT Analysis { | 61 struct CC_EXPORT Analysis { |
67 Analysis(); | 62 Analysis(); |
68 ~Analysis(); | 63 ~Analysis(); |
69 | 64 |
70 bool is_solid_color; | 65 bool is_solid_color; |
71 SkColor solid_color; | 66 SkColor solid_color; |
72 }; | 67 }; |
73 | 68 |
74 void AnalyzeInRect(const gfx::Rect& content_rect, | 69 void AnalyzeInRect(const gfx::Rect& content_rect, |
75 float contents_scale, | 70 float contents_scale, |
76 Analysis* analysis); | 71 Analysis* analysis) const; |
77 | 72 |
78 void AnalyzeInRect(const gfx::Rect& content_rect, | 73 void AnalyzeInRect( |
79 float contents_scale, | 74 const gfx::Rect& content_rect, |
80 Analysis* analysis, | 75 float contents_scale, |
81 RenderingStatsInstrumentation* stats_instrumentation); | 76 Analysis* analysis, |
| 77 RenderingStatsInstrumentation* stats_instrumentation) const; |
82 | 78 |
83 class CC_EXPORT PixelRefIterator { | 79 class CC_EXPORT PixelRefIterator { |
84 public: | 80 public: |
85 PixelRefIterator(const gfx::Rect& content_rect, | 81 PixelRefIterator(const gfx::Rect& content_rect, |
86 float contents_scale, | 82 float contents_scale, |
87 const PicturePileImpl* picture_pile); | 83 const PicturePileImpl* picture_pile); |
88 ~PixelRefIterator(); | 84 ~PixelRefIterator(); |
89 | 85 |
90 SkPixelRef* operator->() const { return *pixel_ref_iterator_; } | 86 SkPixelRef* operator->() const { return *pixel_ref_iterator_; } |
91 SkPixelRef* operator*() const { return *pixel_ref_iterator_; } | 87 SkPixelRef* operator*() const { return *pixel_ref_iterator_; } |
(...skipping 14 matching lines...) Expand all Loading... |
106 | 102 |
107 protected: | 103 protected: |
108 friend class PicturePile; | 104 friend class PicturePile; |
109 friend class PixelRefIterator; | 105 friend class PixelRefIterator; |
110 | 106 |
111 PicturePileImpl(); | 107 PicturePileImpl(); |
112 explicit PicturePileImpl(const PicturePileBase* other); | 108 explicit PicturePileImpl(const PicturePileBase* other); |
113 virtual ~PicturePileImpl(); | 109 virtual ~PicturePileImpl(); |
114 | 110 |
115 private: | 111 private: |
116 class ClonesForDrawing { | 112 typedef std::map<const Picture*, Region> PictureRegionMap; |
117 public: | |
118 ClonesForDrawing(const PicturePileImpl* pile, int num_threads); | |
119 ~ClonesForDrawing(); | |
120 | 113 |
121 typedef std::vector<scoped_refptr<PicturePileImpl> > PicturePileVector; | |
122 PicturePileVector clones_; | |
123 }; | |
124 | |
125 static scoped_refptr<PicturePileImpl> CreateCloneForDrawing( | |
126 const PicturePileImpl* other, unsigned thread_index); | |
127 | |
128 PicturePileImpl(const PicturePileImpl* other, unsigned thread_index); | |
129 | |
130 private: | |
131 typedef std::map<Picture*, Region> PictureRegionMap; | |
132 void CoalesceRasters(const gfx::Rect& canvas_rect, | 114 void CoalesceRasters(const gfx::Rect& canvas_rect, |
133 const gfx::Rect& content_rect, | 115 const gfx::Rect& content_rect, |
134 float contents_scale, | 116 float contents_scale, |
135 PictureRegionMap* result); | 117 PictureRegionMap* result) const; |
136 | 118 |
137 void RasterCommon( | 119 void RasterCommon( |
138 SkCanvas* canvas, | 120 SkCanvas* canvas, |
139 SkDrawPictureCallback* callback, | 121 SkDrawPictureCallback* callback, |
140 const gfx::Rect& canvas_rect, | 122 const gfx::Rect& canvas_rect, |
141 float contents_scale, | 123 float contents_scale, |
142 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 124 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
143 bool is_analysis); | 125 bool is_analysis) const; |
144 | |
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_; | |
150 | 126 |
151 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl); | 127 DISALLOW_COPY_AND_ASSIGN(PicturePileImpl); |
152 }; | 128 }; |
153 | 129 |
154 } // namespace cc | 130 } // namespace cc |
155 | 131 |
156 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_ | 132 #endif // CC_RESOURCES_PICTURE_PILE_IMPL_H_ |
OLD | NEW |