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 <algorithm> | 5 #include <algorithm> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "cc/base/region.h" | 9 #include "cc/base/region.h" |
10 #include "cc/debug/debug_colors.h" | 10 #include "cc/debug/debug_colors.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 // If this picture has opaque contents, it is guaranteeing that it will | 107 // If this picture has opaque contents, it is guaranteeing that it will |
108 // draw an opaque rect the size of the layer. If it is not, then we must | 108 // draw an opaque rect the size of the layer. If it is not, then we must |
109 // clear this canvas ourselves. | 109 // clear this canvas ourselves. |
110 if (contents_opaque_ || contents_fill_bounds_completely_) { | 110 if (contents_opaque_ || contents_fill_bounds_completely_) { |
111 // Even if completely covered, for rasterizations that touch the edge of the | 111 // Even if completely covered, for rasterizations that touch the edge of the |
112 // layer, we also need to raster the background color underneath the last | 112 // layer, we also need to raster the background color underneath the last |
113 // texel (since the recording won't cover it) and outside the last texel | 113 // texel (since the recording won't cover it) and outside the last texel |
114 // (due to linear filtering when using this texture). | 114 // (due to linear filtering when using this texture). |
115 gfx::Rect content_tiling_rect = gfx::ToEnclosingRect( | 115 gfx::Rect content_tiling_rect = gfx::ToEnclosingRect( |
116 gfx::ScaleRect(tiling_.tiling_rect(), contents_scale)); | 116 gfx::ScaleRect(gfx::Rect(tiling_.tiling_size()), contents_scale)); |
117 | 117 |
118 // The final texel of content may only be partially covered by a | 118 // The final texel of content may only be partially covered by a |
119 // rasterization; this rect represents the content rect that is fully | 119 // rasterization; this rect represents the content rect that is fully |
120 // covered by content. | 120 // covered by content. |
121 gfx::Rect deflated_content_tiling_rect = content_tiling_rect; | 121 gfx::Rect deflated_content_tiling_rect = content_tiling_rect; |
122 deflated_content_tiling_rect.Inset(0, 0, 1, 1); | 122 deflated_content_tiling_rect.Inset(0, 0, 1, 1); |
123 if (!deflated_content_tiling_rect.Contains(canvas_rect)) { | 123 if (!deflated_content_tiling_rect.Contains(canvas_rect)) { |
124 if (clear_canvas_with_debug_color_) { | 124 if (clear_canvas_with_debug_color_) { |
125 // Any non-painted areas outside of the content bounds are left in | 125 // Any non-painted areas outside of the content bounds are left in |
126 // this color. If this is seen then it means that cc neglected to | 126 // this color. If this is seen then it means that cc neglected to |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 SkCanvas* canvas, | 262 SkCanvas* canvas, |
263 SkDrawPictureCallback* callback, | 263 SkDrawPictureCallback* callback, |
264 const gfx::Rect& canvas_rect, | 264 const gfx::Rect& canvas_rect, |
265 float contents_scale, | 265 float contents_scale, |
266 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 266 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
267 bool is_analysis) { | 267 bool is_analysis) { |
268 DCHECK(contents_scale >= min_contents_scale_); | 268 DCHECK(contents_scale >= min_contents_scale_); |
269 | 269 |
270 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 270 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); |
271 gfx::Rect content_tiling_rect = gfx::ToEnclosingRect( | 271 gfx::Rect content_tiling_rect = gfx::ToEnclosingRect( |
272 gfx::ScaleRect(tiling_.tiling_rect(), contents_scale)); | 272 gfx::ScaleRect(gfx::Rect(tiling_.tiling_size()), contents_scale)); |
273 content_tiling_rect.Intersect(canvas_rect); | 273 content_tiling_rect.Intersect(canvas_rect); |
274 | 274 |
275 canvas->clipRect(gfx::RectToSkRect(content_tiling_rect), | 275 canvas->clipRect(gfx::RectToSkRect(content_tiling_rect), |
276 SkRegion::kIntersect_Op); | 276 SkRegion::kIntersect_Op); |
277 | 277 |
278 PictureRegionMap picture_region_map; | 278 PictureRegionMap picture_region_map; |
279 CoalesceRasters( | 279 CoalesceRasters( |
280 canvas_rect, content_tiling_rect, contents_scale, &picture_region_map); | 280 canvas_rect, content_tiling_rect, contents_scale, &picture_region_map); |
281 | 281 |
282 #ifndef NDEBUG | 282 #ifndef NDEBUG |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 canvas->clipRect(gfx::RectToSkRect(it.rect()), SkRegion::kDifference_Op); | 338 canvas->clipRect(gfx::RectToSkRect(it.rect()), SkRegion::kDifference_Op); |
339 paint.setColor(DebugColors::MissingPictureFillColor()); | 339 paint.setColor(DebugColors::MissingPictureFillColor()); |
340 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 340 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
341 canvas->drawPaint(paint); | 341 canvas->drawPaint(paint); |
342 #endif // NDEBUG | 342 #endif // NDEBUG |
343 } | 343 } |
344 | 344 |
345 skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { | 345 skia::RefPtr<SkPicture> PicturePileImpl::GetFlattenedPicture() { |
346 TRACE_EVENT0("cc", "PicturePileImpl::GetFlattenedPicture"); | 346 TRACE_EVENT0("cc", "PicturePileImpl::GetFlattenedPicture"); |
347 | 347 |
348 gfx::Rect tiling_rect(tiling_.tiling_rect()); | 348 gfx::Rect tiling_rect(tiling_.tiling_size()); |
349 SkPictureRecorder recorder; | 349 SkPictureRecorder recorder; |
350 SkCanvas* canvas = | 350 SkCanvas* canvas = |
351 recorder.beginRecording(tiling_rect.width(), tiling_rect.height()); | 351 recorder.beginRecording(tiling_rect.width(), tiling_rect.height()); |
352 if (!tiling_rect.IsEmpty()) | 352 if (!tiling_rect.IsEmpty()) |
353 RasterToBitmap(canvas, tiling_rect, 1.0, NULL); | 353 RasterToBitmap(canvas, tiling_rect, 1.0, NULL); |
354 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 354 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
355 | 355 |
356 return picture; | 356 return picture; |
357 } | 357 } |
358 | 358 |
359 void PicturePileImpl::AnalyzeInRect( | 359 void PicturePileImpl::AnalyzeInRect( |
360 const gfx::Rect& content_rect, | 360 const gfx::Rect& content_rect, |
361 float contents_scale, | 361 float contents_scale, |
362 PicturePileImpl::Analysis* analysis) { | 362 PicturePileImpl::Analysis* analysis) { |
363 AnalyzeInRect(content_rect, contents_scale, analysis, NULL); | 363 AnalyzeInRect(content_rect, contents_scale, analysis, NULL); |
364 } | 364 } |
365 | 365 |
366 void PicturePileImpl::AnalyzeInRect( | 366 void PicturePileImpl::AnalyzeInRect( |
367 const gfx::Rect& content_rect, | 367 const gfx::Rect& content_rect, |
368 float contents_scale, | 368 float contents_scale, |
369 PicturePileImpl::Analysis* analysis, | 369 PicturePileImpl::Analysis* analysis, |
370 RenderingStatsInstrumentation* stats_instrumentation) { | 370 RenderingStatsInstrumentation* stats_instrumentation) { |
371 DCHECK(analysis); | 371 DCHECK(analysis); |
372 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); | 372 TRACE_EVENT0("cc", "PicturePileImpl::AnalyzeInRect"); |
373 | 373 |
374 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( | 374 gfx::Rect layer_rect = gfx::ScaleToEnclosingRect( |
375 content_rect, 1.0f / contents_scale); | 375 content_rect, 1.0f / contents_scale); |
376 | 376 |
377 layer_rect.Intersect(tiling_.tiling_rect()); | 377 layer_rect.Intersect(gfx::Rect(tiling_.tiling_size())); |
378 | 378 |
379 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); | 379 skia::AnalysisCanvas canvas(layer_rect.width(), layer_rect.height()); |
380 | 380 |
381 RasterForAnalysis(&canvas, layer_rect, 1.0f, stats_instrumentation); | 381 RasterForAnalysis(&canvas, layer_rect, 1.0f, stats_instrumentation); |
382 | 382 |
383 analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); | 383 analysis->is_solid_color = canvas.GetColorIfSolid(&analysis->solid_color); |
384 } | 384 } |
385 | 385 |
386 // Since there are situations when we can skip analysis, the variables have to | 386 // Since there are situations when we can skip analysis, the variables have to |
387 // be set to their safest values. That is, we have to assume that the tile is | 387 // be set to their safest values. That is, we have to assume that the tile is |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 ++it) { | 450 ++it) { |
451 Picture* picture = it->second.GetPicture(); | 451 Picture* picture = it->second.GetPicture(); |
452 if (picture && (processed_pictures.count(picture) == 0)) { | 452 if (picture && (processed_pictures.count(picture) == 0)) { |
453 picture->EmitTraceSnapshot(); | 453 picture->EmitTraceSnapshot(); |
454 processed_pictures.insert(picture); | 454 processed_pictures.insert(picture); |
455 } | 455 } |
456 } | 456 } |
457 } | 457 } |
458 | 458 |
459 } // namespace cc | 459 } // namespace cc |
OLD | NEW |