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/debug_colors.h" | 6 #include "cc/debug_colors.h" |
7 #include "cc/picture_pile_impl.h" | 7 #include "cc/picture_pile_impl.h" |
8 #include "cc/region.h" | 8 #include "cc/region.h" |
9 #include "cc/rendering_stats.h" | 9 #include "cc/rendering_stats.h" |
10 #include "skia/ext/analysis_canvas.h" | |
10 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
11 #include "third_party/skia/include/core/SkSize.h" | 12 #include "third_party/skia/include/core/SkSize.h" |
12 #include "ui/gfx/rect_conversions.h" | 13 #include "ui/gfx/rect_conversions.h" |
13 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
14 | 15 |
15 namespace cc { | 16 namespace cc { |
16 | 17 |
17 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { | 18 scoped_refptr<PicturePileImpl> PicturePileImpl::Create() { |
18 return make_scoped_refptr(new PicturePileImpl()); | 19 return make_scoped_refptr(new PicturePileImpl()); |
19 } | 20 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 layer_rect.height(), | 182 layer_rect.height(), |
182 SkPicture::kUsePathBoundsForClip_RecordingFlag); | 183 SkPicture::kUsePathBoundsForClip_RecordingFlag); |
183 | 184 |
184 int64 total_pixels_rasterized = 0; | 185 int64 total_pixels_rasterized = 0; |
185 Raster(canvas, layer_rect, 1.0, &total_pixels_rasterized); | 186 Raster(canvas, layer_rect, 1.0, &total_pixels_rasterized); |
186 picture->endRecording(); | 187 picture->endRecording(); |
187 | 188 |
188 return picture; | 189 return picture; |
189 } | 190 } |
190 | 191 |
191 bool PicturePileImpl::IsCheapInRect( | 192 void PicturePileImpl::AnalyzeInRect(const gfx::Rect& content_rect, |
192 gfx::Rect content_rect, float contents_scale) const { | 193 float contents_scale, |
194 PicturePileImpl::Analysis* analysis) { | |
195 DCHECK(analysis); | |
196 | |
197 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); | |
198 | |
193 gfx::Rect layer_rect = gfx::ToEnclosingRect( | 199 gfx::Rect layer_rect = gfx::ToEnclosingRect( |
194 gfx::ScaleRect(content_rect, 1.f / contents_scale)); | 200 gfx::ScaleRect(content_rect, 1.f / contents_scale)); |
195 | 201 |
202 SkBitmap emptyBitmap; | |
203 emptyBitmap.setConfig(SkBitmap::kNo_Config, content_rect.width(), | |
204 content_rect.height()); | |
205 skia::AnalysisDevice device(emptyBitmap); | |
206 skia::AnalysisCanvas canvas(&device); | |
207 | |
208 canvas.translate(-content_rect.x(), -content_rect.y()); | |
209 canvas.clipRect(gfx::RectToSkRect(content_rect)); | |
Justin Novosad
2013/03/05 22:14:02
I think this call to clip rect is redundant. It is
| |
210 | |
211 bool determined_if_transparent = false; | |
212 bool is_transparent_guess = false; | |
213 bool cheap = true; | |
Sami
2013/03/05 20:18:31
Nit: is_cheap for consistency.
| |
214 | |
215 // The loop here is similar to the raster loop. | |
216 Region unclipped(content_rect); | |
196 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); | 217 for (TilingData::Iterator tile_iter(&tiling_, layer_rect); |
197 tile_iter; ++tile_iter) { | 218 tile_iter; ++tile_iter) { |
198 PictureListMap::const_iterator map_iter = | 219 PictureListMap::iterator map_iter = |
199 picture_list_map_.find(tile_iter.index()); | 220 picture_list_map_.find(tile_iter.index()); |
200 if (map_iter == picture_list_map_.end()) | 221 if (map_iter == picture_list_map_.end()) |
201 continue; | 222 continue; |
223 PictureList& pic_list= map_iter->second; | |
Sami
2013/03/05 20:18:31
Nit: space missing before =.
| |
224 if (pic_list.empty()) | |
225 continue; | |
202 | 226 |
203 const PictureList& pic_list = map_iter->second; | 227 for (PictureList::reverse_iterator i = pic_list.rbegin(); |
204 for (PictureList::const_iterator i = pic_list.begin(); | 228 i != pic_list.rend(); ++i) { |
205 i != pic_list.end(); ++i) { | 229 gfx::Rect content_clip = gfx::ToEnclosedRect( |
206 if (!(*i)->LayerRect().Intersects(layer_rect) || !(*i)->HasRecording()) | 230 gfx::ScaleRect((*i)->LayerRect(), contents_scale)); |
231 DCHECK(!content_clip.IsEmpty()); | |
232 if (!unclipped.Intersects(content_clip)) | |
207 continue; | 233 continue; |
208 if (!(*i)->IsCheapInRect(layer_rect)) | 234 |
209 return false; | 235 // Do the analysis on the canvas. |
Sami
2013/03/05 20:18:31
Nit: doesn't seem like a very useful comment.
| |
236 (*i)->AnalyzeInRect(&canvas, | |
237 content_rect, | |
238 contents_scale); | |
239 | |
240 canvas.clipRect( | |
241 gfx::RectToSkRect(content_clip), | |
242 SkRegion::kDifference_Op); | |
243 unclipped.Subtract(content_clip); | |
244 | |
210 } | 245 } |
211 } | 246 } |
212 return true; | 247 |
248 analysis->is_transparent = canvas.isTransparent(); | |
249 analysis->is_solid_color = canvas.getColorIfSolid(&analysis->solid_color); | |
250 analysis->is_cheap_to_raster = canvas.isCheap(); | |
251 } | |
252 | |
253 PicturePileImpl::Analysis::Analysis() : | |
254 is_solid_color(false), | |
255 is_transparent(false), | |
256 is_cheap_to_raster(false) { | |
213 } | 257 } |
214 | 258 |
215 } // namespace cc | 259 } // namespace cc |
OLD | NEW |