| 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/resources/raster_source_helper.h" | 5 #include "cc/resources/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 gfx::Rect canvas_rect = |
| 26 canvas_playback_rect - canvas_bitmap_rect.OffsetFromOrigin(); |
| 27 |
| 28 if (!partial_update) |
| 29 canvas->discard(); |
| 24 if (clear_canvas_with_debug_color) { | 30 if (clear_canvas_with_debug_color) { |
| 25 // Any non-painted areas in the content bounds will be left in this color. | 31 // Any non-painted areas in the content bounds will be left in this color. |
| 26 canvas->clear(DebugColors::NonPaintedFillColor()); | 32 if (!partial_update) { |
| 33 canvas->clear(DebugColors::NonPaintedFillColor()); |
| 34 } else { |
| 35 canvas->save(); |
| 36 canvas->clipRect(gfx::RectToSkRect(canvas_rect)); |
| 37 canvas->drawColor(DebugColors::NonPaintedFillColor()); |
| 38 canvas->restore(); |
| 39 } |
| 27 } | 40 } |
| 28 | 41 |
| 29 // If this raster source has opaque contents, it is guaranteeing that it will | 42 // 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 | 43 // draw an opaque rect the size of the layer. If it is not, then we must |
| 31 // clear this canvas ourselves. | 44 // clear this canvas ourselves. |
| 32 if (requires_clear) { | 45 if (requires_clear) { |
| 33 TRACE_EVENT_INSTANT0("cc", "SkCanvas::clear", TRACE_EVENT_SCOPE_THREAD); | 46 TRACE_EVENT_INSTANT0("cc", "SkCanvas::clear", TRACE_EVENT_SCOPE_THREAD); |
| 34 // Clearing is about ~4x faster than drawing a rect even if the content | 47 // Clearing is about ~4x faster than drawing a rect even if the content |
| 35 // isn't covering a majority of the canvas. | 48 // isn't covering a majority of the canvas. |
| 36 canvas->clear(SK_ColorTRANSPARENT); | 49 if (!partial_update) { |
| 50 canvas->clear(SK_ColorTRANSPARENT); |
| 51 } else { |
| 52 canvas->save(); |
| 53 canvas->clipRect(gfx::RectToSkRect(canvas_rect)); |
| 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 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 |