OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/playback/raster_source_helper.h" | 5 #include "cc/playback/raster_source_helper.h" |
6 | 6 |
7 #include "base/trace_event/trace_event.h" | 7 #include "base/trace_event/trace_event.h" |
8 #include "cc/debug/debug_colors.h" | 8 #include "cc/debug/debug_colors.h" |
9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
10 #include "ui/gfx/geometry/rect_conversions.h" | 10 #include "ui/gfx/geometry/rect_conversions.h" |
11 #include "ui/gfx/skia_util.h" | 11 #include "ui/gfx/skia_util.h" |
12 | 12 |
13 namespace cc { | 13 namespace cc { |
14 | 14 |
15 void RasterSourceHelper::PrepareForPlaybackToCanvas( | 15 void RasterSourceHelper::PrepareForPlaybackToCanvas( |
16 SkCanvas* canvas, | 16 SkCanvas* canvas, |
17 const gfx::Rect& canvas_rect, | 17 const gfx::Rect& canvas_bitmap_rect, |
| 18 const gfx::Rect& canvas_playback_rect, |
18 const gfx::Rect& source_rect, | 19 const gfx::Rect& source_rect, |
19 float contents_scale, | 20 float contents_scale, |
20 SkColor background_color, | 21 SkColor background_color, |
21 bool clear_canvas_with_debug_color, | 22 bool clear_canvas_with_debug_color, |
22 bool requires_clear) { | 23 bool requires_clear) { |
23 canvas->discard(); | 24 bool partial_update = canvas_bitmap_rect != canvas_playback_rect; |
| 25 |
| 26 if (!partial_update) |
| 27 canvas->discard(); |
24 if (clear_canvas_with_debug_color) { | 28 if (clear_canvas_with_debug_color) { |
25 // Any non-painted areas in the content bounds will be left in this color. | 29 // Any non-painted areas in the content bounds will be left in this color. |
26 canvas->clear(DebugColors::NonPaintedFillColor()); | 30 if (!partial_update) { |
| 31 canvas->clear(DebugColors::NonPaintedFillColor()); |
| 32 } else { |
| 33 canvas->save(); |
| 34 canvas->clipRect(gfx::RectToSkRect( |
| 35 canvas_playback_rect - canvas_bitmap_rect.OffsetFromOrigin())); |
| 36 canvas->drawColor(DebugColors::NonPaintedFillColor()); |
| 37 canvas->restore(); |
| 38 } |
27 } | 39 } |
28 | 40 |
29 // If this raster source has opaque contents, it is guaranteeing that it will | 41 // If this raster source has opaque contents, it is guaranteeing that it will |
30 // draw an opaque rect the size of the layer. If it is not, then we must | 42 // draw an opaque rect the size of the layer. If it is not, then we must |
31 // clear this canvas ourselves. | 43 // clear this canvas ourselves. |
32 if (requires_clear) { | 44 if (requires_clear) { |
33 TRACE_EVENT_INSTANT0("cc", "SkCanvas::clear", TRACE_EVENT_SCOPE_THREAD); | 45 TRACE_EVENT_INSTANT0("cc", "SkCanvas::clear", TRACE_EVENT_SCOPE_THREAD); |
34 // Clearing is about ~4x faster than drawing a rect even if the content | 46 // Clearing is about ~4x faster than drawing a rect even if the content |
35 // isn't covering a majority of the canvas. | 47 // isn't covering a majority of the canvas. |
36 canvas->clear(SK_ColorTRANSPARENT); | 48 if (!partial_update) { |
| 49 canvas->clear(SK_ColorTRANSPARENT); |
| 50 } else { |
| 51 canvas->save(); |
| 52 canvas->clipRect(gfx::RectToSkRect( |
| 53 canvas_playback_rect - canvas_bitmap_rect.OffsetFromOrigin())); |
| 54 canvas->drawColor(SK_ColorTRANSPARENT); |
| 55 canvas->restore(); |
| 56 } |
37 } else { | 57 } else { |
38 // Even if completely covered, for rasterizations that touch the edge of the | 58 // Even if completely covered, for rasterizations that touch the edge of the |
39 // layer, we also need to raster the background color underneath the last | 59 // layer, we also need to raster the background color underneath the last |
40 // texel (since the recording won't cover it) and outside the last texel | 60 // texel (since the recording won't cover it) and outside the last texel |
41 // (due to linear filtering when using this texture). | 61 // (due to linear filtering when using this texture). |
42 gfx::Rect content_rect = | 62 gfx::Rect content_rect = |
43 gfx::ToEnclosingRect(gfx::ScaleRect(source_rect, contents_scale)); | 63 gfx::ToEnclosingRect(gfx::ScaleRect(source_rect, contents_scale)); |
44 | 64 |
45 // The final texel of content may only be partially covered by a | 65 // The final texel of content may only be partially covered by a |
46 // rasterization; this rect represents the content rect that is fully | 66 // rasterization; this rect represents the content rect that is fully |
47 // covered by content. | 67 // covered by content. |
48 gfx::Rect deflated_content_rect = content_rect; | 68 gfx::Rect deflated_content_rect = content_rect; |
49 deflated_content_rect.Inset(0, 0, 1, 1); | 69 deflated_content_rect.Inset(0, 0, 1, 1); |
50 if (!deflated_content_rect.Contains(canvas_rect)) { | 70 if (!deflated_content_rect.Contains(canvas_playback_rect)) { |
51 if (clear_canvas_with_debug_color) { | 71 if (clear_canvas_with_debug_color) { |
52 // Any non-painted areas outside of the content bounds are left in | 72 // Any non-painted areas outside of the content bounds are left in |
53 // this color. If this is seen then it means that cc neglected to | 73 // this color. If this is seen then it means that cc neglected to |
54 // rerasterize a tile that used to intersect with the content rect | 74 // rerasterize a tile that used to intersect with the content rect |
55 // after the content bounds grew. | 75 // after the content bounds grew. |
56 canvas->save(); | 76 canvas->save(); |
57 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 77 canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); |
58 canvas->clipRect(gfx::RectToSkRect(content_rect), | 78 canvas->clipRect(gfx::RectToSkRect(content_rect), |
59 SkRegion::kDifference_Op); | 79 SkRegion::kDifference_Op); |
60 canvas->drawColor(DebugColors::MissingResizeInvalidations(), | 80 canvas->drawColor(DebugColors::MissingResizeInvalidations(), |
61 SkXfermode::kSrc_Mode); | 81 SkXfermode::kSrc_Mode); |
62 canvas->restore(); | 82 canvas->restore(); |
63 } | 83 } |
64 | 84 |
65 // Drawing at most 2 x 2 x (canvas width + canvas height) texels is 2-3X | 85 // Drawing at most 2 x 2 x (canvas width + canvas height) texels is 2-3X |
66 // faster than clearing, so special case this. | 86 // faster than clearing, so special case this. |
67 canvas->save(); | 87 canvas->save(); |
68 canvas->translate(-canvas_rect.x(), -canvas_rect.y()); | 88 canvas->translate(-canvas_bitmap_rect.x(), -canvas_bitmap_rect.y()); |
69 gfx::Rect inflated_content_rect = content_rect; | 89 gfx::Rect inflated_content_rect = content_rect; |
70 inflated_content_rect.Inset(0, 0, -1, -1); | 90 inflated_content_rect.Inset(0, 0, -1, -1); |
71 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), | 91 canvas->clipRect(gfx::RectToSkRect(inflated_content_rect), |
72 SkRegion::kReplace_Op); | 92 SkRegion::kReplace_Op); |
73 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), | 93 canvas->clipRect(gfx::RectToSkRect(deflated_content_rect), |
74 SkRegion::kDifference_Op); | 94 SkRegion::kDifference_Op); |
75 canvas->drawColor(background_color, SkXfermode::kSrc_Mode); | 95 canvas->drawColor(background_color, SkXfermode::kSrc_Mode); |
76 canvas->restore(); | 96 canvas->restore(); |
77 } | 97 } |
78 } | 98 } |
79 } | 99 } |
80 | 100 |
81 } // namespace cc | 101 } // namespace cc |
OLD | NEW |