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 #include "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
6 #include "cc/base/region.h" | 6 #include "cc/base/region.h" |
7 #include "cc/debug/debug_colors.h" | 7 #include "cc/debug/debug_colors.h" |
8 #include "cc/debug/rendering_stats.h" | 8 #include "cc/debug/rendering_stats.h" |
9 #include "cc/resources/picture_pile_impl.h" | 9 #include "cc/resources/picture_pile_impl.h" |
10 #include "skia/ext/analysis_canvas.h" | 10 #include "skia/ext/analysis_canvas.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 PicturePileImpl::~PicturePileImpl() { | 65 PicturePileImpl::~PicturePileImpl() { |
66 } | 66 } |
67 | 67 |
68 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( | 68 PicturePileImpl* PicturePileImpl::GetCloneForDrawingOnThread( |
69 unsigned thread_index) const { | 69 unsigned thread_index) const { |
70 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); | 70 CHECK_GT(clones_for_drawing_.clones_.size(), thread_index); |
71 return clones_for_drawing_.clones_[thread_index]; | 71 return clones_for_drawing_.clones_[thread_index]; |
72 } | 72 } |
73 | 73 |
74 void PicturePileImpl::Raster( | 74 int64 PicturePileImpl::Raster( |
75 SkCanvas* canvas, | 75 SkCanvas* canvas, |
76 gfx::Rect canvas_rect, | 76 gfx::Rect canvas_rect, |
77 float contents_scale, | 77 float contents_scale) { |
78 int64* total_pixels_rasterized) { | |
79 | 78 |
80 DCHECK(contents_scale >= min_contents_scale_); | 79 DCHECK(contents_scale >= min_contents_scale_); |
81 | 80 |
82 #ifndef NDEBUG | 81 #ifndef NDEBUG |
83 // Any non-painted areas will be left in this color. | 82 // Any non-painted areas will be left in this color. |
84 canvas->clear(DebugColors::NonPaintedFillColor()); | 83 canvas->clear(DebugColors::NonPaintedFillColor()); |
85 #endif // NDEBUG | 84 #endif // NDEBUG |
86 | 85 |
87 canvas->save(); | 86 canvas->save(); |
88 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 87 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); |
(...skipping 24 matching lines...) Expand all Loading... |
113 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); | 112 canvas->drawColor(background_color_, SkXfermode::kSrc_Mode); |
114 } | 113 } |
115 | 114 |
116 // Rasterize the collection of relevant picture piles. | 115 // Rasterize the collection of relevant picture piles. |
117 gfx::Rect layer_rect = gfx::ToEnclosingRect( | 116 gfx::Rect layer_rect = gfx::ToEnclosingRect( |
118 gfx::ScaleRect(content_rect, 1.f / contents_scale)); | 117 gfx::ScaleRect(content_rect, 1.f / contents_scale)); |
119 | 118 |
120 canvas->clipRect(gfx::RectToSkRect(content_rect), | 119 canvas->clipRect(gfx::RectToSkRect(content_rect), |
121 SkRegion::kReplace_Op); | 120 SkRegion::kReplace_Op); |
122 Region unclipped(content_rect); | 121 Region unclipped(content_rect); |
| 122 |
| 123 int64 total_pixels_rasterized = 0; |
123 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); | 124 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); |
124 tile_iter; ++tile_iter) { | 125 tile_iter; ++tile_iter) { |
125 PictureListMap::iterator map_iter = | 126 PictureListMap::iterator map_iter = |
126 picture_list_map_.find(tile_iter.index()); | 127 picture_list_map_.find(tile_iter.index()); |
127 if (map_iter == picture_list_map_.end()) | 128 if (map_iter == picture_list_map_.end()) |
128 continue; | 129 continue; |
129 PictureList& pic_list= map_iter->second; | 130 PictureList& pic_list= map_iter->second; |
130 if (pic_list.empty()) | 131 if (pic_list.empty()) |
131 continue; | 132 continue; |
132 | 133 |
(...skipping 18 matching lines...) Expand all Loading... |
151 } else { | 152 } else { |
152 (*i)->Raster(canvas, content_clip, contents_scale, enable_lcd_text_); | 153 (*i)->Raster(canvas, content_clip, contents_scale, enable_lcd_text_); |
153 } | 154 } |
154 | 155 |
155 // Don't allow pictures underneath to draw where this picture did. | 156 // Don't allow pictures underneath to draw where this picture did. |
156 canvas->clipRect( | 157 canvas->clipRect( |
157 gfx::RectToSkRect(content_clip), | 158 gfx::RectToSkRect(content_clip), |
158 SkRegion::kDifference_Op); | 159 SkRegion::kDifference_Op); |
159 unclipped.Subtract(content_clip); | 160 unclipped.Subtract(content_clip); |
160 | 161 |
161 *total_pixels_rasterized += | 162 total_pixels_rasterized += |
162 content_clip.width() * content_clip.height(); | 163 content_clip.width() * content_clip.height(); |
163 } | 164 } |
164 } | 165 } |
165 | 166 |
166 #ifndef NDEBUG | 167 #ifndef NDEBUG |
167 // Fill the remaining clip with debug color. This allows us to | 168 // Fill the remaining clip with debug color. This allows us to |
168 // distinguish between non painted areas and problems with missing | 169 // distinguish between non painted areas and problems with missing |
169 // pictures. | 170 // pictures. |
170 SkPaint paint; | 171 SkPaint paint; |
171 paint.setColor(DebugColors::MissingPictureFillColor()); | 172 paint.setColor(DebugColors::MissingPictureFillColor()); |
172 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 173 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
173 canvas->drawPaint(paint); | 174 canvas->drawPaint(paint); |
174 #endif // NDEBUG | 175 #endif // NDEBUG |
175 | 176 |
176 // We should always paint some part of |content_rect|. | 177 // We should always paint some part of |content_rect|. |
177 DCHECK(!unclipped.Contains(content_rect)); | 178 DCHECK(!unclipped.Contains(content_rect)); |
178 | 179 |
179 canvas->restore(); | 180 canvas->restore(); |
| 181 |
| 182 return total_pixels_rasterized; |
180 } | 183 } |
181 | 184 |
182 void PicturePileImpl::GatherPixelRefs( | 185 void PicturePileImpl::GatherPixelRefs( |
183 gfx::Rect content_rect, | 186 gfx::Rect content_rect, |
184 float contents_scale, | 187 float contents_scale, |
185 std::list<skia::LazyPixelRef*>& pixel_refs) { | 188 std::list<skia::LazyPixelRef*>& pixel_refs) { |
186 std::list<skia::LazyPixelRef*> result; | 189 std::list<skia::LazyPixelRef*> result; |
187 | 190 |
188 gfx::Rect layer_rect = gfx::ToEnclosingRect( | 191 gfx::Rect layer_rect = gfx::ToEnclosingRect( |
189 gfx::ScaleRect(content_rect, 1.f / contents_scale)); | 192 gfx::ScaleRect(content_rect, 1.f / contents_scale)); |
(...skipping 20 matching lines...) Expand all Loading... |
210 gfx::Rect layer_rect(tiling_.total_size()); | 213 gfx::Rect layer_rect(tiling_.total_size()); |
211 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); | 214 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); |
212 if (layer_rect.IsEmpty()) | 215 if (layer_rect.IsEmpty()) |
213 return picture; | 216 return picture; |
214 | 217 |
215 SkCanvas* canvas = picture->beginRecording( | 218 SkCanvas* canvas = picture->beginRecording( |
216 layer_rect.width(), | 219 layer_rect.width(), |
217 layer_rect.height(), | 220 layer_rect.height(), |
218 SkPicture::kUsePathBoundsForClip_RecordingFlag); | 221 SkPicture::kUsePathBoundsForClip_RecordingFlag); |
219 | 222 |
220 int64 total_pixels_rasterized = 0; | 223 Raster(canvas, layer_rect, 1.0); |
221 Raster(canvas, layer_rect, 1.0, &total_pixels_rasterized); | |
222 picture->endRecording(); | 224 picture->endRecording(); |
223 | 225 |
224 return picture; | 226 return picture; |
225 } | 227 } |
226 | 228 |
227 void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect, | 229 void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect, |
228 float contents_scale, | 230 float contents_scale, |
229 PicturePileImpl::Analysis* analysis) { | 231 PicturePileImpl::Analysis* analysis) { |
230 DCHECK(analysis); | 232 DCHECK(analysis); |
231 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); | 233 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); |
232 | 234 |
233 gfx::Rect layer_rect = gfx::ToEnclosingRect( | 235 gfx::Rect layer_rect = gfx::ToEnclosingRect( |
234 gfx::ScaleRect(content_rect, 1.f / contents_scale)); | 236 gfx::ScaleRect(content_rect, 1.f / contents_scale)); |
235 | 237 |
236 SkBitmap empty_bitmap; | 238 SkBitmap empty_bitmap; |
237 empty_bitmap.setConfig(SkBitmap::kNo_Config, content_rect.width(), | 239 empty_bitmap.setConfig(SkBitmap::kNo_Config, content_rect.width(), |
238 content_rect.height()); | 240 content_rect.height()); |
239 skia::AnalysisDevice device(empty_bitmap); | 241 skia::AnalysisDevice device(empty_bitmap); |
240 skia::AnalysisCanvas canvas(&device); | 242 skia::AnalysisCanvas canvas(&device); |
241 | 243 |
242 int64 total_pixels_rasterized = 0; | 244 Raster(&canvas, content_rect, contents_scale); |
243 Raster(&canvas, content_rect, contents_scale, &total_pixels_rasterized); | |
244 | 245 |
245 analysis->is_transparent = canvas.isTransparent(); | 246 analysis->is_transparent = canvas.isTransparent(); |
246 analysis->is_solid_color = canvas.getColorIfSolid(&analysis->solid_color); | 247 analysis->is_solid_color = canvas.getColorIfSolid(&analysis->solid_color); |
247 analysis->is_cheap_to_raster = canvas.isCheap(); | 248 analysis->is_cheap_to_raster = canvas.isCheap(); |
248 canvas.consumeLazyPixelRefs(&analysis->lazy_pixel_refs); | 249 canvas.consumeLazyPixelRefs(&analysis->lazy_pixel_refs); |
249 } | 250 } |
250 | 251 |
251 PicturePileImpl::Analysis::Analysis() : | 252 PicturePileImpl::Analysis::Analysis() : |
252 is_solid_color(false), | 253 is_solid_color(false), |
253 is_transparent(false), | 254 is_transparent(false), |
254 is_cheap_to_raster(false) { | 255 is_cheap_to_raster(false) { |
255 } | 256 } |
256 | 257 |
257 PicturePileImpl::Analysis::~Analysis() { | 258 PicturePileImpl::Analysis::~Analysis() { |
258 } | 259 } |
259 | 260 |
260 } // namespace cc | 261 } // namespace cc |
OLD | NEW |